diff --git a/src/app/(pages)/mypage/components/sections/CommentsSection.tsx b/src/app/(pages)/mypage/components/sections/CommentsSection.tsx index 514282ce..8b6ee157 100644 --- a/src/app/(pages)/mypage/components/sections/CommentsSection.tsx +++ b/src/app/(pages)/mypage/components/sections/CommentsSection.tsx @@ -1,36 +1,48 @@ "use client"; import React from "react"; -import { useState } from "react"; +import { useState, useEffect } from "react"; import { useMyComments } from "@/hooks/queries/user/me/useMyComments"; import Pagination from "@/app/components/pagination/Pagination"; -import Link from "next/link"; import LoadingSpinner from "@/app/components/loading-spinner/LoadingSpinner"; import BoardComment from "@/app/components/card/board/BoardComment"; - -// 한 페이지당 댓글 수 -const COMMENTS_PER_PAGE = 10; +import ContentSection from "@/app/components/layout/ContentSection"; +import useWidth from "@/hooks/useWidth"; export default function CommentsSection() { - // 현재 페이지 상태 관리 const [currentPage, setCurrentPage] = useState(1); + const { isMobile, isTablet, isDesktop } = useWidth(); + + // 화면 크기에 따른 페이지당 댓글 수 계산 + const getCommentsPerPage = () => { + if (isMobile) return 2; // 1열 x 2줄 = 2개 + if (isTablet) return 4; // 2열 x 2줄 = 4개 + if (isDesktop) return 6; // 3열 x 2줄 = 6개 + return 8; // xl 사이즈: 4열 x 2줄 = 8개 + }; + + const commentsPerPage = getCommentsPerPage(); - // 내가 작성한 댓글 목록 조회 const { data, isLoading, error } = useMyComments({ page: currentPage, - pageSize: COMMENTS_PER_PAGE, + pageSize: commentsPerPage, }); - // 총 페이지 수 계산 - const totalPages = data ? Math.ceil(data.totalItemCount / COMMENTS_PER_PAGE) : 0; + const totalPages = data ? Math.ceil(data.totalItemCount / commentsPerPage) : 0; + + // 화면 크기가 변경될 때 현재 페이지 재조정 + useEffect(() => { + const newTotalPages = data ? Math.ceil(data.totalItemCount / commentsPerPage) : 0; + if (currentPage > newTotalPages && newTotalPages > 0) { + setCurrentPage(newTotalPages); + } + }, [commentsPerPage, data, currentPage]); - // 페이지 변경 핸들러 const handlePageChange = (page: number) => { setCurrentPage(page); - window.scrollTo(0, 0); // 페이지 변경 시 상단으로 스크롤 + window.scrollTo(0, 0); }; - // 에러 상태 처리 if (error) { return (
작성한 댓글이 없습니다.
{message}
-게시글을 불러오는데 실패했습니다.
+작성한 게시글이 없습니다.
+{post.content}
+ + {/* 하단 정보 */} +