feat: basic pages system
This commit is contained in:
@@ -0,0 +1,35 @@
|
||||
import Header from "@/components/header";
|
||||
import Footer from "@/components/footer";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { getPageBySlug } from "@/lib/pages/repository";
|
||||
import { getCurrentUser } from "@/lib/user";
|
||||
import { redirect } from "next/navigation";
|
||||
import Editor from "@/components/editor";
|
||||
|
||||
export default async function EditPage({ params }: { params: Promise<{ slug: string }> }) {
|
||||
const user = await getCurrentUser();
|
||||
if (!user?.isAdmin) redirect("/");
|
||||
|
||||
const { slug } = await params;
|
||||
const page = slug === "create" ? null : await getPageBySlug(slug);
|
||||
|
||||
return (
|
||||
<>
|
||||
<Header />
|
||||
<div className="flex flex-col p-16 gap-16">
|
||||
<div className="flex flex-row items-center justify-between">
|
||||
<h1 className="underline underline-offset-8 decoration-2">
|
||||
{page ? "Edit page" : "Create page"}
|
||||
</h1>
|
||||
<div className="flex flex-row gap-4">
|
||||
<Button variant="outline">Save as draft</Button>
|
||||
<Button>Publish</Button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<Editor page={page} />
|
||||
</div>
|
||||
<Footer />
|
||||
</>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
import DraftsDialog from "@/components/drafts";
|
||||
import Footer from "@/components/footer";
|
||||
import Header from "@/components/header";
|
||||
import { Badge } from "@/components/ui/badge"
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { getPages } from "@/lib/pages/repository";
|
||||
import { PageMeta } from "@/lib/pages/types";
|
||||
import { getCurrentUser } from "@/lib/user";
|
||||
import { ArrowRight, Calendar, Globe2 } from "lucide-react";
|
||||
import Link from "next/link";
|
||||
|
||||
export default async function News() {
|
||||
const user = await getCurrentUser();
|
||||
const news = await getPages("NEWS", "PUBLISHED");
|
||||
const drafts = await getPages("NEWS", "DRAFT");
|
||||
|
||||
return (
|
||||
<>
|
||||
<Header />
|
||||
<div className="flex flex-col p-16 gap-16">
|
||||
<div className="flex flex-row items-center justify-between">
|
||||
<h1 className="underline underline-offset-8 decoration-2">News</h1>
|
||||
<div className="flex flex-row items-center gap-4">
|
||||
<DraftsDialog drafts={drafts} />
|
||||
{user?.isAdmin && (<Link href="/news/create/edit"><Button variant="secondary">Create a news page</Button></Link>)}
|
||||
</div>
|
||||
</div>
|
||||
{
|
||||
news.length > 0 ? news.map((n) => (
|
||||
<div className="flex flex-col gap-2" key={n.id}>
|
||||
<h2 className="w-max hover:underline underline-offset-8 decoration-2 duration-200 cursor-pointer">{n.title}</h2>
|
||||
<div className="flex flex-row gap-8 items-center">
|
||||
<h3 className="flex gap-2 items-baseline"><Calendar size={18} />{(n.publishedAt)?.toString()}</h3>
|
||||
<h3 className="flex gap-2 items-baseline"><Globe2 size={18} />{(n.meta as PageMeta)?.location}</h3>
|
||||
<div className="flex flex-row gap-4">
|
||||
{((n.meta as PageMeta)?.tags)?.map((i, tag) => (
|
||||
<Badge key={i}>{tag}</Badge>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
), (
|
||||
<h2 className="w-max flex flex-row items-center gap-2 hover:gap-4 hover:underline underline-offset-8 decoration-2 duration-200 cursor-pointer">See all news<ArrowRight size={32} /></h2>
|
||||
)) : <h2>There are no news yet...</h2>
|
||||
}
|
||||
</div>
|
||||
<Footer />
|
||||
</>
|
||||
);
|
||||
}
|
||||
+22
-23
@@ -1,9 +1,13 @@
|
||||
import Footer from "@/components/footer";
|
||||
import Header from "@/components/header";
|
||||
import { Badge } from "@/components/ui/badge"
|
||||
import { getPages } from "@/lib/pages/repository";
|
||||
import { PageMeta } from "@/lib/pages/types";
|
||||
import { ArrowRight, Calendar, Globe2 } from "lucide-react";
|
||||
|
||||
export default function Home() {
|
||||
export default async function Home() {
|
||||
const news = await getPages("NEWS", "PUBLISHED", 5);
|
||||
|
||||
return (
|
||||
<>
|
||||
<Header />
|
||||
@@ -32,29 +36,24 @@ export default function Home() {
|
||||
</div>
|
||||
<div className="flex flex-col gap-8 mt-8">
|
||||
<h1 className="underline underline-offset-8 decoration-2">Recent news</h1>
|
||||
<div className="flex flex-col gap-2">
|
||||
<h2 className="w-max hover:underline underline-offset-8 decoration-2 duration-200 cursor-pointer">Construction of the White House has started</h2>
|
||||
<div className="flex flex-row gap-8 items-center">
|
||||
<h3 className="flex gap-2 items-baseline"><Calendar size={18} />16 June, 2026</h3>
|
||||
<h3 className="flex gap-2 items-baseline"><Globe2 size={18} />Liberty City</h3>
|
||||
<div className="flex flex-row gap-4">
|
||||
<Badge>Liberty City</Badge>
|
||||
{
|
||||
news.length > 0 ? news.map((n) => (
|
||||
<div className="flex flex-col gap-2" key={n.id}>
|
||||
<h2 className="w-max hover:underline underline-offset-8 decoration-2 duration-200 cursor-pointer">{n.title}</h2>
|
||||
<div className="flex flex-row gap-8 items-center">
|
||||
<h3 className="flex gap-2 items-baseline"><Calendar size={18} />{(n.publishedAt)?.toString()}</h3>
|
||||
<h3 className="flex gap-2 items-baseline"><Globe2 size={18} />{(n.meta as PageMeta)?.location}</h3>
|
||||
<div className="flex flex-row gap-4">
|
||||
{((n.meta as PageMeta)?.tags)?.map((i, tag) => (
|
||||
<Badge key={i}>{tag}</Badge>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div className="flex flex-col gap-2">
|
||||
<h2 className="w-max hover:underline underline-offset-8 decoration-2 duration-200 cursor-pointer">President Volokhov has visited the Liberty City Trainbuilding Plant</h2>
|
||||
<div className="flex flex-row gap-8 items-center">
|
||||
<h3 className="flex gap-2 items-baseline"><Calendar size={18} />16 June, 2026</h3>
|
||||
<h3 className="flex gap-2 items-baseline"><Globe2 size={18} />Liberty City</h3>
|
||||
<div className="flex flex-row gap-4">
|
||||
<Badge>President</Badge>
|
||||
<Badge>Liberty City</Badge>
|
||||
<Badge>Industry</Badge>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<h2 className="w-max flex flex-row items-center gap-2 hover:gap-4 hover:underline underline-offset-8 decoration-2 duration-200 cursor-pointer">See all news<ArrowRight size={32} /></h2>
|
||||
), (
|
||||
<h2 className="w-max flex flex-row items-center gap-2 hover:gap-4 hover:underline underline-offset-8 decoration-2 duration-200 cursor-pointer">See all news<ArrowRight size={32} /></h2>
|
||||
)) : <h2>There are no news yet...</h2>
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
<Footer />
|
||||
|
||||
Reference in New Issue
Block a user