import { getArticlesPaginated } from '@/lib/feature/article/article.external'; import { ArticleListPagination } from '@/ui/components/internal/article-list-pagination'; import { DeleteArticleButton } from '@/ui/components/internal/article/delete-article-button'; import { Button } from '@/ui/components/shadcn/button'; import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow, } from '@/ui/components/shadcn/table'; import { FileTextIcon, PencilIcon } from 'lucide-react'; import Link from 'next/link'; type AdminArticleListProps = { searchParams: Promise<{ page?: string; pageSize?: string }>; defaultPageSize: number; }; const formatDate = (date: Date) => new Intl.DateTimeFormat('en-US', { year: 'numeric', month: 'short', day: 'numeric', }).format(date); export const AdminArticleList = async ({ searchParams, defaultPageSize, }: AdminArticleListProps) => { const { page: pageParam, pageSize: pageSizeParam } = await searchParams; const page = Math.max(1, Number(pageParam) || 1); const pageSize = Number(pageSizeParam) || defaultPageSize; const paginationResult = await getArticlesPaginated(page, pageSize); if (!paginationResult.ok) { return (

Failed to load articles. Please try again later.

); } const { data: articles, totalPages, total, page: currentPage, } = paginationResult.value; if (articles.length === 0) { return (

No articles yet.

); } return ( <>

{total} article{total === 1 ? '' : 's'} published

Cover Title Description Published Actions {articles.map((article) => (
{article.coverImageUrl ? ( // eslint-disable-next-line @next/next/no-img-element ) : (
{'{}'}
)}
{article.title}

/{article.slug}

{article.description}

))}
{totalPages > 1 && (

Page {currentPage} of {totalPages}

)} ); };