Files
sorsfonalak/services/frontend/src/app/forum/layout.tsx
T

59 lines
2.3 KiB
TypeScript
Raw Normal View History

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 ForumNavData, type ForumTheme } 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.",
};
/**
2026-11-26 11:41:45 +00:00
* The live connection's address: in production Caddy sends `/api/v1/forum/ws`
* straight to the forum service; in development FORUM_WS_URL points at it.
*
* 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<ForumNavData>("/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}
2026-11-26 11:41:45 +00:00
initial={{
unread: nav.ok ? (nav.data.followed?.new_replies ?? 0) : 0,
messages: nav.ok ? (nav.data.messages ?? 0) : 0,
reports: nav.ok ? (nav.data.reports ?? 0) : 0,
}}
wsUrl={process.env.FORUM_WS_URL || "/api/v1/forum/ws"}
/>
<ThemeToggle initial={theme} />
</div>
<main className="forum-main">{children}</main>
</div>
</div>
</>
);
}