54 lines
2.0 KiB
TypeScript
54 lines
2.0 KiB
TypeScript
import type { Metadata } from "next";
|
|||
|
|
import { cookies } from "next/headers";
|
||
|
|
import Link from "next/link";
|
||
|
|
import { notFound } from "next/navigation";
|
||
|
|
|
||
|
|
import { ForumNav } from "@/components/forum/ForumNav";
|
||
|
|
import { ThemeToggle } from "@/components/forum/ThemeToggle";
|
||
|
|
import { PublicHeader } from "@/components/SiteHeader";
|
||
|
|
import { FORUM_THEME_COOKIE, type ForumTheme, type ForumViewer } from "@/lib/forum";
|
||
|
|
import { forumEnabled, forumGet } from "@/lib/forumServer";
|
||
|
|
|
||
|
|
import "./forum.css";
|
||
|
|
|
||
|
|
export const metadata: Metadata = {
|
||
|
|
title: { default: "Fórum", template: "%s · Fórum · Sorsfonalak" },
|
||
|
|
description: "Spirituális fórum a Sorsfonalakon: beszélgetés, meghallgatás, asztrológia, álmok.",
|
||
|
|
};
|
||
|
|
|
||
|
|
/**
|
||
|
|
* The forum's frame: the visitor header (the logged-in one comes from the
|
||
|
|
* root layout), the forum's bar with its menu and the light/dark switch.
|
||
|
|
* Light by default; the choice lives in a cookie.
|
||
|
|
*/
|
||
|
|
export default async function ForumLayout({ children }: { children: React.ReactNode }) {
|
||
|
|
if (!forumEnabled()) notFound();
|
||
|
|
const [nav, jar] = await Promise.all([
|
||
|
|
forumGet<{ viewer: ForumViewer; followed: { new_replies: number } | null }>("/v1/forum/nav"),
|
||
|
|
cookies(),
|
||
|
|
]);
|
||
|
|
const viewer = nav.ok ? nav.data.viewer : null;
|
||
|
|
const theme: ForumTheme = jar.get(FORUM_THEME_COOKIE)?.value === "dark" ? "dark" : "light";
|
||
|
|
return (
|
||
|
|
<>
|
||
|
|
{!viewer?.logged_in && <PublicHeader current="forum" />}
|
||
|
|
<div className="forum" data-theme={theme}>
|
||
|
|
<div className="forum-inner">
|
||
|
|
<div className="forum-bar">
|
||
|
|
<Link href="/forum" className="forum-mark">
|
||
|
|
Fórum
|
||
|
|
</Link>
|
||
|
|
<ForumNav
|
||
|
|
member={viewer?.member?.nickname ?? null}
|
||
|
|
loggedIn={viewer?.logged_in ?? false}
|
||
|
|
unread={nav.ok ? (nav.data.followed?.new_replies ?? 0) : 0}
|
||
|
|
/>
|
||
|
|
<ThemeToggle initial={theme} />
|
||
|
|
</div>
|
||
|
|
<main className="forum-main">{children}</main>
|
||
|
|
</div>
|
||
|
|
</div>
|
||
|
|
</>
|
||
|
|
);
|
||
|
|
}
|