1
0
Fork 0
polaris-task-force/src/app/(frontend)/wiki/page.tsx

67 lines
2.1 KiB
TypeScript

import config from "@payload-config";
import { headers as nextHeaders } from "next/headers";
import { getPayload } from "payload";
import { BookOpenIcon } from "lucide-react";
import type { WikiPage as WikiPageDocument } from "@/payload-types";
import { WikiIndex, type WikiIndexPage } from "@/components/frontend/wiki/WikiIndex";
import { hasIntelligenceQualification } from "@/utils/access-control/hasIntelligenceQualification";
export const metadata = {
title: "Wiki: Polaris Task Force",
};
function relationName(relation: WikiPageDocument["lastEditor"]): string {
if (typeof relation === "object" && relation !== null) {
return (
relation.payloadDisplayName || relation.displayName || relation.username || "Unknown editor"
);
}
return typeof relation === "number" ? `User #${relation}` : "Unknown editor";
}
export default async function WikiPage() {
const headers = await nextHeaders();
const payload = await getPayload({ config });
const { user } = await payload.auth({
headers,
canSetHeaders: false,
});
const [pagesResult, isModerator] = await Promise.all([
payload.find({
collection: "wiki-pages",
sort: "-updatedAt",
limit: 200,
depth: 1,
overrideAccess: true,
}),
hasIntelligenceQualification(payload, user),
]);
const pages: WikiIndexPage[] = pagesResult.docs.map((page) => ({
id: page.id,
title: page.title,
slug: page.slug,
category: page.category,
tags: page.tags ?? [],
updatedAt: page.updatedAt,
lastEditorName: relationName(page.lastEditor),
}));
return (
<div className="flex flex-col gap-6 p-5">
<div className="flex flex-col gap-1">
<div className="flex items-center gap-2">
<BookOpenIcon className="size-5 text-muted-foreground" />
<h1 className="text-lg font-semibold">Wiki</h1>
</div>
<p className="text-sm text-muted-foreground">
A shared field guide for campaigns, characters, places, and the stories around them.
</p>
</div>
<WikiIndex pages={pages} isModerator={isModerator} />
</div>
);
}