'use client'; import './style.scss'; import { useState, useEffect } from 'react'; import { FontAwesomeIcon } from '@fortawesome/react-fontawesome' import { faArrowRotateRight } from '@fortawesome/free-solid-svg-icons'; import BoardResponse from '@/dtos/response/forum/board/boardResponse'; import PostResponse from '@/dtos/response/forum/post/postResponse'; import CommentListRequest from '@/dtos/request/forum/comment/commentListRequest'; import CommentListResponse from '@/dtos/response/forum/comment/commentListResponse'; import { fetchCommentList } from '@/lib/api/forum/comment'; import { throwError, loginCheck } from '@/lib/utils/client'; import useAuth from '@/hooks/useAuth'; import WriteForm from './_component/WriteForm'; import List from './_component/List'; import { type CommentSort, CommentConst } from '@/constants/forum'; import Pagination from '@/app/component/Pagination'; type Props = { board: BoardResponse; post: PostResponse; } export default function View({ board, post } : Props) { const { isAuthenticated } = useAuth(); const [error, setError] = useState(null); const [loading, setLoading] = useState(false); const [page, setPage] = useState(1); const [sort, setSort] = useState(CommentConst.Sort.CreatedAt); const [data, setData] = useState({ total: 0, list: [] }); const [replyTargetID, setReplyTargetID] = useState(null); useEffect(() => { if (error) { alert(error); setError(null); } }, [error]); useEffect(() => { loadComments(); }, [page, sort]); const loadComments = async () => { setLoading(true); // 댓글 목록 호출 fetchCommentList({ postID: post.id, page: page, sort: sort, perPage: board.boardMeta.comment?.perPage ?? 20 } as CommentListRequest).then((res) => { throwError(res); if (res.data != null) { setData(res.data); } }).catch(err => { setError(err.message); }).finally(() => { setLoading(false); }); }; const handleReply = (commentID: number) => { if (!loginCheck(isAuthenticated)) { return; } setReplyTargetID((prev) => (prev === commentID ? null : commentID)); // toggle }; const handleSuccess = () => { setReplyTargetID(null); loadComments(); }; const handleDelete = () => { setReplyTargetID(null); loadComments(); }; return ( <> {/* 댓글, 답글 */}
댓글 {data.total}개
{/* 댓글 작성란 */}
{/* 댓글 목록 */} {/* 페이징 */}
); }