'use client'; import { use, useState, useEffect } from 'react'; import { useQuery } from '@tanstack/react-query'; import { getPostsByCategory } from '@/api/posts'; import PostCard from '@/components/post/PostCard'; import PostListItem from '@/components/post/PostListItem'; // 추가 import { Loader2, ChevronLeft, ChevronRight, LayoutGrid, List } from 'lucide-react'; import { notFound } from 'next/navigation'; import { clsx } from 'clsx'; export default function CategoryPage({ params }: { params: Promise<{ id: string }> }) { const { id } = use(params); const categoryName = decodeURIComponent(id); const apiCategoryName = categoryName === 'uncategorized' ? '미분류' : categoryName; const [page, setPage] = useState(0); const [viewMode, setViewMode] = useState<'grid' | 'list'>('grid'); const PAGE_SIZE = 10; // 💡 로컬 스토리지에서 뷰 모드 불러오기 useEffect(() => { const savedMode = localStorage.getItem('postViewMode') as 'grid' | 'list'; if (savedMode) setViewMode(savedMode); }, []); const handleViewModeChange = (mode: 'grid' | 'list') => { setViewMode(mode); localStorage.setItem('postViewMode', mode); }; const { data: postsData, isLoading, error, isPlaceholderData } = useQuery({ queryKey: ['posts', 'category', apiCategoryName, page], queryFn: () => getPostsByCategory(apiCategoryName, page, PAGE_SIZE), placeholderData: (previousData) => previousData, }); if (isLoading || (postsData === undefined && !error)) { return (
아직 작성된 글이 없습니다.