feat: improved news

This commit is contained in:
Ivan Rezchikov
2026-06-21 13:35:32 +03:00
parent 95fd6ae716
commit 48656b562a
13 changed files with 154 additions and 147 deletions
+22
View File
@@ -0,0 +1,22 @@
"use client";
import { useTransition } from "react";
import { Button } from "@/components/ui/button";
import { ArchiveIcon } from "lucide-react";
import { Spinner } from "@/components/ui/spinner";
import { archivePageAction } from "@/lib/pages/actions";
export function ArchiveButton({ pageId }: { pageId: string }) {
const [isPending, startTransition] = useTransition();
return (
<Button
variant="secondary"
size="icon-sm"
disabled={isPending}
onClick={() => startTransition(() => archivePageAction(pageId))}
>
{isPending ? <Spinner /> : <ArchiveIcon />}
</Button>
);
}
+2 -12
View File
@@ -47,24 +47,14 @@ export default function EditPageClient({ page, pageType, initialBlocks = [] }: P
return (
<div className="flex flex-col p-16 gap-12">
<div className="flex flex-row items-center justify-between">
<h1 className="underline underline-offset-8 decoration-2">
{page ? "Edit page" : "Create page"}
</h1>
<h1 className="underline underline-offset-8 decoration-2">Edit page</h1>
<div className="flex flex-row gap-3">
<Button
variant="outline"
disabled={isPending}
onClick={() => handleSave("DRAFT")}
>
{isPending && <Loader2 size={14} className="animate-spin mr-1" />}
Save as draft
</Button>
<Button
disabled={isPending}
onClick={() => handleSave("PUBLISHED")}
>
{isPending && <Loader2 size={14} className="animate-spin mr-1" />}
Publish
Save
</Button>
</div>
</div>
+32 -8
View File
@@ -1,13 +1,17 @@
import Header from "@/components/header";
import Footer from "@/components/footer";
import { getPageBySlug, getBlocksByPageId } from "@/lib/pages/repository";
import { getCurrentUser } from "@/lib/user";
import { getCurrentUser, getUser } from "@/lib/user";
import { notFound } from "next/navigation";
import { Block, PAGE_TYPES, PageMeta, PageType } from "@/lib/pages/types";
import { formatDate } from "@/lib/utils";
import { CalendarIcon, Globe2Icon, InfoIcon } from "lucide-react";
import { ArchiveIcon, CalendarIcon, Globe2Icon, InfoIcon, PencilIcon, UserIcon } from "lucide-react";
import { Alert, AlertDescription, AlertTitle } from "@/components/ui/alert";
import { Separator } from "@/components/ui/separator";
import Link from "next/link";
import { Button } from "@/components/ui/button";
import { archivePageAction } from "@/lib/pages/actions";
import { ArchiveButton } from "./archiveButton";
function BlockRenderer({ block }: {block: Block }) {
const b = block.content
@@ -50,23 +54,43 @@ export default async function Page({ params }: { params: Promise<{ type: string;
if (!PAGE_TYPES.includes(pageType)) notFound();
const page = await getPageBySlug(slug);
if (!page) notFound();
if (!page || (!user?.isAdmin && page.status == "ARCHIVED")) notFound();
const blocks = page ? await getBlocksByPageId(page.id) : [];
const createdBy = await getUser(page?.createdBy);
const updatedBy = await getUser(page?.updatedBy);
return (
<>
<Header />
<div className="flex flex-col p-16 gap-16">
<div className="flex flex-col gap-4 items-center justify-center">
<h1 className="underline underline-offset-8 decoration-2 text-center">{page?.title}</h1>
<div className="flex flex-row gap-4 items-center">
<h3 className="flex gap-2 items-baseline"><CalendarIcon size={18} />{formatDate(page?.publishedAt)}</h3>
{formatDate(page?.publishedAt) !== formatDate(page?.updatedAt) && <h3 className="flex gap-2 items-baseline"><CalendarIcon size={18} />Updated on {formatDate(page?.updatedAt)}</h3>}
{<h3 className="flex gap-2 items-baseline"><Globe2Icon size={18} />{(page?.meta as PageMeta)?.location}</h3>}
<div className="flex flex-row items-center gap-6">
<h1 className="underline underline-offset-8 decoration-2 text-center">{page?.title}</h1>
<div className="flex flex-row gap-2 items-center">
<Link href={`/news/${page.slug}/edit`}>
<Button variant="secondary" size="icon-sm"><PencilIcon /></Button>
</Link>
{page.status != "ARCHIVED" && <ArchiveButton pageId={page.id} />}
</div>
</div>
<div className="flex flex-row gap-6 items-center">
<p className="flex gap-1.5 items-center"><CalendarIcon size={16} />{formatDate(page?.publishedAt)}</p>
{formatDate(page?.publishedAt) !== formatDate(page?.updatedAt) && <p className="flex gap-2 items-center"><CalendarIcon size={16} />Updated on {formatDate(page?.updatedAt)}</p>}
{(page?.meta as PageMeta)?.location && <p className="flex gap-1.5 items-center"><Globe2Icon size={16} />{(page?.meta as PageMeta)?.location}</p>}
{user?.isAdmin && <p className="flex gap-1.5 items-center"><UserIcon size={16} />{`${createdBy?.firstName} ${createdBy?.secondName}`}</p>}
{user?.isAdmin && page.updatedBy && page.createdBy !== page.updatedBy && <p className="flex gap-2 items-center"><CalendarIcon size={18} />Last update by {updatedBy?.firstName} ${updatedBy?.secondName}</p>}
</div>
</div>
<div className="flex flex-col gap-8">
{page.status == "ARCHIVED" && (
<Alert>
<InfoIcon />
<AlertTitle>This page is archived</AlertTitle>
<AlertDescription>It can be seen only by admins. Make any edits to make it visible again.</AlertDescription>
</Alert>
)}
{blocks.map((block) => (
<BlockRenderer key={block.id} block={block} />
))}