import { getPages } from "@/lib/pages/repository"; import { getCurrentUser } from "@/lib/user"; import { formatDate } from "@/lib/utils"; import { ArchiveIcon, CalendarIcon, PencilLineIcon } from "lucide-react"; import { Metadata } from "next"; import Link from "next/link"; export const metadata: Metadata = { title: "List of pages" }; export default async function List() { const user = await getCurrentUser(); const isAdmin = user?.isAdmin; const pagesPublished = await getPages("PAGE", "PUBLISHED"); const pagesArchived = isAdmin ? await getPages("PAGE", "ARCHIVED") : []; const pagesDraft = isAdmin ? await getPages("PAGE", "DRAFT") : []; const pages = [...pagesPublished, ...pagesArchived, ...pagesDraft].sort((a, b) => { const aDate = new Date(a.updatedAt ?? a.publishedAt).getTime(); const bDate = new Date(b.updatedAt ?? b.publishedAt).getTime(); return bDate - aDate; }); return (

List of pages

{ pages.length > 0 ? pages.map((p) => (

{p.title}

{p.publishedAt &&
{formatDate(p.publishedAt)}
} {p.status === "ARCHIVED" &&
Archived
} {p.status === "DRAFT" &&
Draft
}
)) :

There are no pages yet...

}
); }