Files
eu/app/list/page.tsx
T
2026-07-15 22:19:26 +03:00

48 lines
1.9 KiB
TypeScript

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();
if (!user?.isAdmin) redirect("/");
const pagesPublished = await getPages("PAGE", "PUBLISHED");
const pagesArchived = await getPages("PAGE", "ARCHIVED");
const pagesDraft = 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>
);
}