import { flexRender, type Table as TableInstance } from '@tanstack/react-table'; import { ArrowDownIcon, ArrowUpIcon, ArrowUpDownIcon } from 'lucide-react'; import type { Post } from '@/entities/post'; import { Button } from '@/shared/ui/button'; import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow, } from '@/shared/ui/table'; type PostTableViewProps = { table: TableInstance; sort: 'asc' | 'desc' | null; onCycleSort: () => void; emptyMessage: string; }; const ARIA_SORT = { asc: 'ascending', desc: 'descending' } as const; const SORT_ICONS = { asc: ArrowUpIcon, desc: ArrowDownIcon } as const; const SORT_LABELS = { asc: '오름차순 정렬됨', desc: '내림차순 정렬됨', } as const; export const PostTableView = ({ table, sort, onCycleSort, emptyMessage, }: PostTableViewProps) => { 'use no memo'; const ariaSort = sort === null ? 'none' : ARIA_SORT[sort]; const SortIcon = sort === null ? ArrowUpDownIcon : SORT_ICONS[sort]; const rows = table.getRowModel().rows; return (
{table.getFlatHeaders().map((header) => { const isTitle = header.column.id === 'title'; return ( {isTitle ? ( ) : ( flexRender( header.column.columnDef.header, header.getContext() ) )} ); })} {rows.map((row) => ( {row.getVisibleCells().map((cell) => ( {flexRender(cell.column.columnDef.cell, cell.getContext())} ))} ))} {rows.length === 0 && ( {emptyMessage} )}
); };