feat: list of pages

This commit is contained in:
Ivan Rezchikov
2026-07-13 20:11:42 +03:00
parent 2e356e4c47
commit 7a7ca2d831
7 changed files with 122 additions and 68 deletions
-2
View File
@@ -141,8 +141,6 @@ function BlockRenderer({ block }: { block: Block }) {
<img
src={b.url}
alt={b.caption || "Image"}
width={1200}
height={800}
style={imageWidth && imageWidth < 100 ? { width: `${imageWidth}%` } : undefined}
className={cn(
"h-auto rounded-md border object-contain",
-33
View File
@@ -1,33 +0,0 @@
import { NewsCard } from "@/components/news-card";
import { getPages } from "@/lib/pages/repository";
import { PAGE_TYPES, PageType } from "@/lib/pages/types";
import { getCurrentUser } from "@/lib/user";
import { Metadata } from "next";
import { notFound, redirect } from "next/navigation";
export const metadata: Metadata = { title: "Pages" };
export default async function Pages({ params }: { params: Promise<{ type: string }> }) {
const user = await getCurrentUser();
if (!user?.isAdmin) redirect("/");
const { type } = await params;
if (!PAGE_TYPES.includes(type as PageType)) {
notFound();
}
const pages = await getPages(type as PageType, "PUBLISHED");
return (
<div className="flex flex-col p-4 md:p-16 gap-8 md:gap-16 mb-4 md:mb-0">
<h2>All pages of type ${type}</h2>
<div className="flex flex-col gap-6">
{
pages.length > 0 ? pages.map((n) => (
<NewsCard news={n} key={n.id} />
)) : <h2 className="text-muted-foreground">There are no pages of that type yet...</h2>
}
</div>
</div>
);
}
+45
View File
@@ -0,0 +1,45 @@
import { getPages } from "@/lib/pages/repository";
import { getCurrentUser } from "@/lib/user";
import { formatDate } from "@/lib/utils";
import { ArchiveIcon, CalendarIcon } 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 pages = [...pagesPublished, ...pagesArchived].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">
<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>}
</div>
</div>
)) : <h2 className="text-muted-foreground">There are no pages yet...</h2>
}
</div>
</div>
);
}