import type { Metadata } from "next"; import Link from "next/link"; import { notFound, redirect } from "next/navigation"; import { ThreadList } from "@/components/forum/ThreadList"; import type { TopicPage } from "@/lib/forum"; import { forumGet } from "@/lib/forumServer"; type Props = { params: Promise<{ tema: string }>; searchParams: Promise<{ oldal?: string }> }; async function load(slug: string, page: number) { return forumGet(`/v1/forum/topics/${encodeURIComponent(slug)}?page=${page}`); } function pageOf(raw: string | undefined): number { const n = Number(raw ?? 1); return Number.isInteger(n) && n > 0 ? n : 1; } export async function generateMetadata({ params }: Props): Promise { const { tema } = await params; const res = await load(tema, 1); if (!res.ok) return { title: "Fórum" }; const { topic } = res.data; // Members-only topics stay out of search engines. return { title: topic.name, description: topic.description, robots: topic.visibility === "public" ? undefined : { index: false, follow: false }, }; } /** A topic's threads: pinned ones first, then by the latest post. */ export default async function TopicPageView({ params, searchParams }: Props) { const { tema } = await params; const page = pageOf((await searchParams).oldal); const res = await load(tema, page); if (!res.ok) { if (res.status === 401) redirect(`/belepes?vissza=/forum/${tema}`); notFound(); } const { topic, threads, has_more, viewer } = res.data; return (

{topic.name}

{topic.description}

{topic.listening && (

Meghallgatós téma: itt nincs ⌄, és a szálak alapból meghallgatást kérnek, nem tanácsot.

)}
Új szál
{threads.length === 0 ? (

Ebben a témában még nincs szál. Nyisd meg te az elsőt!

) : (
)} {(page > 1 || has_more) && ( )}
); }