This commit is contained in:
Ivan Rezchikov
2026-07-15 22:36:52 +03:00
parent ac75c72382
commit db5823c593
+48
View File
@@ -0,0 +1,48 @@
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";
import { redirect } from "next/navigation";
export const metadata: Metadata = { title: "List of pages" };
export default async function List() {
const user = await getCurrentUser();
const isAdmin = user?.isAdmin;
if (!isAdmin) redirect("/");
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 (
<div className="flex flex-col p-4 md:p-16 gap-6 md:gap-10 mb-4 md:mb-0">
<h1>List of pages</h1>
<div className="flex flex-col gap-4">
{
pages.length > 0 ? pages.map((p) => (
<div className="flex flex-col gap-1" key={p.id}>
<Link href={`/page/${p.slug}`} className="max-w-vh">
<h3 className="truncate">{p.title}</h3>
</Link>
<div className="flex flex-row gap-4">
{p.publishedAt && <h5 className="flex gap-1 items-center"><CalendarIcon size={14} />{formatDate(p.publishedAt)}</h5>}
{p.status === "ARCHIVED" && <h5 className="flex gap-1 items-center"><ArchiveIcon size={14} />Archived</h5>}
{p.status === "DRAFT" && <h5 className="flex gap-1 items-center"><PencilLineIcon size={14} />Draft</h5>}
</div>
</div>
)) : <h2 className="text-muted-foreground">There are no pages yet...</h2>
}
</div>
</div>
);
}