| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133 |
- 'use client';
- import './style.scss';
- import Link from 'next/link';
- import { useSearchParams } from 'next/navigation';
- import { useMemo } from 'react';
- import Post from '@/types/forum/post';
- import { BoardListMeta } from '@/types/forum/boardMeta';
- import { formatDate, isNewPost } from '@/lib/utils/client';
- import NoticeListLayout from './NoticeListLayout';
- import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
- import { faComment } from '@fortawesome/free-regular-svg-icons';
- interface Props {
- boardListMeta: BoardListMeta;
- notice?: Post[];
- list: Post[];
- startIndex?: number;
- onChange?: (_: number|undefined) => void;
- }
- export default function QnAListLayout({boardListMeta, notice = [], list, startIndex, onChange}: Props)
- {
- const searchParams = useSearchParams();
- const query = useMemo(() => Object.fromEntries(searchParams.entries()), [searchParams]);
- return (
- <>
- <section className='qna-list-layout' aria-label='1:1문의 게시판'>
- <article>
- <ul>
- <li>번호</li>
- <li>제목</li>
- <li>작성자</li>
- <li>답변 여부</li>
- <li>작성일</li>
- </ul>
- </article>
- <article>
- {/* 일반 공지 */}
- <NoticeListLayout isEnabled={!boardListMeta.exceptNotice} list={notice} layout={boardListMeta.layout} />
- {/* 일반 글 */}
- {list.length > 0 && (
- list.map((row, i) => {
- const isNew = isNewPost(boardListMeta.isNewIcon, row);
- const createdAt = formatDate(row.createdAt);
- const postViewUrl = {pathname: '/post/' + row.id, query};
- return (
- <section key={row.id}>
- {/* PC */}
- <ol>
- <li>
- <small>{startIndex !== undefined ? startIndex - i : i + 1}</small>
- </li>
- <li>
- {row.boardPrefix && row.boardPrefixID && onChange && (
- <button type="button" onClick={() => onChange(row.boardPrefixID || undefined)}>
- [{row.boardPrefix.name}]
- </button>
- )}
- <Link href={postViewUrl}>
- <em>{row.subject} {row.comments > 0 && (<span>[{row.comments}]</span>)}</em>
- {isNew && <span><img src='/resources/new.gif' alt='NEW'/></span>}
- </Link>
- </li>
- <li>{row.name || row.sid}</li>
- <li>
- {!row.isReply ? (
- <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'>
- 대기
- </span>
- ) : (
- <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'>
- 완료
- </span>
- )}
- </li>
- <li>{createdAt}</li>
- </ol>
- {/* Mobile */}
- <dl hidden>
- <dt>
- {row.boardPrefix && row.boardPrefixID && onChange && (
- <button type="button" onClick={() => onChange(row.boardPrefixID || undefined)}>
- [{row.boardPrefix.name}]
- </button>
- )}
- <Link href={postViewUrl}>
- <em>{row.subject} {row.comments > 0 && (<span>[{row.comments}]</span>)}</em>
- {isNew && <span><img src='/resources/new.gif' alt='NEW'/></span>}
- </Link>
- </dt>
- <dd>
- <ul>
- <li>{row.name || row.sid}</li>
- <li><FontAwesomeIcon icon={faComment} /> {row.comments}</li>
- <li>
- {!row.isReply ? (
- <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'>
- 대기
- </span>
- ) : (
- <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'>
- 완료
- </span>
- )}
- </li>
- <li>{createdAt}</li>
- </ul>
- </dd>
- </dl>
- </section>
- );
- })
- )}
- {list.length <= 0 && (
- <section>
- <p className="text-center p-10">
- 1:1문의 글이 없습니다.
- </p>
- </section>
- )}
- </article>
- </section>
- </>
- );
- }
|