QnAListLayout.tsx 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. 'use client';
  2. import './style.scss';
  3. import Link from 'next/link';
  4. import { useSearchParams } from 'next/navigation';
  5. import Post from '@/types/forum/post';
  6. import { BoardListMeta } from '@/types/forum/boardMeta';
  7. import { formatDate, isNewPost } from '@/lib/utils/client';
  8. import NoticeListLayout from './NoticeListLayout';
  9. import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
  10. import { faComment } from '@fortawesome/free-regular-svg-icons';
  11. interface Props {
  12. boardListMeta: BoardListMeta;
  13. notice: Post[];
  14. list: Post[];
  15. startIndex: number;
  16. onChange: (_: number|undefined) => void;
  17. }
  18. export default function QnAListLayout({boardListMeta, notice, list, startIndex, onChange}: Props)
  19. {
  20. const searchParams = useSearchParams();
  21. return (
  22. <>
  23. <section className='qna-list-layout' aria-label='1:1문의 게시판'>
  24. <article>
  25. <ul>
  26. <li>번호</li>
  27. <li>제목</li>
  28. <li>작성자</li>
  29. <li>답변 여부</li>
  30. <li>작성일</li>
  31. </ul>
  32. </article>
  33. <article>
  34. {/* 일반 공지 */}
  35. <NoticeListLayout isEnabled={!boardListMeta.exceptNotice} list={notice} layout={boardListMeta.layout} />
  36. {/* 일반 글 */}
  37. {list.length > 0 && (
  38. list.map((row, i) => {
  39. const query = Object.fromEntries(searchParams.entries());
  40. const isNew = isNewPost(boardListMeta.isNewIcon, row);
  41. const createdAt = formatDate(row.createdAt);
  42. return (
  43. <section key={row.id}>
  44. {/* PC */}
  45. <ol>
  46. <li>
  47. <small>{startIndex - i}</small>
  48. </li>
  49. <li>
  50. {row.boardPrefix && row.boardPrefixID && (
  51. <button type="button" onClick={() => onChange(row.boardPrefixID || undefined)}>
  52. [{row.boardPrefix.name}]
  53. </button>
  54. )}
  55. <Link href={{
  56. pathname: '/post/' + row.id,
  57. query: {
  58. ...query
  59. }
  60. }}
  61. >
  62. <em>{row.subject} {row.comments > 0 && (<span>[{row.comments}]</span>)}</em>
  63. {isNew && <span><img src='/resources/new.gif' alt='NEW'/></span>}
  64. </Link>
  65. </li>
  66. <li>{row.name || row.sid}</li>
  67. <li>
  68. {!row.isReply ? (
  69. <span className='inline-flex items-center rounded-md bg-yellow-50 px-2 py-1 text-xs font-medium text-yellow-800 ring-1 ring-yellow-600/20 ring-inset'>
  70. 대기
  71. </span>
  72. ) : (
  73. <span className='inline-flex items-center rounded-md bg-green-50 px-2 py-1 text-xs font-medium text-green-700 ring-1 ring-green-600/20 ring-inset'>
  74. 완료
  75. </span>
  76. )}
  77. </li>
  78. <li>{createdAt}</li>
  79. </ol>
  80. {/* Mobile */}
  81. <dl hidden>
  82. <dt>
  83. {row.boardPrefix && row.boardPrefixID && (
  84. <button type="button" onClick={() => onChange(row.boardPrefixID || undefined)}>
  85. [{row.boardPrefix.name}]
  86. </button>
  87. )}
  88. <Link href={{
  89. pathname: '/post/' + row.id,
  90. query: {
  91. ...query
  92. }
  93. }}
  94. >
  95. <em>{row.subject}</em>
  96. {isNew && <span><img src='/resources/new.gif' alt='NEW'/></span>}
  97. </Link>
  98. </dt>
  99. <dd>
  100. <ul>
  101. <li>{row.name || row.sid}</li>
  102. <li><FontAwesomeIcon icon={faComment} /> {row.comments}</li>
  103. <li>
  104. {!row.isReply ? (
  105. <span className='inline-flex items-center rounded-md bg-yellow-50 px-2 py-1 text-xs font-medium text-yellow-800 ring-1 ring-yellow-600/20 ring-inset'>
  106. 대기
  107. </span>
  108. ) : (
  109. <span className='inline-flex items-center rounded-md bg-green-50 px-2 py-1 text-xs font-medium text-green-700 ring-1 ring-green-600/20 ring-inset'>
  110. 완료
  111. </span>
  112. )}
  113. </li>
  114. <li>{createdAt}</li>
  115. </ul>
  116. </dd>
  117. </dl>
  118. </section>
  119. );
  120. })
  121. )}
  122. {list.length <= 0 && (
  123. <section>
  124. <p className="text-center p-10">
  125. 1:1문의 글이 없습니다.
  126. </p>
  127. </section>
  128. )}
  129. </article>
  130. </section>
  131. </>
  132. );
  133. }