Files
sorsfonalak/services/frontend/src/app/forum/[tema]/page.tsx
T
fecoandClaude Opus 5.5 36b38525c3 Forum: a service of its own and the /forum pages
services/forum (axum, port 8083) on the same database and login, in the
forum schema (migration 0038, which also adds the moderator role):
nicknames, profiles with shared signs, topics, threads with listening or
advice intent, two-level replies, read marks and followed threads,
reactions as ratings with points and ranks, newcomer limits (lifted by a
purchase), moderation with reasons, bans and a log. Integration tests run
in CI.

The frontend's /forum pages (light by default, dark on request, phone
first with a desktop layout) are switched on by FORUM_URL; the /api/v1
proxy sends /api/v1/forum/* to the forum service. Concept and status:
docs/kozosseg.md.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012vLHzh5qUhFtmJhzkcTbXL
2026-11-26 10:29:49 +00:00

82 lines
2.9 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
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<TopicPage>(`/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<Metadata> {
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 (
<div className="fh">
<nav className="forum-crumbs" aria-label="Morzsamenü">
<Link href="/forum">Fórum</Link>
</nav>
<header className="ftopic-head">
<div>
<h1>{topic.name}</h1>
<p className="muted">{topic.description}</p>
{topic.listening && (
<p className="hint">
Meghallgatós téma: itt nincs ⌄, és a szálak alapból meghallgatást kérnek, nem tanácsot.
</p>
)}
</div>
<Link
href={viewer.logged_in ? `/forum/uj?tema=${topic.slug}` : `/belepes?vissza=/forum/uj?tema=${topic.slug}`}
className="btn btn-primary"
>
Új szál
</Link>
</header>
{threads.length === 0 ? (
<p className="fh-card fh-empty">Ebben a témában még nincs szál. Nyisd meg te az elsőt!</p>
) : (
<div className="fh-card fh-flush">
<ThreadList threads={threads} showTopic={false} />
</div>
)}
{(page > 1 || has_more) && (
<nav className="forum-pager" aria-label="Lapozás">
{page > 1 ? <Link href={`/forum/${topic.slug}?oldal=${page - 1}`}>‹ Újabbak</Link> : <span />}
<span className="hint">{page}. oldal</span>
{has_more ? <Link href={`/forum/${topic.slug}?oldal=${page + 1}`}>Régebbiek ›</Link> : <span />}
</nav>
)}
</div>
);
}