'use client'; import { useState, useEffect } from 'react'; import Image from 'next/image'; import Link from 'next/link'; import { GalleryPost, getGalleryPosts } from '@/lib/services'; import { useAuth, usePagination } from '@/hooks'; import Pagination from '@/components/Pagination'; import { FileTextIcon } from 'lucide-react'; export default function GalleryPage() { const [posts, setPosts] = useState([]); const [loading, setLoading] = useState(true); const { user } = useAuth(); const { currentPage, totalPages, setCurrentPage, setTotalPages } = usePagination(); useEffect(() => { fetchPosts(currentPage); }, [currentPage]); const fetchPosts = async (page: number) => { setLoading(true); try { const result = await getGalleryPosts(page, 9); setPosts(result.data); setTotalPages(result.pagination.totalPages); } catch (error) { console.error('Failed to fetch posts:', error); } finally { setLoading(false); } }; return (
{/* 글쓰기 버튼 */} {user && (
갤러리 작성
)} {/* 갤러리 그리드 */} {loading ? (
{Array.from({ length: 9 }).map((_, idx) => (
))}
) : posts.length === 0 ? (

등록된 갤러리가 없습니다.

) : (
{posts.map((post) => (
{post.thumbnailUrl && ( {post.title} )} {post.images.length > 1 && (
+{post.images.length - 1}
)}

{post.title}

{new Date(post.createdAt).toLocaleDateString('ko-KR')}

))}
)} {/* Pagination */}
); }