"use client"; import { useEffect, useState } from "react"; import Link from "next/link"; import { getAnnouncements, type Announcement } from "@/lib/services"; import { useAuth, usePagination } from "@/hooks"; import { FileTextIcon } from "lucide-react"; import Pagination from "@/components/Pagination"; export default function AnnouncementsPage() { const [announcements, setAnnouncements] = useState([]); const [isLoading, setIsLoading] = useState(true); const { user } = useAuth(); const { currentPage, totalPages, setCurrentPage, setTotalPages } = usePagination(); useEffect(() => { loadData(currentPage); }, [currentPage]); const loadData = async (page: number) => { setIsLoading(true); try { // 공지사항 목록 불러오기 const announcementsResponse = await getAnnouncements(page, 10); setAnnouncements(announcementsResponse.data); setTotalPages(announcementsResponse.pagination.totalPages); } catch (error) { console.error("Failed to load announcements:", error); } finally { setIsLoading(false); } }; const formatDate = (dateString: string) => { const date = new Date(dateString); return date.toLocaleDateString("ko-KR", { year: "numeric", month: "2-digit", day: "2-digit", }); }; if (isLoading) { return (
{/* 테이블 헤더 스켈레톤 - 데스크톱 */}
번호
제목
작성자
작성일
조회수
{/* 테이블 바디 스켈레톤 */}
{[...Array(5)].map((_, index) => (
{/* 모바일 뷰 스켈레톤 */}
{/* 데스크톱 뷰 스켈레톤 */}
))}
); } return (
{/* 공지 작성 버튼 */} {user && (
공지 작성
)} {/* 테이블 */} {announcements.length === 0 ? (

등록된 주보가 없습니다.

) : (
{/* 테이블 헤더 - 데스크톱 */}
번호
제목
작성자
작성일
조회수
{/* 테이블 바디 */}
{announcements.map((item, index) => ( {/* 모바일 뷰 */}
{item.isImportant && ( 필독 )}

{item.title}

{item.author.userName} {formatDate(item.createdAt)}
{/* 데스크톱 뷰 */}
{announcements.length - index}
{item.isImportant && ( 필독 )} {item.title}
{item.author.userName}
{formatDate(item.createdAt)}
{item.viewCount}
))}
)} {/* Pagination */}
); }