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
This commit is contained in:
@@ -9,7 +9,7 @@ import { ROLE_LABELS, formatDate } from "@/lib/astro";
|
||||
import type { AdminUser, Package, Role } from "@/lib/types";
|
||||
|
||||
const PAGE_SIZE = 25;
|
||||
const EDITABLE_ROLES: Role[] = ["user", "creator", "admin"];
|
||||
const EDITABLE_ROLES: Role[] = ["user", "creator", "moderator", "admin"];
|
||||
type UnitKind = "natal" | "synastry" | "forecast" | "question" | "tarot";
|
||||
|
||||
/** `short`: the mark in the list, where the names do not fit (explained under it). */
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
// Forwards /api/v1/* to the backend, so the browser talks to one origin and
|
||||
// the session cookie belongs to the frontend's host (no CORS needed).
|
||||
// Forwards /api/v1/* to the backend (and /api/v1/forum/* to the forum
|
||||
// service), so the browser talks to one origin and the session cookie belongs
|
||||
// to the frontend's host (no CORS needed).
|
||||
import { revalidateTag } from "next/cache";
|
||||
import type { NextRequest } from "next/server";
|
||||
|
||||
import { CELEBRITIES_TAG } from "@/lib/celebrities";
|
||||
import { FORUM_URL } from "@/lib/forumServer";
|
||||
import { BACKEND_URL } from "@/lib/server";
|
||||
import { SHARES_TAG } from "@/lib/share";
|
||||
|
||||
@@ -22,7 +24,13 @@ const SKIP_RESPONSE_HEADERS = new Set(["connection", "content-encoding", "conten
|
||||
|
||||
async function forward(req: NextRequest, ctx: { params: Promise<{ path: string[] }> }) {
|
||||
const { path } = await ctx.params;
|
||||
const target = `${BACKEND_URL}/v1/${path.map(encodeURIComponent).join("/")}${req.nextUrl.search}`;
|
||||
// The forum is a service of its own; without FORUM_URL it is switched off.
|
||||
const forum = path[0] === "forum";
|
||||
if (forum && !FORUM_URL) {
|
||||
return Response.json({ error: { code: "not_found", message: "A fórum nincs bekapcsolva." } }, { status: 404 });
|
||||
}
|
||||
const base = forum ? FORUM_URL : BACKEND_URL;
|
||||
const target = `${base}/v1/${path.map(encodeURIComponent).join("/")}${req.nextUrl.search}`;
|
||||
|
||||
const headers = new Headers();
|
||||
for (const name of REQUEST_HEADERS) {
|
||||
|
||||
@@ -0,0 +1,81 @@
|
||||
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>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,205 @@
|
||||
"use client";
|
||||
|
||||
import { useRouter } from "next/navigation";
|
||||
import { useEffect, useState } from "react";
|
||||
|
||||
import { AVATAR_COLOURS, AVATAR_GLYPHS, Avatar, GLYPH_NAMES } from "@/components/forum/Avatar";
|
||||
import { signsText } from "@/components/forum/AuthorLine";
|
||||
import { api, errorText } from "@/lib/api";
|
||||
import { type ChartShare, type ForumMe, banText, memberHref } from "@/lib/forum";
|
||||
|
||||
const SHARE_LEVELS: { value: ChartShare; label: string }[] = [
|
||||
{ value: "none", label: "Semmit" },
|
||||
{ value: "sun", label: "Csak a Nap-jegyemet" },
|
||||
{ value: "big3", label: "Nap, Hold és Aszcendens" },
|
||||
{ value: "planets", label: "Minden bolygó jegyét" },
|
||||
];
|
||||
|
||||
export function ProfileForm({ me, back }: { me: ForumMe; back: string | null }) {
|
||||
const router = useRouter();
|
||||
const member = me.member;
|
||||
const [nickname, setNickname] = useState(member?.nickname ?? "");
|
||||
const [check, setCheck] = useState<{ ok: boolean; message?: string } | null>(null);
|
||||
const [avatar, setAvatar] = useState(member?.avatar ?? "");
|
||||
const [bio, setBio] = useState(member?.bio ?? "");
|
||||
const [share, setShare] = useState<ChartShare>(member?.chart_share ?? "none");
|
||||
const [invisible, setInvisible] = useState(member?.invisible ?? false);
|
||||
const [busy, setBusy] = useState(false);
|
||||
const [error, setError] = useState<string | null>(null);
|
||||
const [saved, setSaved] = useState(false);
|
||||
|
||||
// While typing: valid and free? (Not for the member's own current name.)
|
||||
useEffect(() => {
|
||||
const name = nickname.trim();
|
||||
if (!name || name === member?.nickname) {
|
||||
setCheck(null);
|
||||
return;
|
||||
}
|
||||
const timer = window.setTimeout(() => {
|
||||
api<{ ok: boolean; message?: string }>(`/forum/nickname-check?name=${encodeURIComponent(name)}`)
|
||||
.then(setCheck)
|
||||
.catch(() => setCheck(null));
|
||||
}, 400);
|
||||
return () => window.clearTimeout(timer);
|
||||
}, [nickname, member?.nickname]);
|
||||
|
||||
async function submit(e: React.FormEvent) {
|
||||
e.preventDefault();
|
||||
setBusy(true);
|
||||
setError(null);
|
||||
setSaved(false);
|
||||
try {
|
||||
const res = await api<ForumMe>("/forum/me", {
|
||||
method: "PUT",
|
||||
body: { nickname, avatar: avatar || null, bio, chart_share: share, invisible },
|
||||
});
|
||||
if (back) {
|
||||
router.push(back);
|
||||
} else if (!member && res.member) {
|
||||
router.push(memberHref(res.member.nickname));
|
||||
} else {
|
||||
setSaved(true);
|
||||
}
|
||||
router.refresh();
|
||||
} catch (err) {
|
||||
setError(errorText(err));
|
||||
} finally {
|
||||
setBusy(false);
|
||||
}
|
||||
}
|
||||
|
||||
const preview = share === "none" ? null : me.chart?.[share];
|
||||
|
||||
return (
|
||||
<form className="fprof" onSubmit={submit}>
|
||||
{member?.banned_until && (
|
||||
<p className="fh-banner fh-banner-warn">
|
||||
Most nem írhatsz a fórumba ({banText(member.banned_until)}).
|
||||
{member.ban_reason && ` Indok: ${member.ban_reason}`}
|
||||
</p>
|
||||
)}
|
||||
|
||||
<div className="field">
|
||||
<label htmlFor="fprof-nick">Álnév</label>
|
||||
<input
|
||||
id="fprof-nick"
|
||||
className="inp"
|
||||
value={nickname}
|
||||
onChange={(e) => setNickname(e.target.value)}
|
||||
maxLength={24}
|
||||
required
|
||||
autoComplete="off"
|
||||
aria-describedby="fprof-nick-hint"
|
||||
/>
|
||||
<span id="fprof-nick-hint" className={check && !check.ok ? "hint warn" : "hint"}>
|
||||
{check && !check.ok
|
||||
? check.message
|
||||
: check?.ok
|
||||
? "Szabad, választhatod."
|
||||
: "Ne a valódi neved legyen, ha nem szeretnéd, hogy felismerjenek. 3–24 karakter: betűk, számok, szóköz, kötőjel."}
|
||||
</span>
|
||||
{member?.nickname_change_after && (
|
||||
<span className="hint">
|
||||
Új álnevet{" "}
|
||||
{new Date(member.nickname_change_after).toLocaleDateString("hu-HU", { month: "long", day: "numeric" })} után
|
||||
választhatsz (az ékezet és a kis- és nagybetű javítható addig is).
|
||||
</span>
|
||||
)}
|
||||
</div>
|
||||
|
||||
<fieldset className="fnew-set">
|
||||
<legend>Avatar</legend>
|
||||
<div className="fprof-avatars">
|
||||
{AVATAR_COLOURS.flatMap((colour) =>
|
||||
AVATAR_GLYPHS.map((glyph) => {
|
||||
const value = `${glyph}-${colour}`;
|
||||
return (
|
||||
<label key={value} className="fprof-avatar" title={GLYPH_NAMES[glyph]}>
|
||||
<input
|
||||
type="radio"
|
||||
name="avatar"
|
||||
value={value}
|
||||
checked={avatar === value}
|
||||
onChange={() => setAvatar(value)}
|
||||
className="sr-only"
|
||||
/>
|
||||
<Avatar avatar={value} size={44} />
|
||||
<span className="sr-only">{GLYPH_NAMES[glyph]}</span>
|
||||
</label>
|
||||
);
|
||||
}),
|
||||
)}
|
||||
</div>
|
||||
{!avatar && <span className="hint">Ha nem választasz, az álneved alapján kapsz egyet.</span>}
|
||||
</fieldset>
|
||||
|
||||
<div className="field">
|
||||
<label htmlFor="fprof-bio">Bemutatkozás</label>
|
||||
<textarea
|
||||
id="fprof-bio"
|
||||
className="fc-text"
|
||||
rows={4}
|
||||
maxLength={500}
|
||||
value={bio}
|
||||
onChange={(e) => setBio(e.target.value)}
|
||||
placeholder="Pár mondat magadról, ha szeretnéd."
|
||||
/>
|
||||
<span className="hint">{bio.length}/500 · link nem tehető bele</span>
|
||||
</div>
|
||||
|
||||
<fieldset className="fnew-set">
|
||||
<legend>Mit mutatsz meg a képletedből?</legend>
|
||||
<div className="fnew-intents">
|
||||
{SHARE_LEVELS.map((level) => (
|
||||
<label key={level.value} className="fnew-intent">
|
||||
<input type="radio" name="share" checked={share === level.value} onChange={() => setShare(level.value)} />
|
||||
<span>
|
||||
<strong>{level.label}</strong>
|
||||
</span>
|
||||
</label>
|
||||
))}
|
||||
</div>
|
||||
<span className="hint">
|
||||
{me.chart === null
|
||||
? "Még nincs saját képleted, így most semmi nem látszana."
|
||||
: preview
|
||||
? `Így látszik a neved mellett: ${signsText(preview)}`
|
||||
: share === "none"
|
||||
? "Semmi nem látszik a képletedből."
|
||||
: "Ehhez a szinthez nincs adat a képletedben."}{" "}
|
||||
Fokokat soha nem mutatunk, mert azokból kiszámolható a születési időd.
|
||||
</span>
|
||||
</fieldset>
|
||||
|
||||
<label className="fprof-check">
|
||||
<input type="checkbox" checked={invisible} onChange={(e) => setInvisible(e.target.checked)} />
|
||||
<span>
|
||||
<strong>Láthatatlan mód</strong>
|
||||
<span className="hint">Nem jelenik meg mellettem a zöld pötty, és az sem, mikor jártam itt utoljára.</span>
|
||||
</span>
|
||||
</label>
|
||||
|
||||
{member && (
|
||||
<div className="fprof-rank">
|
||||
<span className="eyebrow">Rangod</span>
|
||||
<strong>{member.rank_name}</strong>
|
||||
<span className="hint">
|
||||
{member.points} pont · {member.post_count} hozzászólás
|
||||
{member.next_rank &&
|
||||
` · a ${member.next_rank.name} ranghoz ${member.next_rank.points} pont és ${member.next_rank.days} nap tagság kell`}
|
||||
</span>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{error && (
|
||||
<p className="msg msg-error" role="alert">
|
||||
{error}
|
||||
</p>
|
||||
)}
|
||||
{saved && <p className="msg">Elmentve.</p>}
|
||||
<button type="submit" className="btn btn-primary" disabled={busy || !nickname.trim() || check?.ok === false}>
|
||||
{busy ? "Mentés…" : member ? "Mentés" : "Álnév mentése"}
|
||||
</button>
|
||||
</form>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
import { redirect } from "next/navigation";
|
||||
|
||||
import type { ForumMe } from "@/lib/forum";
|
||||
import { forumGet } from "@/lib/forumServer";
|
||||
|
||||
import { ProfileForm } from "./ProfileForm";
|
||||
|
||||
export const metadata = { title: "Fórumprofil", robots: { index: false } };
|
||||
|
||||
type Props = { searchParams: Promise<{ vissza?: string }> };
|
||||
|
||||
/** The member's forum profile: the nickname first, then avatar, bio, signs, visibility. */
|
||||
export default async function ForumSettingsPage({ searchParams }: Props) {
|
||||
const { vissza } = await searchParams;
|
||||
const res = await forumGet<ForumMe>("/v1/forum/me");
|
||||
if (!res.ok) redirect(`/belepes?vissza=${encodeURIComponent("/forum/beallitasok")}`);
|
||||
// Only back into the forum.
|
||||
const back = vissza?.startsWith("/forum") ? vissza : null;
|
||||
const me = res.data;
|
||||
return (
|
||||
<div className="fh">
|
||||
<h1 className="fpage-title">{me.member ? "Fórumprofil" : "Válassz álnevet"}</h1>
|
||||
{!me.member && (
|
||||
<p className="muted">
|
||||
A fórumon mindenki álnéven ír. A valódi neved, az e-mail-címed és a születési adataid soha nem jelennek meg
|
||||
itt.
|
||||
</p>
|
||||
)}
|
||||
<ProfileForm me={me} back={back} />
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,447 @@
|
||||
/* The forum: phones first (most members write from a phone), big touch
|
||||
targets and text for the 50+ readers. Light by default, dark on request
|
||||
(data-theme on .forum, from a cookie): both redefine the site's colour
|
||||
tokens for the forum's part of the page, so the shared .btn, .inp, .hint
|
||||
and links follow. */
|
||||
|
||||
/* --- themes --- */
|
||||
.forum {
|
||||
--f-hover: rgba(255, 255, 255, 0.04);
|
||||
--f-tint: rgba(217, 180, 106, 0.1);
|
||||
--f-tint-strong: rgba(217, 180, 106, 0.14);
|
||||
--f-nav-bg: rgba(13, 18, 32, 0.97);
|
||||
--f-shadow: 0 16px 40px rgba(0, 0, 0, 0.45);
|
||||
--f-border-hover: #5a6790;
|
||||
--f-online: #9fd8b0;
|
||||
--f-blue-tint: rgba(127, 176, 224, 0.12);
|
||||
--f-orange-tint: rgba(240, 163, 94, 0.12);
|
||||
--f-red-tint: rgba(242, 160, 160, 0.08);
|
||||
--f-green-tint: rgba(159, 216, 176, 0.12);
|
||||
color: var(--ink);
|
||||
}
|
||||
.forum[data-theme="light"] {
|
||||
--bg: #f6f3ed;
|
||||
--panel: #ffffff;
|
||||
--panel-2: #faf8f4;
|
||||
--line: #e6dfd2;
|
||||
--line-2: #d3c9b6;
|
||||
--ink: #1b2236;
|
||||
--ink-2: #3a4259;
|
||||
--muted: #5c6376;
|
||||
--gold: #8a6a24;
|
||||
--gold-hover: #6e5419;
|
||||
--gold-ink: #ffffff;
|
||||
--danger: #b03a3a;
|
||||
--ok: #2d7a4c;
|
||||
--harmonic: #2c66a0;
|
||||
--square: #9c520e;
|
||||
--f-hover: rgba(27, 34, 54, 0.04);
|
||||
--f-tint: rgba(167, 128, 47, 0.09);
|
||||
--f-tint-strong: rgba(167, 128, 47, 0.14);
|
||||
--f-nav-bg: rgba(255, 255, 255, 0.97);
|
||||
--f-shadow: 0 12px 32px rgba(27, 34, 54, 0.14);
|
||||
--f-border-hover: #a99d86;
|
||||
--f-online: #2fa865;
|
||||
--f-blue-tint: rgba(44, 102, 160, 0.09);
|
||||
--f-orange-tint: rgba(156, 82, 14, 0.09);
|
||||
--f-red-tint: rgba(176, 58, 58, 0.07);
|
||||
--f-green-tint: rgba(45, 122, 76, 0.1);
|
||||
color-scheme: light;
|
||||
}
|
||||
/* The light forum takes the whole page between the (dark) header and footer
|
||||
(the body rule; the background here is for browsers without :has). */
|
||||
.forum[data-theme="light"] { background: var(--bg); min-height: 70vh; }
|
||||
body:has(.forum[data-theme="light"]) { background: #f6f3ed; }
|
||||
body:has(.forum[data-theme="light"]) .night-sky { display: none; }
|
||||
body:has(.forum[data-theme="light"]) .site-footer { background: #0d1220; }
|
||||
.forum[data-theme="light"] .inp:focus { background-color: var(--panel); box-shadow: 0 0 0 3px rgba(167, 128, 47, 0.22); }
|
||||
.forum[data-theme="light"] .inp::placeholder { color: #8b8f9c; }
|
||||
.forum[data-theme="light"] .btn:hover { border-color: var(--f-border-hover); background: var(--f-hover); }
|
||||
.forum[data-theme="light"] .moon-phase-icon .moon-dark { fill: #ebe5d8; stroke: #b99550; }
|
||||
.forum[data-theme="light"] .moon-phase-icon .moon-lit { fill: #d9b46a; }
|
||||
|
||||
/* --- frame --- */
|
||||
.forum-inner { max-width: 1180px; margin: 0 auto; padding: 8px 16px 104px; }
|
||||
.forum-main { display: flex; flex-direction: column; }
|
||||
.forum h1, .forum h2 { font-family: var(--font-display); font-weight: 600; color: var(--ink); }
|
||||
.forum-bar { display: flex; align-items: center; justify-content: space-between; gap: 12px; min-height: 52px; margin-bottom: 8px; }
|
||||
.forum-mark { font-family: var(--font-display); font-size: 26px; font-weight: 600; color: var(--ink); text-decoration: none; }
|
||||
.forum-mark:hover { color: var(--gold); }
|
||||
.forum-theme {
|
||||
display: inline-flex; align-items: center; gap: 8px; min-width: 44px; min-height: 44px; padding: 0 10px; justify-content: center;
|
||||
border: 1px solid var(--line-2); border-radius: 999px; background: var(--panel); color: var(--ink-2);
|
||||
font: 500 14px var(--font-body); cursor: pointer;
|
||||
}
|
||||
.forum-theme:hover { color: var(--gold); border-color: var(--f-border-hover); }
|
||||
.forum-theme svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
|
||||
.forum-theme-label { display: none; }
|
||||
|
||||
/* The forum's menu: a bar at the bottom on phones, tabs in the forum bar on wider screens. */
|
||||
.forum-nav {
|
||||
position: fixed; left: 0; right: 0; bottom: 0; z-index: 25;
|
||||
display: grid; grid-template-columns: repeat(4, minmax(0, 1fr));
|
||||
background: var(--f-nav-bg); border-top: 1px solid var(--line);
|
||||
padding-bottom: env(safe-area-inset-bottom);
|
||||
box-shadow: 0 -4px 16px rgba(0, 0, 0, 0.08);
|
||||
}
|
||||
.fn-item {
|
||||
display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
|
||||
min-height: 62px; color: var(--ink-2); text-decoration: none; font-size: 12px;
|
||||
}
|
||||
.fn-item[aria-current="page"] { color: var(--gold); font-weight: 600; }
|
||||
.fn-item:hover { color: var(--gold); }
|
||||
.fn-icon-wrap { position: relative; display: inline-flex; }
|
||||
.fn-icon { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
|
||||
.fn-badge {
|
||||
position: absolute; top: -6px; right: -11px; min-width: 18px; height: 18px; padding: 0 5px; box-sizing: border-box;
|
||||
border-radius: 999px; background: var(--gold); color: var(--gold-ink); font-size: 11px; font-weight: 600; line-height: 18px; text-align: center;
|
||||
}
|
||||
@media (min-width: 760px) {
|
||||
.forum-inner { padding: 20px 24px 64px; }
|
||||
.forum-bar {
|
||||
gap: 16px; margin-bottom: 24px; padding: 6px 6px 6px 18px;
|
||||
background: var(--panel); border: 1px solid var(--line); border-radius: 16px;
|
||||
}
|
||||
.forum-nav {
|
||||
position: static; flex: 1; display: flex; gap: 4px; padding: 0;
|
||||
background: none; border: 0; box-shadow: none;
|
||||
}
|
||||
.fn-item { flex-direction: row; gap: 8px; min-height: 44px; padding: 0 14px; border-radius: 10px; font-size: 15px; }
|
||||
.fn-item[aria-current="page"] { background: var(--f-tint); }
|
||||
.fn-icon { width: 20px; height: 20px; }
|
||||
.forum-theme { padding: 0 14px; }
|
||||
.forum-theme-label { display: inline; }
|
||||
}
|
||||
|
||||
/* --- avatars and the author line --- */
|
||||
.av { position: relative; display: inline-flex; flex: none; }
|
||||
.av svg { display: block; }
|
||||
/* The night-coloured avatars keep the bright gold in both themes. */
|
||||
.av-glyph { fill: none; stroke: #d9b46a; stroke-width: 2.2; stroke-linecap: round; stroke-linejoin: round; }
|
||||
.av-glyph .av-fill { fill: #d9b46a; stroke: none; }
|
||||
.av-online {
|
||||
position: absolute; right: -1px; bottom: -1px; width: 28%; height: 28%; min-width: 9px; min-height: 9px;
|
||||
border-radius: 50%; background: var(--f-online); border: 2px solid var(--panel); box-sizing: border-box;
|
||||
}
|
||||
.fa-line { display: flex; align-items: center; gap: 10px; min-width: 0; }
|
||||
.fa-avatar { display: inline-flex; }
|
||||
.fa-meta { display: flex; flex-direction: column; gap: 1px; min-width: 0; }
|
||||
.fa-names { display: flex; align-items: center; flex-wrap: wrap; gap: 6px; }
|
||||
.fa-name { font-size: 16px; font-weight: 600; color: var(--ink); text-decoration: none; }
|
||||
.fa-name:hover { color: var(--gold); }
|
||||
.fa-rank { font-size: 12px; color: var(--ink-2); border: 1px solid var(--line-2); border-radius: 6px; padding: 0 6px; }
|
||||
.fa-badge { font-size: 12px; border-radius: 6px; padding: 0 6px; }
|
||||
.fa-badge-mod { color: var(--ok); background: var(--f-green-tint); }
|
||||
.fa-badge-starter { color: var(--gold); border: 1px solid var(--line-2); }
|
||||
.fa-badge-new { color: var(--gold-ink); background: var(--gold); font-weight: 600; }
|
||||
.fa-sub { font-size: 13px; color: var(--muted); }
|
||||
|
||||
/* --- cards, banners, sections --- */
|
||||
.fh { display: flex; flex-direction: column; gap: 22px; }
|
||||
.fh-card { background: var(--panel); border: 1px solid var(--line); border-radius: 16px; padding: 18px; }
|
||||
.forum[data-theme="light"] .fh-card { box-shadow: 0 1px 2px rgba(27, 34, 54, 0.04); }
|
||||
.fh-flush { padding: 0; overflow: hidden; }
|
||||
.fh-empty { color: var(--muted); }
|
||||
.fh-card-head { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; margin-bottom: 12px; }
|
||||
.fh-intro { display: flex; flex-direction: column; gap: 12px; align-items: flex-start; }
|
||||
.fh-intro h1 { font-size: 36px; }
|
||||
.fh-banner {
|
||||
display: flex; align-items: center; gap: 12px; justify-content: space-between;
|
||||
min-height: 52px; padding: 12px 14px; border-radius: 12px;
|
||||
background: var(--f-tint); border: 1px solid var(--line-2); color: var(--ink); text-decoration: none;
|
||||
}
|
||||
.fh-banner strong { color: var(--gold); font-weight: 600; }
|
||||
.fh-banner:hover { color: var(--ink); background: var(--f-tint-strong); }
|
||||
.fh-banner-warn { background: var(--f-red-tint); border-color: var(--danger); }
|
||||
.fh-section { display: flex; flex-direction: column; gap: 12px; }
|
||||
.fh-section-head { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; }
|
||||
.fh-section-head h2 { font-size: 24px; }
|
||||
.fh-sky-body { display: flex; gap: 16px; align-items: flex-start; }
|
||||
.fh-moon .moon-phase-icon { width: 56px; height: 56px; }
|
||||
.fh-sky-text { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
|
||||
.fh-sky-text h2 { font-size: 24px; line-height: 1.15; }
|
||||
.fh-sky-text p { color: var(--ink-2); font-size: 16px; }
|
||||
.fh-sky-link, .fh-side-link { display: inline-flex; align-items: center; min-height: 44px; margin-top: 8px; font-size: 15px; }
|
||||
.fh-waiting-grid { display: grid; gap: 12px; }
|
||||
@media (min-width: 760px) { .fh-waiting-grid { grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); } }
|
||||
.fh-me { display: flex; flex-direction: column; gap: 14px; }
|
||||
.fh-me-head { display: flex; align-items: center; gap: 12px; }
|
||||
.fh-me-names { display: flex; flex-direction: column; gap: 4px; align-items: flex-start; }
|
||||
.fh-me-actions { display: flex; gap: 8px; flex-wrap: wrap; }
|
||||
|
||||
/* Front page: one column on phones in reading order (the two columns'
|
||||
blocks interleave), main column and sidebar from 1024 px. */
|
||||
.fh-home .fh-col { display: contents; }
|
||||
.o-1 { order: 1; } .o-2 { order: 2; } .o-3 { order: 3; } .o-4 { order: 4; }
|
||||
.o-5 { order: 5; } .o-6 { order: 6; } .o-7 { order: 7; } .o-8 { order: 8; }
|
||||
@media (min-width: 1024px) {
|
||||
.fh-home { display: grid; grid-template-columns: minmax(0, 1fr) 340px; gap: 28px; align-items: start; }
|
||||
.fh-home .fh-col { display: flex; flex-direction: column; gap: 22px; }
|
||||
.fh-home .fh-col-side { position: sticky; top: 88px; }
|
||||
}
|
||||
|
||||
/* --- topics --- */
|
||||
.fh-topics { list-style: none; margin: 0; }
|
||||
.fh-topics li + li { border-top: 1px solid var(--line); }
|
||||
.fh-topic { display: flex; align-items: center; gap: 14px; padding: 14px 16px; min-height: 76px; color: var(--ink); text-decoration: none; }
|
||||
.fh-topic:hover { color: var(--ink); background: var(--f-hover); }
|
||||
.fh-topic-icon {
|
||||
flex: none; width: 44px; height: 44px; border-radius: 12px; background: var(--f-tint);
|
||||
display: inline-flex; align-items: center; justify-content: center;
|
||||
}
|
||||
.topic-icon { width: 24px; height: 24px; fill: none; stroke: var(--gold); stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
|
||||
.fh-topic-text { display: flex; flex-direction: column; gap: 2px; flex: 1; min-width: 0; }
|
||||
.fh-topic-name { display: flex; align-items: center; gap: 8px; font-size: 17px; font-weight: 600; }
|
||||
.fh-lock { width: 14px; height: 14px; fill: none; stroke: var(--muted); stroke-width: 2; stroke-linecap: round; }
|
||||
.fh-topic-desc { font-size: 14px; color: var(--muted); }
|
||||
.fh-topic-last { display: flex; align-items: center; gap: 6px; font-size: 13px; color: var(--muted); }
|
||||
.fh-topic-count { display: none; flex: none; font-size: 14px; color: var(--muted); text-align: right; min-width: 64px; }
|
||||
.fh-topic-count strong { color: var(--ink); font-weight: 600; }
|
||||
@media (min-width: 640px) { .fh-topic-count { display: block; } }
|
||||
|
||||
/* --- thread lists: a meta line on phones, columns on wider screens --- */
|
||||
.ft-list { list-style: none; margin: 0; padding: 0; }
|
||||
.ft-list li + li { border-top: 1px solid var(--line); }
|
||||
.ft-row { display: flex; align-items: center; gap: 12px; padding: 14px 16px; min-height: 64px; color: var(--ink); text-decoration: none; }
|
||||
.ft-row:hover { color: var(--ink); background: var(--f-hover); }
|
||||
.ft-main { display: flex; flex-direction: column; gap: 4px; flex: 1; min-width: 0; }
|
||||
.ft-title { font-size: 17px; font-weight: 600; line-height: 1.35; }
|
||||
.ft-row:hover .ft-title { color: var(--gold); }
|
||||
.ft-excerpt { font-size: 14px; color: var(--ink-2); display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
|
||||
.ft-meta { display: flex; align-items: center; gap: 8px; font-size: 14px; color: var(--muted); }
|
||||
.ft-col { display: none; }
|
||||
.ft-new {
|
||||
flex: none; font-size: 13px; font-weight: 600; color: var(--gold-ink); background: var(--gold);
|
||||
border-radius: 999px; padding: 2px 9px; white-space: nowrap;
|
||||
}
|
||||
.ft-read { flex: none; font-size: 13px; color: var(--muted); }
|
||||
@media (min-width: 760px) {
|
||||
.ft-row { display: grid; grid-template-columns: minmax(0, 1fr) 110px 100px 72px; gap: 16px; padding: 14px 20px; }
|
||||
.ft-m-narrow { display: none; }
|
||||
.ft-col { display: flex; flex-direction: column; align-items: flex-end; font-size: 14px; color: var(--muted); }
|
||||
.ft-col strong { color: var(--ink); font-weight: 600; font-size: 16px; }
|
||||
.ft-col-replies { flex-direction: row; gap: 4px; align-items: baseline; justify-content: flex-end; flex-wrap: wrap; }
|
||||
.ft-col-replies .hint { flex-basis: 100%; text-align: right; }
|
||||
.ft-new, .ft-read { justify-self: end; }
|
||||
}
|
||||
.ft-pin {
|
||||
display: inline-block; margin-right: 8px; vertical-align: 2px; font-size: 12px; font-weight: 500;
|
||||
color: var(--ink-2); border: 1px solid var(--line-2); border-radius: 6px; padding: 0 6px;
|
||||
}
|
||||
.ft-intent { align-self: flex-start; font-size: 13px; font-weight: 500; border-radius: 999px; padding: 3px 10px; }
|
||||
.ft-intent-listen { color: var(--harmonic); background: var(--f-blue-tint); }
|
||||
.ft-intent-advice { color: var(--square); background: var(--f-orange-tint); }
|
||||
.ft-waiting {
|
||||
display: flex; flex-direction: column; gap: 10px; padding: 16px; border-radius: 14px;
|
||||
background: var(--panel); border: 1px solid var(--line);
|
||||
}
|
||||
.ft-waiting-title { font-size: 18px; font-weight: 600; line-height: 1.35; color: var(--ink); text-decoration: none; }
|
||||
.ft-waiting-title:hover { color: var(--gold); }
|
||||
.ft-answer { align-self: flex-start; min-height: 44px; border-color: var(--gold); color: var(--gold); margin-top: auto; }
|
||||
|
||||
/* --- topic page and the other headings --- */
|
||||
.forum-crumbs { display: flex; gap: 8px; align-items: center; font-size: 14px; color: var(--muted); }
|
||||
.forum-crumbs a { color: var(--ink-2); text-decoration: none; min-height: 32px; display: inline-flex; align-items: center; }
|
||||
.forum-crumbs a:hover { color: var(--gold); }
|
||||
.ftopic-head { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: flex-start; gap: 16px; }
|
||||
.ftopic-head h1, .fpage-title { font-size: 34px; line-height: 1.1; }
|
||||
.ftopic-head > div { display: flex; flex-direction: column; gap: 6px; max-width: 620px; }
|
||||
.forum-pager { display: flex; justify-content: space-between; align-items: center; min-height: 44px; }
|
||||
|
||||
/* --- thread view --- */
|
||||
.ftv { display: flex; flex-direction: column; gap: 12px; width: 100%; max-width: 980px; margin: 0 auto; }
|
||||
.ftv-toolbar { display: flex; justify-content: flex-end; gap: 8px; flex-wrap: wrap; }
|
||||
.ftv-toolbar:empty { display: none; }
|
||||
.ftv-mod { position: relative; }
|
||||
.ftv-mod summary { list-style: none; cursor: pointer; }
|
||||
.ftv-mod summary::-webkit-details-marker { display: none; }
|
||||
.ftv-mod-menu {
|
||||
position: absolute; right: 0; top: calc(100% + 6px); z-index: 10; min-width: 200px; padding: 6px;
|
||||
display: flex; flex-direction: column; background: var(--panel); border: 1px solid var(--line-2); border-radius: 12px;
|
||||
box-shadow: var(--f-shadow);
|
||||
}
|
||||
.ftv-mod-menu button {
|
||||
min-height: 44px; padding: 0 12px; border: 0; border-radius: 8px; background: none; color: var(--ink);
|
||||
font: inherit; font-size: 15px; text-align: left; cursor: pointer;
|
||||
}
|
||||
.ftv-mod-menu button:hover { background: var(--f-hover); color: var(--gold); }
|
||||
.ftv-mod-menu button.danger { color: var(--danger); }
|
||||
.ftv-intent {
|
||||
display: flex; flex-direction: column; gap: 4px; padding: 12px 14px; border-radius: 12px;
|
||||
background: var(--f-blue-tint); font-size: 14px; line-height: 1.45; color: var(--ink-2);
|
||||
}
|
||||
.ftv-intent strong { color: var(--harmonic); font-weight: 600; }
|
||||
.ftv-intent-advice { background: var(--f-orange-tint); }
|
||||
.ftv-intent-advice strong { color: var(--square); }
|
||||
.ftv-title { font-size: 30px; line-height: 1.12; }
|
||||
.ftv-count { display: flex; justify-content: space-between; align-items: baseline; padding-top: 6px; }
|
||||
.ftv .ftv-count h2 { font-family: var(--font-body); font-size: 15px; color: var(--ink-2); }
|
||||
.ftv-branch { display: flex; flex-direction: column; }
|
||||
.ftv-children { margin-left: 17px; padding-left: 14px; border-left: 2px solid var(--line); display: flex; flex-direction: column; }
|
||||
.ftv-marker { display: flex; align-items: center; gap: 10px; margin: 8px 0 0; color: var(--gold); font-size: 13px; font-weight: 600; }
|
||||
.ftv-marker::before, .ftv-marker::after { content: ""; flex: 1; height: 1px; background: var(--gold); opacity: 0.5; }
|
||||
.ftv-incoming {
|
||||
position: sticky; bottom: 84px; align-self: center; z-index: 5;
|
||||
display: inline-flex; align-items: center; min-height: 44px; padding: 0 18px; border: 0; border-radius: 999px;
|
||||
background: var(--gold); color: var(--gold-ink); font: 600 15px var(--font-body); cursor: pointer;
|
||||
box-shadow: var(--f-shadow);
|
||||
}
|
||||
.ftv-compose { display: flex; flex-direction: column; gap: 8px; padding-top: 14px; border-top: 1px solid var(--line); scroll-margin-top: 90px; }
|
||||
.ftv-hint { font-size: 14px; color: var(--harmonic); }
|
||||
.ftv-replyto { display: flex; align-items: center; gap: 6px; font-size: 14px; color: var(--ink-2); }
|
||||
.ftv-gate { padding: 16px; border-radius: 12px; background: var(--panel); border: 1px solid var(--line); }
|
||||
|
||||
/* --- posts: author on top on phones, the old forums' author column on wide screens --- */
|
||||
.fp { display: flex; flex-direction: column; padding: 16px 0; border-bottom: 1px solid var(--line); scroll-margin-top: 90px; }
|
||||
.fp-content { display: flex; flex-direction: column; gap: 10px; min-width: 0; }
|
||||
.fp-author, .fp-when { display: none; }
|
||||
.ftv-children .fp:last-child { border-bottom: 0; }
|
||||
.fp-opening { padding-top: 6px; padding-bottom: 20px; }
|
||||
.fp-body { font-size: 17px; line-height: 1.6; overflow-wrap: anywhere; color: var(--ink); }
|
||||
.fp-body p + p { margin-top: 10px; }
|
||||
.fp-removed {
|
||||
gap: 4px; margin: 12px 0; padding: 12px 14px; border: 1px dashed var(--line-2);
|
||||
border-radius: 12px; color: var(--ink-2); font-size: 15px;
|
||||
}
|
||||
.fp-mod-note { font-size: 13px; color: var(--danger); }
|
||||
.fp-collapsed {
|
||||
align-self: flex-start; min-height: 44px; padding: 0; border: 0; background: none; color: var(--muted);
|
||||
font: inherit; font-size: 15px; text-decoration: underline; cursor: pointer;
|
||||
}
|
||||
.fp-helped { display: flex; align-items: center; gap: 6px; font-size: 14px; color: var(--ok); }
|
||||
.fp-helped svg { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 2.2; stroke-linecap: round; stroke-linejoin: round; }
|
||||
.fp-actions { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
|
||||
.fp-spacer { flex: 1; }
|
||||
.fp-link {
|
||||
min-height: 44px; padding: 0 8px; border: 0; background: none; color: var(--gold);
|
||||
font: 500 15px var(--font-body); cursor: pointer;
|
||||
}
|
||||
.fp-link:hover { color: var(--gold-hover); }
|
||||
.fp-tools { display: flex; align-items: center; gap: 2px; flex-wrap: wrap; }
|
||||
.fp-tools:empty { display: none; }
|
||||
.fp-tool {
|
||||
min-height: 36px; padding: 0 8px; border: 0; border-radius: 8px; background: none; color: var(--muted);
|
||||
font: 400 14px var(--font-body); cursor: pointer;
|
||||
}
|
||||
.fp-tool:hover { color: var(--ink); background: var(--f-hover); }
|
||||
.fp-tool[aria-pressed="true"] { color: var(--ok); }
|
||||
.fp-tool-mod { color: var(--danger); }
|
||||
@media (min-width: 900px) {
|
||||
.forum-inner .ftv { gap: 14px; }
|
||||
.fp { display: grid; grid-template-columns: 150px minmax(0, 1fr); gap: 0 24px; padding: 20px 0; }
|
||||
.fp.fp-removed { display: flex; flex-direction: column; }
|
||||
.fp-head { display: none; }
|
||||
.fp-author { display: flex; flex-direction: column; align-items: flex-start; gap: 6px; min-width: 0; }
|
||||
.fp-author-name { font-size: 16px; font-weight: 600; color: var(--ink); text-decoration: none; overflow-wrap: anywhere; margin-top: 2px; }
|
||||
.fp-author-name:hover { color: var(--gold); }
|
||||
.fp-author-signs { display: flex; flex-direction: column; gap: 1px; font-size: 13px; color: var(--muted); margin-top: 2px; }
|
||||
.fp-when { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--muted); }
|
||||
.ftv-children { margin-left: 40px; padding-left: 20px; }
|
||||
.ftv-children .fp { grid-template-columns: 120px minmax(0, 1fr); }
|
||||
.fr-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); }
|
||||
.ftv-incoming { bottom: 20px; }
|
||||
}
|
||||
|
||||
/* --- reactions --- */
|
||||
.fr-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
|
||||
.fr-big {
|
||||
display: flex; align-items: center; gap: 8px; min-height: 46px; padding: 0 12px; border-radius: 12px;
|
||||
border: 1px solid var(--line-2); background: var(--panel); color: var(--ink); font: 500 15px var(--font-body); cursor: pointer;
|
||||
text-align: left;
|
||||
}
|
||||
.fr-big:hover:not(:disabled) { border-color: var(--f-border-hover); }
|
||||
.fr-big[aria-pressed="true"] { border-color: var(--gold); background: var(--f-tint-strong); }
|
||||
.fr-big:disabled { cursor: default; }
|
||||
.fr-big-label { flex: 1; min-width: 0; }
|
||||
.fr-count { color: var(--muted); }
|
||||
.fr-big[aria-pressed="true"] .fr-count { color: var(--gold); font-weight: 600; }
|
||||
.fr-row { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
|
||||
.fr-chip {
|
||||
min-height: 44px; min-width: 44px; padding: 0 12px; border-radius: 999px; border: 1px solid var(--line-2);
|
||||
background: none; color: var(--ink); font: 500 14px var(--font-body); cursor: pointer;
|
||||
}
|
||||
.fr-chip:disabled { cursor: default; }
|
||||
.fr-chip:hover:not(:disabled) { border-color: var(--f-border-hover); }
|
||||
.fr-chip[aria-pressed="true"] { border-color: var(--gold); background: var(--f-tint-strong); }
|
||||
.fr-add { border-style: dashed; color: var(--muted); font-size: 18px; }
|
||||
.fr-down { color: var(--muted); font-size: 18px; }
|
||||
.fr-down[aria-pressed="true"] { background: var(--f-hover); color: var(--ink); }
|
||||
.fr-more { position: relative; }
|
||||
.fr-pop {
|
||||
position: absolute; left: 0; bottom: calc(100% + 6px); z-index: 10; min-width: 210px; padding: 6px;
|
||||
display: flex; flex-direction: column; background: var(--panel); border: 1px solid var(--line-2); border-radius: 12px;
|
||||
box-shadow: var(--f-shadow);
|
||||
}
|
||||
.fr-pop-item {
|
||||
display: flex; align-items: center; gap: 10px; min-height: 44px; padding: 0 12px; border: 0; border-radius: 8px;
|
||||
background: none; color: var(--ink); font: 400 15px var(--font-body); text-align: left; cursor: pointer;
|
||||
}
|
||||
.fr-pop-item:hover { background: var(--f-hover); }
|
||||
|
||||
/* --- composer --- */
|
||||
.fc { display: flex; flex-direction: column; gap: 8px; }
|
||||
.fc-text {
|
||||
width: 100%; min-height: 96px; box-sizing: border-box; padding: 12px 14px; border-radius: 12px;
|
||||
border: 1px solid var(--line-2); background: var(--panel-2); color: var(--ink); font: 400 16px/1.45 var(--font-body);
|
||||
resize: vertical; caret-color: var(--gold);
|
||||
}
|
||||
.fc-text::placeholder { color: var(--muted); }
|
||||
.fc-text:focus { outline: none; border-color: var(--gold); box-shadow: 0 0 0 3px var(--f-tint-strong); background: var(--panel); }
|
||||
.fc-actions { display: flex; align-items: center; gap: 8px; }
|
||||
.fc-spacer { flex: 1; }
|
||||
.fc-icon-btn {
|
||||
width: 44px; height: 44px; flex: none; display: inline-flex; align-items: center; justify-content: center;
|
||||
border: 0; border-radius: 10px; background: none; color: var(--ink-2); cursor: pointer;
|
||||
}
|
||||
.fc-icon-btn:hover, .fc-icon-btn[aria-expanded="true"] { color: var(--gold); background: var(--f-tint); }
|
||||
.fc-icon-btn svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; }
|
||||
.fc-tray {
|
||||
display: grid; grid-template-columns: repeat(auto-fill, minmax(42px, 1fr)); gap: 2px; padding: 8px;
|
||||
border: 1px solid var(--line-2); border-radius: 12px; background: var(--panel-2);
|
||||
}
|
||||
.fc-emoji {
|
||||
width: 100%; height: 42px; border: 0; border-radius: 8px; background: none; color: var(--ink);
|
||||
font-size: 22px; cursor: pointer; font-family: var(--font-symbols), sans-serif;
|
||||
}
|
||||
.fc-emoji:hover { background: var(--f-hover); }
|
||||
|
||||
/* --- new thread and profile forms --- */
|
||||
.fnew, .fprof { display: flex; flex-direction: column; gap: 22px; width: 100%; max-width: 760px; }
|
||||
.fnew-set { border: 0; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 10px; min-width: 0; }
|
||||
.fnew-set legend { font-size: 14px; font-weight: 500; margin-bottom: 8px; padding: 0; }
|
||||
.fnew-topics, .fnew-intents { display: grid; gap: 8px; }
|
||||
@media (min-width: 640px) { .fnew-topics { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
|
||||
.fnew-topic, .fnew-intent, .fprof-check {
|
||||
display: flex; align-items: flex-start; gap: 10px; padding: 12px 14px; border: 1px solid var(--line-2);
|
||||
border-radius: 12px; cursor: pointer; background: var(--panel);
|
||||
}
|
||||
.fnew-topic:has(input:checked), .fnew-intent:has(input:checked) { border-color: var(--gold); background: var(--f-tint); }
|
||||
.fnew-topic > span, .fnew-intent > span, .fprof-check > span { display: flex; flex-direction: column; gap: 2px; }
|
||||
.fnew-topic input, .fnew-intent input, .fprof-check input { margin-top: 4px; accent-color: var(--gold); width: 18px; height: 18px; flex: none; }
|
||||
.fprof-avatars { display: grid; grid-template-columns: repeat(auto-fill, minmax(54px, 1fr)); gap: 6px; }
|
||||
.fprof-avatar {
|
||||
display: inline-flex; align-items: center; justify-content: center; padding: 3px; border-radius: 50%;
|
||||
border: 2px solid transparent; cursor: pointer; justify-self: center;
|
||||
}
|
||||
.fprof-avatar:has(input:checked) { border-color: var(--gold); }
|
||||
.fprof-avatar:has(input:focus-visible) { outline: 2px solid var(--gold); outline-offset: 2px; }
|
||||
.fprof-rank { display: flex; flex-direction: column; gap: 4px; padding: 14px 16px; border-radius: 12px; background: var(--panel); border: 1px solid var(--line); }
|
||||
|
||||
/* --- member page (two columns on wide screens) and moderation --- */
|
||||
.fmember { display: flex; flex-direction: column; gap: 12px; align-items: flex-start; }
|
||||
.fmember-head { display: flex; align-items: center; gap: 16px; }
|
||||
.fmember-names { display: flex; flex-direction: column; gap: 4px; }
|
||||
.fmember-names h1 { font-size: 30px; line-height: 1.1; }
|
||||
.fmember-badges { display: flex; gap: 6px; flex-wrap: wrap; }
|
||||
.fmember-signs { color: var(--ink-2); }
|
||||
@media (min-width: 900px) {
|
||||
.fh-member { display: grid; grid-template-columns: 340px minmax(0, 1fr); gap: 28px; align-items: start; }
|
||||
.fh-member .fmember { position: sticky; top: 88px; }
|
||||
}
|
||||
.fban { align-self: stretch; }
|
||||
.fban summary { list-style: none; cursor: pointer; display: inline-flex; }
|
||||
.fban summary::-webkit-details-marker { display: none; }
|
||||
.fban-body { display: flex; flex-direction: column; gap: 12px; margin-top: 12px; padding: 14px; border: 1px solid var(--line-2); border-radius: 12px; }
|
||||
.fmodlog { list-style: none; margin: 0; }
|
||||
.fmodlog li { display: flex; flex-direction: column; gap: 2px; padding: 12px 16px; }
|
||||
.fmodlog li + li { border-top: 1px solid var(--line); }
|
||||
@@ -0,0 +1,27 @@
|
||||
import { redirect } from "next/navigation";
|
||||
|
||||
import { ThreadList } from "@/components/forum/ThreadList";
|
||||
import type { ForumViewer, ThreadCard } from "@/lib/forum";
|
||||
import { forumGet } from "@/lib/forumServer";
|
||||
|
||||
export const metadata = { title: "Követett szálak", robots: { index: false } };
|
||||
|
||||
/** The threads the member follows (their own and the ones they replied to), with what is new. */
|
||||
export default async function FollowedPage() {
|
||||
const res = await forumGet<{ viewer: ForumViewer; threads: ThreadCard[] }>("/v1/forum/followed");
|
||||
if (!res.ok) redirect("/belepes?vissza=/forum/kovetett");
|
||||
const { threads } = res.data;
|
||||
return (
|
||||
<div className="fh">
|
||||
<h1 className="fpage-title">Követett szálak</h1>
|
||||
<p className="muted">A saját szálaid, azok, amelyekhez hozzászóltál, és amelyeket követni kezdtél.</p>
|
||||
{threads.length === 0 ? (
|
||||
<p className="fh-card fh-empty">Még nem követsz egy szálat sem.</p>
|
||||
) : (
|
||||
<div className="fh-card fh-flush">
|
||||
<ThreadList threads={threads} />
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
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>
|
||||
</>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,64 @@
|
||||
import Link from "next/link";
|
||||
import { notFound } from "next/navigation";
|
||||
|
||||
import { type ModLogEntry, banText, memberHref, threadHref } from "@/lib/forum";
|
||||
import { forumGet } from "@/lib/forumServer";
|
||||
|
||||
export const metadata = { title: "Moderálási napló", robots: { index: false } };
|
||||
|
||||
const ACTIONS: Record<string, string> = {
|
||||
delete_post: "hozzászólást távolított el",
|
||||
restore_post: "hozzászólást állított vissza",
|
||||
delete_thread: "szálat távolított el",
|
||||
restore_thread: "szálat állított vissza",
|
||||
ban: "eltiltotta",
|
||||
unban: "feloldotta az eltiltását",
|
||||
lock: "lezárta a szálat",
|
||||
unlock: "feloldotta a szálat",
|
||||
pin: "kitűzte a szálat",
|
||||
unpin: "levette a kitűzést",
|
||||
};
|
||||
|
||||
/** Every moderation step: who, what, why (moderators only). */
|
||||
export default async function ModLogPage() {
|
||||
const res = await forumGet<{ entries: ModLogEntry[] }>("/v1/forum/mod/log");
|
||||
if (!res.ok) notFound();
|
||||
return (
|
||||
<div className="fh">
|
||||
<h1 className="fpage-title">Moderálási napló</h1>
|
||||
{res.data.entries.length === 0 ? (
|
||||
<p className="fh-card fh-empty">Még nem volt moderálás.</p>
|
||||
) : (
|
||||
<ul className="fh-card fh-flush fmodlog">
|
||||
{res.data.entries.map((e) => (
|
||||
<li key={e.id}>
|
||||
<span className="hint">
|
||||
{new Date(e.created_at).toLocaleString("hu-HU", { timeZone: "Europe/Budapest" })}
|
||||
{e.actor_kind === "ai" && " · AI"}
|
||||
</span>
|
||||
<span>
|
||||
<strong>{e.actor ?? "?"}</strong> {ACTIONS[e.action] ?? e.action}
|
||||
{e.target && (
|
||||
<>
|
||||
{" "}
|
||||
(<Link href={memberHref(e.target)}>{e.target}</Link>)
|
||||
</>
|
||||
)}
|
||||
{e.thread && (
|
||||
<>
|
||||
{": "}
|
||||
<Link href={threadHref({ id: e.thread.id, slug: "" }, e.post_id ?? undefined)}>
|
||||
{e.thread.title ?? `#${e.thread.id}`}
|
||||
</Link>
|
||||
</>
|
||||
)}
|
||||
{e.until && ` · ${banText(e.until)}`}
|
||||
</span>
|
||||
{e.reason && <span className="hint">Ok: {e.reason}</span>}
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,244 @@
|
||||
import Link from "next/link";
|
||||
import { notFound } from "next/navigation";
|
||||
|
||||
import { Avatar } from "@/components/forum/Avatar";
|
||||
import { ThreadList, WaitingCard } from "@/components/forum/ThreadList";
|
||||
import { MoonPhaseIcon } from "@/components/MoonChip";
|
||||
import { MOON_PHASES, SIGNS } from "@/lib/astro";
|
||||
import { type ForumHome, ago, memberHref } from "@/lib/forum";
|
||||
import { forumGet } from "@/lib/forumServer";
|
||||
import { loadSky } from "@/lib/sky";
|
||||
import { MOON_IN_SIGN, SIGN_IN, withArticle } from "@/lib/skyText";
|
||||
import type { SkyNow } from "@/lib/types";
|
||||
|
||||
export const metadata = { title: { absolute: "Fórum · Sorsfonalak" } };
|
||||
|
||||
function TopicIcon({ slug }: { slug: string }) {
|
||||
return (
|
||||
<svg viewBox="0 0 24 24" aria-hidden="true" className="topic-icon">
|
||||
{slug === "ami-a-szivemen-van" && (
|
||||
<path d="M12 20s-7.5-4.6-7.5-10.2A4.2 4.2 0 0 1 12 7.3a4.2 4.2 0 0 1 7.5 2.5C19.5 15.4 12 20 12 20z" />
|
||||
)}
|
||||
{slug === "belso-utak" && (
|
||||
<>
|
||||
<path d="M12 12a1.2 1.2 0 1 0 1.2-1.2" />
|
||||
<path d="M13.2 10.8A3.4 3.4 0 1 0 15.4 14" />
|
||||
<path d="M15.4 14A5.6 5.6 0 1 1 12 6.4" />
|
||||
<path d="M12 6.4a7.8 7.8 0 1 1-7.6 9.4" />
|
||||
</>
|
||||
)}
|
||||
{slug === "egbolt-es-kepletek" && (
|
||||
<>
|
||||
<circle cx="12" cy="12" r="8.5" />
|
||||
<path d="M12 7.5l1.2 3.3 3.3 1.2-3.3 1.2L12 16.5l-1.2-3.3L7.5 12l3.3-1.2z" />
|
||||
</>
|
||||
)}
|
||||
{slug === "torzsasztal" && (
|
||||
<>
|
||||
<path d="M4.5 10h11v4.5a5 5 0 0 1-5 5h-1a5 5 0 0 1-5-5z" />
|
||||
<path d="M15.5 11.5h1.3a2.4 2.4 0 0 1 0 4.8h-1.6" />
|
||||
<path d="M8.5 3.5c0 1.4 1 1.6 1 3M12 3.5c0 1.4 1 1.6 1 3" />
|
||||
</>
|
||||
)}
|
||||
{!["ami-a-szivemen-van", "belso-utak", "egbolt-es-kepletek", "torzsasztal"].includes(slug) && (
|
||||
<circle cx="12" cy="12" r="8.5" />
|
||||
)}
|
||||
</svg>
|
||||
);
|
||||
}
|
||||
|
||||
/** "Mai égbolt": the Moon today, the same for everyone; never empty. */
|
||||
function SkyCard({ sky }: { sky: SkyNow }) {
|
||||
const moon = sky.moon;
|
||||
const sign = moon.position.sign;
|
||||
const date = new Date(sky.local_time.slice(0, 10) + "T12:00:00Z").toLocaleDateString("hu-HU", {
|
||||
month: "long",
|
||||
day: "numeric",
|
||||
weekday: "long",
|
||||
timeZone: "UTC",
|
||||
});
|
||||
return (
|
||||
<section className="fh-card fh-sky" aria-labelledby="fh-sky-title">
|
||||
<div className="fh-card-head">
|
||||
<span className="eyebrow">Mai égbolt</span>
|
||||
<span className="hint">{date}</span>
|
||||
</div>
|
||||
<div className="fh-sky-body">
|
||||
<span className="fh-moon">
|
||||
<MoonPhaseIcon illumination={moon.illumination} waxing={moon.waxing} />
|
||||
</span>
|
||||
<div className="fh-sky-text">
|
||||
<h2 id="fh-sky-title">
|
||||
{MOON_PHASES[moon.phase] ?? moon.phase}, <span className="sym">{SIGNS[sign]?.glyph}</span> Hold{" "}
|
||||
{withArticle(SIGN_IN[sign] ?? sign)}
|
||||
</h2>
|
||||
<p>{MOON_IN_SIGN[sign]}</p>
|
||||
</div>
|
||||
</div>
|
||||
<Link href="/holdnaptar" className="fh-sky-link">
|
||||
Holdnaptár és a következő holdfázisok
|
||||
</Link>
|
||||
</section>
|
||||
);
|
||||
}
|
||||
|
||||
export default async function ForumHomePage() {
|
||||
const [home, sky] = await Promise.all([forumGet<ForumHome>("/v1/forum/home"), loadSky()]);
|
||||
if (!home.ok) notFound();
|
||||
const { viewer, followed, topics, unanswered, hot } = home.data;
|
||||
|
||||
return (
|
||||
<div className="fh fh-home">
|
||||
<div className="fh-col fh-col-main">
|
||||
{!viewer.logged_in && (
|
||||
<section className="fh-card fh-intro o-1">
|
||||
<h1>Fórum</h1>
|
||||
<p>
|
||||
Beszélgetés a spiritualitásról, az égboltról, az álmokról és arról, ami a szívedet nyomja. Itt mindenki
|
||||
álnéven ír, a tempó nyugodt, és a meghallgatás fontosabb a vitánál.
|
||||
</p>
|
||||
<p className="hint">
|
||||
Olvasni belépés nélkül is lehet. Hozzászólni és az „Ami a szívemen van” témát olvasni belépve.
|
||||
</p>
|
||||
<Link href="/belepes?vissza=/forum" className="btn btn-primary">
|
||||
Belépés
|
||||
</Link>
|
||||
</section>
|
||||
)}
|
||||
|
||||
{viewer.needs_nickname && (
|
||||
<Link href="/forum/beallitasok" className="fh-banner o-2">
|
||||
<span>
|
||||
<strong>Válassz álnevet</strong>, hogy hozzászólhass. A valódi neved soha nem jelenik meg a fórumon.
|
||||
</span>
|
||||
<span aria-hidden="true">›</span>
|
||||
</Link>
|
||||
)}
|
||||
|
||||
{viewer.member?.banned && (
|
||||
<p className="fh-banner fh-banner-warn o-2">
|
||||
Most nem írhatsz a fórumba. A részleteket a beállításaidnál látod.
|
||||
</p>
|
||||
)}
|
||||
|
||||
{followed && followed.new_replies > 0 && (
|
||||
<Link href="/forum/kovetett" className="fh-banner o-2">
|
||||
<span>
|
||||
<strong>{followed.new_replies} új válasz</strong> a követett szálaidban
|
||||
</span>
|
||||
<span aria-hidden="true">›</span>
|
||||
</Link>
|
||||
)}
|
||||
|
||||
{unanswered.length > 0 && (
|
||||
<section className="fh-section o-4" aria-labelledby="fh-waiting">
|
||||
<div className="fh-section-head">
|
||||
<h2 id="fh-waiting">Várják a válaszod</h2>
|
||||
<span className="hint">még senki nem válaszolt</span>
|
||||
</div>
|
||||
<div className="fh-waiting-grid">
|
||||
{unanswered.map((t) => (
|
||||
<WaitingCard key={t.id} thread={t} />
|
||||
))}
|
||||
</div>
|
||||
</section>
|
||||
)}
|
||||
|
||||
{hot.length > 0 && (
|
||||
<section className="fh-section o-5" aria-labelledby="fh-hot">
|
||||
<div className="fh-section-head">
|
||||
<h2 id="fh-hot">Pörgős most</h2>
|
||||
<span className="hint">az utóbbi 24 órában</span>
|
||||
</div>
|
||||
<div className="fh-card fh-flush">
|
||||
<ThreadList threads={hot} />
|
||||
</div>
|
||||
</section>
|
||||
)}
|
||||
|
||||
<section className="fh-section o-6" aria-labelledby="fh-topics">
|
||||
<div className="fh-section-head">
|
||||
<h2 id="fh-topics">Témák</h2>
|
||||
</div>
|
||||
<ul className="fh-card fh-flush fh-topics">
|
||||
{topics.map((t) => (
|
||||
<li key={t.slug}>
|
||||
<Link href={t.readable ? `/forum/${t.slug}` : `/belepes?vissza=/forum/${t.slug}`} className="fh-topic">
|
||||
<span className="fh-topic-icon">
|
||||
<TopicIcon slug={t.slug} />
|
||||
</span>
|
||||
<span className="fh-topic-text">
|
||||
<span className="fh-topic-name">
|
||||
{t.name}
|
||||
{t.visibility !== "public" && (
|
||||
<svg viewBox="0 0 24 24" className="fh-lock" role="img" aria-label="Csak tagoknak">
|
||||
<rect x="5" y="11" width="14" height="9" rx="2" />
|
||||
<path d="M8 11V8a4 4 0 0 1 8 0v3" />
|
||||
</svg>
|
||||
)}
|
||||
</span>
|
||||
<span className="fh-topic-desc">{t.description}</span>
|
||||
{t.readable && t.last && (
|
||||
<span className="fh-topic-last">
|
||||
{t.last.author && (
|
||||
<Avatar avatar={t.last.author.avatar} size={18} online={t.last.author.online} />
|
||||
)}
|
||||
{t.last.author?.nickname ?? "Törölt tag"},{" "}
|
||||
<time suppressHydrationWarning dateTime={t.last.at}>
|
||||
{ago(t.last.at)}
|
||||
</time>
|
||||
</span>
|
||||
)}
|
||||
{!t.readable && <span className="fh-topic-last">Belépés után olvasható</span>}
|
||||
</span>
|
||||
{t.readable && (
|
||||
<span className="fh-topic-count">
|
||||
<strong>{t.thread_count ?? 0}</strong> szál
|
||||
</span>
|
||||
)}
|
||||
{t.readable && t.new_count ? (
|
||||
<span className="ft-new">{t.new_count > 99 ? "99+" : t.new_count} új</span>
|
||||
) : null}
|
||||
</Link>
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
</section>
|
||||
</div>
|
||||
|
||||
<aside className="fh-col fh-col-side" aria-label="Oldalsáv">
|
||||
{sky && (
|
||||
<div className="o-3">
|
||||
<SkyCard sky={sky} />
|
||||
</div>
|
||||
)}
|
||||
{viewer.member && (
|
||||
<section className="fh-card fh-me o-7" aria-label="Saját">
|
||||
<div className="fh-me-head">
|
||||
<Avatar avatar={viewer.member.avatar} size={48} />
|
||||
<span className="fh-me-names">
|
||||
<Link href={memberHref(viewer.member.nickname)} className="fa-name">
|
||||
{viewer.member.nickname}
|
||||
</Link>
|
||||
<span className="fa-rank">{viewer.member.rank_name}</span>
|
||||
</span>
|
||||
</div>
|
||||
<div className="fh-me-actions">
|
||||
<Link href="/forum/uj" className="btn btn-primary btn-sm">
|
||||
Új szál
|
||||
</Link>
|
||||
<Link href="/forum/beallitasok" className="btn btn-sm">
|
||||
Fórumprofil
|
||||
</Link>
|
||||
</div>
|
||||
</section>
|
||||
)}
|
||||
{viewer.moderator && (
|
||||
<Link href="/forum/moderalas" className="fh-side-link o-8">
|
||||
Moderálási napló
|
||||
</Link>
|
||||
)}
|
||||
</aside>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
import type { Metadata } from "next";
|
||||
import { notFound, permanentRedirect, redirect } from "next/navigation";
|
||||
|
||||
import { ThreadView } from "@/components/forum/ThreadView";
|
||||
import type { ThreadPage } from "@/lib/forum";
|
||||
import { forumGet } from "@/lib/forumServer";
|
||||
|
||||
type Props = { params: Promise<{ id: string }> };
|
||||
|
||||
/** `123-nem-tudom-elengedni` → 123; the words after the number are only for reading. */
|
||||
function threadId(param: string): number | null {
|
||||
const match = /^(\d{1,15})(?:-|$)/.exec(decodeURIComponent(param));
|
||||
return match ? Number(match[1]) : null;
|
||||
}
|
||||
|
||||
async function load(param: string) {
|
||||
const id = threadId(param);
|
||||
if (id === null) return null;
|
||||
return forumGet<ThreadPage>(`/v1/forum/threads/${id}`);
|
||||
}
|
||||
|
||||
export async function generateMetadata({ params }: Props): Promise<Metadata> {
|
||||
const res = await load((await params).id);
|
||||
if (!res?.ok) return { title: "Fórum", robots: { index: false } };
|
||||
const { thread, posts } = res.data;
|
||||
const open = thread.topic.visibility === "public" && !thread.deleted;
|
||||
const opening = posts.find((p) => p.is_opening)?.body ?? "";
|
||||
return {
|
||||
title: thread.title,
|
||||
description: open ? opening.slice(0, 160) : undefined,
|
||||
alternates: { canonical: `/forum/szal/${thread.id}-${thread.slug}` },
|
||||
// Members-only topics and removed threads stay out of search engines.
|
||||
robots: open ? undefined : { index: false, follow: false },
|
||||
};
|
||||
}
|
||||
|
||||
export default async function ThreadPageView({ params }: Props) {
|
||||
const param = (await params).id;
|
||||
const res = await load(param);
|
||||
if (!res) notFound();
|
||||
if (!res.ok) {
|
||||
if (res.status === 401) redirect(`/belepes?vissza=/forum/szal/${encodeURIComponent(param)}`);
|
||||
notFound();
|
||||
}
|
||||
const { thread } = res.data;
|
||||
const canonical = thread.slug ? `${thread.id}-${thread.slug}` : `${thread.id}`;
|
||||
if (decodeURIComponent(param) !== canonical) permanentRedirect(`/forum/szal/${canonical}`);
|
||||
return <ThreadView initial={res.data} />;
|
||||
}
|
||||
@@ -0,0 +1,89 @@
|
||||
"use client";
|
||||
|
||||
import { useRouter } from "next/navigation";
|
||||
import { useState } from "react";
|
||||
|
||||
import { api, errorText } from "@/lib/api";
|
||||
|
||||
const DURATIONS: { hours: number | null; label: string }[] = [
|
||||
{ hours: 3, label: "3 óra" },
|
||||
{ hours: 24, label: "1 nap" },
|
||||
{ hours: 72, label: "3 nap" },
|
||||
{ hours: 168, label: "1 hét" },
|
||||
{ hours: 720, label: "30 nap" },
|
||||
{ hours: null, label: "Végleg" },
|
||||
];
|
||||
|
||||
/** Moderators: ban a member for a while or for good (they may still read), or lift it. */
|
||||
export function BanPanel({ nickname, banned }: { nickname: string; banned: boolean }) {
|
||||
const router = useRouter();
|
||||
const [hours, setHours] = useState<string>("24");
|
||||
const [reason, setReason] = useState("");
|
||||
const [busy, setBusy] = useState(false);
|
||||
const [error, setError] = useState<string | null>(null);
|
||||
const path = `/forum/members/${encodeURIComponent(nickname)}/ban`;
|
||||
|
||||
async function act(work: () => Promise<unknown>) {
|
||||
setBusy(true);
|
||||
setError(null);
|
||||
try {
|
||||
await work();
|
||||
router.refresh();
|
||||
} catch (e) {
|
||||
setError(errorText(e));
|
||||
} finally {
|
||||
setBusy(false);
|
||||
}
|
||||
}
|
||||
|
||||
return (
|
||||
<details className="fban">
|
||||
<summary className="btn btn-sm btn-ghost">Moderálás</summary>
|
||||
<div className="fban-body">
|
||||
{banned && (
|
||||
<button
|
||||
type="button"
|
||||
className="btn btn-sm"
|
||||
disabled={busy}
|
||||
onClick={() => act(() => api(path, { method: "DELETE" }))}
|
||||
>
|
||||
Eltiltás feloldása
|
||||
</button>
|
||||
)}
|
||||
<div className="field">
|
||||
<label htmlFor="fban-hours">Eltiltás</label>
|
||||
<select id="fban-hours" className="inp" value={hours} onChange={(e) => setHours(e.target.value)}>
|
||||
{DURATIONS.map((d) => (
|
||||
<option key={d.label} value={d.hours ?? "forever"}>
|
||||
{d.label}
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
</div>
|
||||
<div className="field">
|
||||
<label htmlFor="fban-reason">Indoklás (a tag látja)</label>
|
||||
<input
|
||||
id="fban-reason"
|
||||
className="inp"
|
||||
value={reason}
|
||||
onChange={(e) => setReason(e.target.value)}
|
||||
maxLength={300}
|
||||
/>
|
||||
</div>
|
||||
{error && (
|
||||
<p className="msg msg-error" role="alert">
|
||||
{error}
|
||||
</p>
|
||||
)}
|
||||
<button
|
||||
type="button"
|
||||
className="btn btn-sm btn-danger"
|
||||
disabled={busy || reason.trim().length < 3}
|
||||
onClick={() => act(() => api(path, { body: { hours: hours === "forever" ? null : Number(hours), reason } }))}
|
||||
>
|
||||
Eltiltom
|
||||
</button>
|
||||
</div>
|
||||
</details>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,104 @@
|
||||
import type { Metadata } from "next";
|
||||
import Link from "next/link";
|
||||
import { notFound } from "next/navigation";
|
||||
|
||||
import { Avatar } from "@/components/forum/Avatar";
|
||||
import { signsText } from "@/components/forum/AuthorLine";
|
||||
import { PostBody } from "@/components/forum/PostBody";
|
||||
import { type MemberProfile, ago, banText, threadHref } from "@/lib/forum";
|
||||
import { forumGet } from "@/lib/forumServer";
|
||||
|
||||
import { BanPanel } from "./BanPanel";
|
||||
|
||||
type Props = { params: Promise<{ nev: string }> };
|
||||
|
||||
async function load(nev: string) {
|
||||
return forumGet<MemberProfile>(`/v1/forum/members/${encodeURIComponent(decodeURIComponent(nev))}`);
|
||||
}
|
||||
|
||||
export async function generateMetadata({ params }: Props): Promise<Metadata> {
|
||||
const res = await load((await params).nev);
|
||||
return res.ok ? { title: res.data.member.author.nickname, robots: { index: false } } : { title: "Fórum" };
|
||||
}
|
||||
|
||||
const LAST_SEEN: Record<string, string> = {
|
||||
online: "Most online",
|
||||
day: "Az elmúlt napban járt itt",
|
||||
week: "Ezen a héten járt itt",
|
||||
earlier: "Régebben járt itt",
|
||||
};
|
||||
|
||||
/** A member's profile: what they chose to show, and their recent posts. */
|
||||
export default async function MemberPage({ params }: Props) {
|
||||
const res = await load((await params).nev);
|
||||
if (!res.ok) notFound();
|
||||
const { member, recent, viewer } = res.data;
|
||||
const a = member.author;
|
||||
const signs = signsText(a.signs);
|
||||
const since = new Date(member.created_at).toLocaleDateString("hu-HU", { year: "numeric", month: "long" });
|
||||
return (
|
||||
<div className="fh fh-member">
|
||||
<section className="fh-card fmember">
|
||||
<div className="fmember-head">
|
||||
<Avatar avatar={a.avatar} size={72} online={a.online} />
|
||||
<div className="fmember-names">
|
||||
<h1>{a.nickname}</h1>
|
||||
<span className="fmember-badges">
|
||||
<span className="fa-rank">{a.rank_name}</span>
|
||||
{a.moderator && <span className="fa-badge fa-badge-mod">Moderátor</span>}
|
||||
</span>
|
||||
{member.last_seen && <span className="hint">{LAST_SEEN[member.last_seen]}</span>}
|
||||
</div>
|
||||
</div>
|
||||
{signs && <p className="sym fmember-signs">{signs}</p>}
|
||||
{member.bio && <PostBody text={member.bio} />}
|
||||
<p className="hint">
|
||||
Tag {since} óta · {member.post_count} hozzászólás · {member.thread_count} szál
|
||||
</p>
|
||||
{member.banned_until && (
|
||||
<p className="fh-banner fh-banner-warn">
|
||||
Eltiltva ({banText(member.banned_until)}).{member.ban_reason && ` Indok: ${member.ban_reason}`}
|
||||
</p>
|
||||
)}
|
||||
{member.own && (
|
||||
<Link href="/forum/beallitasok" className="btn btn-sm">
|
||||
Profil szerkesztése
|
||||
</Link>
|
||||
)}
|
||||
{viewer.moderator && !member.own && !a.moderator && (
|
||||
<BanPanel nickname={a.nickname} banned={member.banned_until !== null} />
|
||||
)}
|
||||
</section>
|
||||
|
||||
<section className="fh-section" aria-labelledby="fmember-recent">
|
||||
<div className="fh-section-head">
|
||||
<h2 id="fmember-recent">Legutóbbi hozzászólások</h2>
|
||||
</div>
|
||||
{recent.length === 0 ? (
|
||||
<p className="fh-card fh-empty">
|
||||
Még nincs hozzászólása{viewer.logged_in ? "." : ", vagy csak belépve látható."}
|
||||
</p>
|
||||
) : (
|
||||
<ul className="fh-card fh-flush ft-list">
|
||||
{recent.map((r) => (
|
||||
<li key={r.id}>
|
||||
<Link href={threadHref({ id: r.thread_id, slug: r.thread_slug }, r.id)} className="ft-row">
|
||||
<span className="ft-main">
|
||||
<span className="ft-title">{r.thread_title}</span>
|
||||
<span className="ft-excerpt">{r.excerpt}</span>
|
||||
<span className="ft-meta">
|
||||
{r.is_opening ? "Szálat indított" : "Hozzászólt"} · {r.topic.name} ·{" "}
|
||||
<time suppressHydrationWarning dateTime={r.created_at}>
|
||||
{ago(r.created_at)}
|
||||
</time>
|
||||
</span>
|
||||
</span>
|
||||
</Link>
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
)}
|
||||
</section>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,166 @@
|
||||
"use client";
|
||||
|
||||
import { useRouter } from "next/navigation";
|
||||
import { useState } from "react";
|
||||
|
||||
import { api, errorText } from "@/lib/api";
|
||||
import { EMOJI, type ForumTopic, threadHref } from "@/lib/forum";
|
||||
|
||||
type Intent = "listen" | "advice" | "";
|
||||
|
||||
export function NewThreadForm({ topics, initialTopic }: { topics: ForumTopic[]; initialTopic: string }) {
|
||||
const router = useRouter();
|
||||
const [topic, setTopic] = useState(initialTopic);
|
||||
const listening = topics.find((t) => t.slug === topic)?.listening ?? false;
|
||||
const [intent, setIntent] = useState<Intent>(listening ? "listen" : "");
|
||||
const [title, setTitle] = useState("");
|
||||
const [body, setBody] = useState("");
|
||||
const [tray, setTray] = useState(false);
|
||||
const [busy, setBusy] = useState(false);
|
||||
const [error, setError] = useState<string | null>(null);
|
||||
|
||||
function pickTopic(slug: string) {
|
||||
setTopic(slug);
|
||||
const t = topics.find((x) => x.slug === slug);
|
||||
if (t?.listening) setIntent("listen");
|
||||
}
|
||||
|
||||
async function submit(e: React.FormEvent) {
|
||||
e.preventDefault();
|
||||
setBusy(true);
|
||||
setError(null);
|
||||
try {
|
||||
const created = await api<{ id: number; slug: string }>("/forum/threads", {
|
||||
body: { topic, title, body, intent: intent || null },
|
||||
});
|
||||
router.push(threadHref(created));
|
||||
router.refresh();
|
||||
} catch (err) {
|
||||
setError(errorText(err));
|
||||
setBusy(false);
|
||||
}
|
||||
}
|
||||
|
||||
return (
|
||||
<form className="fnew" onSubmit={submit}>
|
||||
<fieldset className="fnew-set">
|
||||
<legend>Téma</legend>
|
||||
<div className="fnew-topics">
|
||||
{topics.map((t) => (
|
||||
<label key={t.slug} className="fnew-topic">
|
||||
<input
|
||||
type="radio"
|
||||
name="topic"
|
||||
value={t.slug}
|
||||
checked={topic === t.slug}
|
||||
onChange={() => pickTopic(t.slug)}
|
||||
/>
|
||||
<span>
|
||||
<strong>{t.name}</strong>
|
||||
<span className="hint">{t.description}</span>
|
||||
</span>
|
||||
</label>
|
||||
))}
|
||||
</div>
|
||||
</fieldset>
|
||||
|
||||
<fieldset className="fnew-set">
|
||||
<legend>Mit szeretnél?</legend>
|
||||
<div className="fnew-intents">
|
||||
<label className="fnew-intent">
|
||||
<input type="radio" name="intent" checked={intent === "listen"} onChange={() => setIntent("listen")} />
|
||||
<span>
|
||||
<strong>Csak meghallgatást kérek</strong>
|
||||
<span className="hint">Nem kérek tanácsot, jólesne, ha valaki meghallgatna.</span>
|
||||
</span>
|
||||
</label>
|
||||
<label className="fnew-intent">
|
||||
<input type="radio" name="intent" checked={intent === "advice"} onChange={() => setIntent("advice")} />
|
||||
<span>
|
||||
<strong>Tanácsot, véleményt kérek</strong>
|
||||
<span className="hint">Kíváncsi vagyok, ti mit gondoltok, mit tennétek.</span>
|
||||
</span>
|
||||
</label>
|
||||
{!listening && (
|
||||
<label className="fnew-intent">
|
||||
<input type="radio" name="intent" checked={intent === ""} onChange={() => setIntent("")} />
|
||||
<span>
|
||||
<strong>Csak beszélgetnék</strong>
|
||||
<span className="hint">Egy téma, egy gondolat, egy élmény.</span>
|
||||
</span>
|
||||
</label>
|
||||
)}
|
||||
</div>
|
||||
</fieldset>
|
||||
|
||||
<div className="field">
|
||||
<label htmlFor="fnew-title">Cím</label>
|
||||
<input
|
||||
id="fnew-title"
|
||||
className="inp"
|
||||
value={title}
|
||||
onChange={(e) => setTitle(e.target.value)}
|
||||
maxLength={120}
|
||||
required
|
||||
placeholder="Miről szeretnél beszélgetni?"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div className="field">
|
||||
<label htmlFor="fnew-body">Az első hozzászólás</label>
|
||||
<textarea
|
||||
id="fnew-body"
|
||||
className="fc-text"
|
||||
rows={8}
|
||||
value={body}
|
||||
onChange={(e) => setBody(e.target.value)}
|
||||
maxLength={10000}
|
||||
required
|
||||
placeholder={intent === "listen" ? "Írd le, ami benned van…" : "Írd le a gondolataidat…"}
|
||||
/>
|
||||
<div className="fc-actions">
|
||||
<button
|
||||
type="button"
|
||||
className="fc-icon-btn"
|
||||
aria-label="Emoji"
|
||||
aria-expanded={tray}
|
||||
onClick={() => setTray((t) => !t)}
|
||||
>
|
||||
<svg viewBox="0 0 24 24" aria-hidden="true">
|
||||
<circle cx="12" cy="12" r="9" />
|
||||
<path d="M8.5 14.5a4 4 0 0 0 7 0" />
|
||||
<path d="M9 9.5h.01M15 9.5h.01" strokeWidth="2.6" />
|
||||
</svg>
|
||||
</button>
|
||||
<span className="hint">
|
||||
Szöveg és emoji. Képet és videót nem lehet beilleszteni, a linkek sima szövegként látszanak.
|
||||
</span>
|
||||
</div>
|
||||
{tray && (
|
||||
<div className="fc-tray" role="group" aria-label="Emoji">
|
||||
{EMOJI.map((em) => (
|
||||
<button
|
||||
key={em}
|
||||
type="button"
|
||||
className="fc-emoji"
|
||||
onClick={() => setBody((b) => b + em)}
|
||||
aria-label={`${em} beszúrása`}
|
||||
>
|
||||
{em}
|
||||
</button>
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
|
||||
{error && (
|
||||
<p className="msg msg-error" role="alert">
|
||||
{error}
|
||||
</p>
|
||||
)}
|
||||
<button type="submit" className="btn btn-primary" disabled={busy || !title.trim() || !body.trim() || !topic}>
|
||||
{busy ? "Küldés…" : "Szál indítása"}
|
||||
</button>
|
||||
</form>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
import { redirect } from "next/navigation";
|
||||
|
||||
import type { ForumTopic, ForumViewer } from "@/lib/forum";
|
||||
import { forumGet } from "@/lib/forumServer";
|
||||
|
||||
import { NewThreadForm } from "./NewThreadForm";
|
||||
|
||||
export const metadata = { title: "Új szál", robots: { index: false } };
|
||||
|
||||
type Props = { searchParams: Promise<{ tema?: string }> };
|
||||
|
||||
/** Starting a thread: a nickname first, then topic, wish, title and text. */
|
||||
export default async function NewThreadPage({ searchParams }: Props) {
|
||||
const { tema } = await searchParams;
|
||||
const back = `/forum/uj${tema ? `?tema=${encodeURIComponent(tema)}` : ""}`;
|
||||
const res = await forumGet<{ topics: ForumTopic[] }>("/v1/forum/topics");
|
||||
const nav = await forumGet<{ viewer: ForumViewer }>("/v1/forum/nav");
|
||||
const viewer = nav.ok ? nav.data.viewer : null;
|
||||
if (!viewer?.logged_in) redirect(`/belepes?vissza=${encodeURIComponent(back)}`);
|
||||
if (viewer.needs_nickname) redirect(`/forum/beallitasok?vissza=${encodeURIComponent(back)}`);
|
||||
const topics = res.ok ? res.data.topics.filter((t) => t.readable) : [];
|
||||
const initial = topics.find((t) => t.slug === tema)?.slug ?? topics[0]?.slug ?? "";
|
||||
return (
|
||||
<div className="fh">
|
||||
<h1 className="fpage-title">Új szál</h1>
|
||||
{viewer.member?.banned ? (
|
||||
<p className="fh-banner fh-banner-warn">Most nem írhatsz a fórumba.</p>
|
||||
) : (
|
||||
<NewThreadForm topics={topics} initialTopic={initial} />
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -12,6 +12,7 @@ export type NavIconName =
|
||||
| "moon"
|
||||
| "retro"
|
||||
| "packages"
|
||||
| "forum"
|
||||
| "admin";
|
||||
|
||||
const GLYPHS: Partial<Record<NavIconName, string>> = {
|
||||
@@ -62,6 +63,12 @@ export function NavIcon({ name }: { name: NavIconName }) {
|
||||
<path d="M3.5 7.2L12 12l8.5-4.8M12 12v9.5" />
|
||||
</>
|
||||
)}
|
||||
{name === "forum" && (
|
||||
<>
|
||||
<path d="M4 5h12a2 2 0 0 1 2 2v6a2 2 0 0 1-2 2H9l-4 3v-3H4a2 2 0 0 1-2-2V7a2 2 0 0 1 2-2z" />
|
||||
<path d="M20 9h1a1 1 0 0 1 1 1v8l-3-2h-6" />
|
||||
</>
|
||||
)}
|
||||
{name === "admin" && (
|
||||
<>
|
||||
<circle cx="12" cy="12" r="3" />
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import Link from "next/link";
|
||||
|
||||
import { forumEnabled } from "@/lib/forumServer";
|
||||
import type { Me, SkyNow } from "@/lib/types";
|
||||
|
||||
import { MobileMenu } from "./MobileMenu";
|
||||
@@ -42,10 +43,11 @@ export function PublicHeader({
|
||||
current,
|
||||
}: {
|
||||
onHome?: boolean;
|
||||
current?: "pelda" | "horoszkop" | "csillagjegyek" | "hires" | "holdnaptar" | "retrograd";
|
||||
current?: "pelda" | "horoszkop" | "csillagjegyek" | "hires" | "holdnaptar" | "retrograd" | "forum";
|
||||
}) {
|
||||
const home = onHome ? "" : "/";
|
||||
const here = (page: typeof current) => (current === page ? "page" : undefined);
|
||||
const forum = forumEnabled();
|
||||
return (
|
||||
<header className="site-header lp-header">
|
||||
<Logo />
|
||||
@@ -56,6 +58,11 @@ export function PublicHeader({
|
||||
<Link href="/pelda" aria-current={here("pelda")}>
|
||||
Példa
|
||||
</Link>
|
||||
{forum && (
|
||||
<Link href="/forum" aria-current={here("forum")}>
|
||||
Fórum
|
||||
</Link>
|
||||
)}
|
||||
</nav>
|
||||
<nav className="lp-free" aria-label="Ingyenes, belépés nélkül">
|
||||
<span className="lp-free-label">Ingyenes</span>
|
||||
@@ -81,6 +88,7 @@ export function PublicHeader({
|
||||
{ href: `${home}#elorejelzes`, label: "Előrejelzés" },
|
||||
{ href: `${home}#osszevetes`, label: "Összevetés" },
|
||||
{ href: "/pelda", label: "Példa" },
|
||||
...(forum ? [{ href: "/forum", label: "Fórum" }] : []),
|
||||
],
|
||||
},
|
||||
{
|
||||
@@ -148,6 +156,7 @@ export function SiteHeader({ me, sky }: { me: Me; sky?: SkyNow | null }) {
|
||||
{ href: "/szemelyek", label: "Személyek", icon: "persons" },
|
||||
{ href: "/osszevetesek", label: "Összevetések", icon: "compare" },
|
||||
{ href: "/kartyajoslas", label: "Kártyajóslás", icon: "tarot" },
|
||||
...(forumEnabled() ? [{ href: "/forum", label: "Fórum", icon: "forum" as const }] : []),
|
||||
];
|
||||
const packages: NavItem = { href: "/csomagok", label: "Csomagok", icon: "packages" };
|
||||
const team: NavItem[] = me.user.roles.includes("admin")
|
||||
|
||||
@@ -0,0 +1,103 @@
|
||||
import Link from "next/link";
|
||||
|
||||
import { POINTS, SIGNS } from "@/lib/astro";
|
||||
import { type ForumAuthor, ago, memberHref } from "@/lib/forum";
|
||||
|
||||
import { Avatar } from "./Avatar";
|
||||
|
||||
/** "☉ Halak · ☽ Rák · Asz Szűz": the signs a member chose to share. */
|
||||
export function signsText(signs: Record<string, string> | null | undefined): string | null {
|
||||
if (!signs) return null;
|
||||
const parts = Object.entries(signs)
|
||||
.sort(([a], [b]) => order(a) - order(b))
|
||||
.map(([point, sign]) => {
|
||||
const name = SIGNS[sign]?.hu ?? sign;
|
||||
return point === "ascendant" ? `Asz ${name}` : `${POINTS[point]?.glyph ?? point} ${name}`;
|
||||
});
|
||||
return parts.length ? parts.join(" · ") : null;
|
||||
}
|
||||
|
||||
const ORDER = [
|
||||
"sun",
|
||||
"moon",
|
||||
"ascendant",
|
||||
"mercury",
|
||||
"venus",
|
||||
"mars",
|
||||
"jupiter",
|
||||
"saturn",
|
||||
"uranus",
|
||||
"neptune",
|
||||
"pluto",
|
||||
];
|
||||
function order(point: string) {
|
||||
const i = ORDER.indexOf(point);
|
||||
return i < 0 ? 99 : i;
|
||||
}
|
||||
|
||||
/**
|
||||
* Who wrote it: avatar with the online dot, nickname, rank, badges, the
|
||||
* shared signs and the time. A deleted account shows as "Törölt tag".
|
||||
*/
|
||||
export function AuthorLine({
|
||||
author,
|
||||
size = 40,
|
||||
time,
|
||||
edited = false,
|
||||
badges,
|
||||
signs = true,
|
||||
}: {
|
||||
author: ForumAuthor | null;
|
||||
size?: number;
|
||||
time?: string;
|
||||
edited?: boolean;
|
||||
badges?: React.ReactNode;
|
||||
signs?: boolean;
|
||||
}) {
|
||||
if (!author) {
|
||||
return (
|
||||
<div className="fa-line">
|
||||
<Avatar avatar={null} size={size} />
|
||||
<span className="fa-meta">
|
||||
<span className="fa-name muted">Törölt tag</span>
|
||||
{time && <span className="fa-sub">{ago(time)}</span>}
|
||||
</span>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
const shown = signs ? signsText(author.signs) : null;
|
||||
return (
|
||||
<div className="fa-line">
|
||||
<Link href={memberHref(author.nickname)} className="fa-avatar" tabIndex={-1} aria-hidden="true">
|
||||
<Avatar avatar={author.avatar} size={size} online={author.online} />
|
||||
</Link>
|
||||
<span className="fa-meta">
|
||||
<span className="fa-names">
|
||||
<Link href={memberHref(author.nickname)} className="fa-name">
|
||||
{author.nickname}
|
||||
</Link>
|
||||
{author.online && <span className="sr-only">(online)</span>}
|
||||
<span className="fa-rank">{author.rank_name}</span>
|
||||
{author.moderator && <span className="fa-badge fa-badge-mod">Moderátor</span>}
|
||||
{badges}
|
||||
</span>
|
||||
{(shown || time) && (
|
||||
<span className="fa-sub">
|
||||
{shown && <span className="sym">{shown}</span>}
|
||||
{shown && time && " · "}
|
||||
{time && (
|
||||
<time
|
||||
suppressHydrationWarning
|
||||
dateTime={time}
|
||||
title={new Date(time).toLocaleString("hu-HU", { timeZone: "Europe/Budapest" })}
|
||||
>
|
||||
{ago(time)}
|
||||
</time>
|
||||
)}
|
||||
{edited && " · szerkesztve"}
|
||||
</span>
|
||||
)}
|
||||
</span>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,100 @@
|
||||
// The starter avatars: a gold glyph on a night colour, `<glyph>-<colour>`
|
||||
// (the forum service checks the same lists). With `online`, the green dot.
|
||||
|
||||
export const AVATAR_GLYPHS = ["hold", "csillag", "nap", "hullam", "level", "lotusz", "kristaly", "toll"] as const;
|
||||
export const AVATAR_COLOURS = ["ejkek", "lila", "tenger", "borostyan", "rozsa", "erdo"] as const;
|
||||
|
||||
const BACKGROUND: Record<string, string> = {
|
||||
ejkek: "#1c2540",
|
||||
lila: "#2a2342",
|
||||
tenger: "#1d3038",
|
||||
borostyan: "#33291c",
|
||||
rozsa: "#3a2230",
|
||||
erdo: "#1f3326",
|
||||
};
|
||||
|
||||
export const GLYPH_NAMES: Record<string, string> = {
|
||||
hold: "Hold",
|
||||
csillag: "Csillag",
|
||||
nap: "Nap",
|
||||
hullam: "Hullám",
|
||||
level: "Levél",
|
||||
lotusz: "Lótusz",
|
||||
kristaly: "Kristály",
|
||||
toll: "Toll",
|
||||
};
|
||||
|
||||
function Glyph({ name }: { name: string }) {
|
||||
switch (name) {
|
||||
case "hold":
|
||||
return <path d="M23 10A10 10 0 1 0 23 30A8 8 0 1 1 23 10Z" className="av-fill" />;
|
||||
case "csillag":
|
||||
return <path d="M20 9 L22.5 17.5 L31 20 L22.5 22.5 L20 31 L17.5 22.5 L9 20 L17.5 17.5 Z" className="av-fill" />;
|
||||
case "nap":
|
||||
return (
|
||||
<>
|
||||
<circle cx="20" cy="20" r="5" className="av-fill" />
|
||||
<path d="M20 8v4M20 28v4M8 20h4M28 20h4M11.5 11.5l2.8 2.8M25.7 25.7l2.8 2.8M28.5 11.5l-2.8 2.8M14.3 25.7l-2.8 2.8" />
|
||||
</>
|
||||
);
|
||||
case "hullam":
|
||||
return (
|
||||
<>
|
||||
<path d="M9 18 q5.5-6 11 0 t11 0" />
|
||||
<path d="M12 25 q4-4 8 0 t8 0" opacity="0.6" />
|
||||
</>
|
||||
);
|
||||
case "level":
|
||||
return (
|
||||
<>
|
||||
<path d="M12 28 C12 16 20 11 29 11 C29 20 24 28 12 28 Z" />
|
||||
<path d="M12 28 L22 18" />
|
||||
</>
|
||||
);
|
||||
case "lotusz":
|
||||
return (
|
||||
<>
|
||||
<path d="M20 11c3 4 3 9 0 14c-3-5-3-10 0-14z" />
|
||||
<path d="M20 25c-4-1-8-4-9-9c4 0 7 3 9 9zM20 25c4-1 8-4 9-9c-4 0-7 3-9 9z" />
|
||||
<path d="M12 29h16" />
|
||||
</>
|
||||
);
|
||||
case "kristaly":
|
||||
return (
|
||||
<>
|
||||
<path d="M20 9l7 9-7 13-7-13z" />
|
||||
<path d="M13 18h14" />
|
||||
</>
|
||||
);
|
||||
default:
|
||||
return (
|
||||
<>
|
||||
<path d="M28 10c-8 1-13 7-15 18l3-1c1-6 5-11 12-17z" />
|
||||
<path d="M13 29l9-11" />
|
||||
</>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
export function Avatar({
|
||||
avatar,
|
||||
size = 40,
|
||||
online = false,
|
||||
}: {
|
||||
avatar: string | null | undefined;
|
||||
size?: number;
|
||||
online?: boolean;
|
||||
}) {
|
||||
const [glyph, colour] = (avatar ?? "hold-ejkek").split("-");
|
||||
return (
|
||||
<span className="av" style={{ width: size, height: size }}>
|
||||
<svg viewBox="0 0 40 40" width={size} height={size} aria-hidden="true">
|
||||
<circle cx="20" cy="20" r="20" fill={BACKGROUND[colour] ?? BACKGROUND.ejkek} />
|
||||
<g className="av-glyph">
|
||||
<Glyph name={glyph} />
|
||||
</g>
|
||||
</svg>
|
||||
{online && <span className="av-online" title="Most online" />}
|
||||
</span>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,114 @@
|
||||
"use client";
|
||||
|
||||
import { useRef, useState } from "react";
|
||||
|
||||
import { EMOJI } from "@/lib/forum";
|
||||
|
||||
/**
|
||||
* The text box with an emoji tray (phones have emoji on the keyboard; the
|
||||
* tray is mostly for computers) and the send button.
|
||||
*/
|
||||
export function Composer({
|
||||
id,
|
||||
label,
|
||||
placeholder,
|
||||
initial = "",
|
||||
submitLabel = "Küldés",
|
||||
busy,
|
||||
onSubmit,
|
||||
onCancel,
|
||||
rows = 3,
|
||||
autoFocus = false,
|
||||
}: {
|
||||
id: string;
|
||||
label: string;
|
||||
placeholder?: string;
|
||||
initial?: string;
|
||||
submitLabel?: string;
|
||||
busy: boolean;
|
||||
onSubmit: (text: string) => Promise<boolean>;
|
||||
onCancel?: () => void;
|
||||
rows?: number;
|
||||
autoFocus?: boolean;
|
||||
}) {
|
||||
const [text, setText] = useState(initial);
|
||||
const [tray, setTray] = useState(false);
|
||||
const area = useRef<HTMLTextAreaElement>(null);
|
||||
|
||||
function insert(emoji: string) {
|
||||
const el = area.current;
|
||||
if (!el) {
|
||||
setText((t) => t + emoji);
|
||||
return;
|
||||
}
|
||||
const start = el.selectionStart ?? text.length;
|
||||
const end = el.selectionEnd ?? text.length;
|
||||
const next = text.slice(0, start) + emoji + text.slice(end);
|
||||
setText(next);
|
||||
requestAnimationFrame(() => {
|
||||
el.focus();
|
||||
el.setSelectionRange(start + emoji.length, start + emoji.length);
|
||||
});
|
||||
}
|
||||
|
||||
async function submit(e: React.FormEvent) {
|
||||
e.preventDefault();
|
||||
if (!text.trim() || busy) return;
|
||||
if (await onSubmit(text)) {
|
||||
setText("");
|
||||
setTray(false);
|
||||
}
|
||||
}
|
||||
|
||||
return (
|
||||
<form className="fc" onSubmit={submit}>
|
||||
<label htmlFor={id} className="sr-only">
|
||||
{label}
|
||||
</label>
|
||||
<textarea
|
||||
id={id}
|
||||
ref={area}
|
||||
className="fc-text"
|
||||
rows={rows}
|
||||
placeholder={placeholder}
|
||||
value={text}
|
||||
onChange={(e) => setText(e.target.value)}
|
||||
maxLength={10000}
|
||||
autoFocus={autoFocus}
|
||||
/>
|
||||
{tray && (
|
||||
<div className="fc-tray" role="group" aria-label="Emoji">
|
||||
{EMOJI.map((e) => (
|
||||
<button key={e} type="button" className="fc-emoji" onClick={() => insert(e)} aria-label={`${e} beszúrása`}>
|
||||
{e}
|
||||
</button>
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
<div className="fc-actions">
|
||||
<button
|
||||
type="button"
|
||||
className="fc-icon-btn"
|
||||
aria-label="Emoji"
|
||||
aria-expanded={tray}
|
||||
onClick={() => setTray((t) => !t)}
|
||||
>
|
||||
<svg viewBox="0 0 24 24" aria-hidden="true">
|
||||
<circle cx="12" cy="12" r="9" />
|
||||
<path d="M8.5 14.5a4 4 0 0 0 7 0" />
|
||||
<path d="M9 9.5h.01M15 9.5h.01" strokeWidth="2.6" />
|
||||
</svg>
|
||||
</button>
|
||||
<span className="fc-spacer" />
|
||||
{onCancel && (
|
||||
<button type="button" className="btn btn-ghost btn-sm" onClick={onCancel}>
|
||||
Mégse
|
||||
</button>
|
||||
)}
|
||||
<button type="submit" className="btn btn-primary btn-sm" disabled={busy || !text.trim()}>
|
||||
{busy ? "Küldés…" : submitLabel}
|
||||
</button>
|
||||
</div>
|
||||
</form>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,111 @@
|
||||
"use client";
|
||||
|
||||
import Link from "next/link";
|
||||
import { usePathname } from "next/navigation";
|
||||
import { useEffect } from "react";
|
||||
|
||||
import { api } from "@/lib/api";
|
||||
|
||||
/** Every minute while the page is in front: keeps the member's online dot. */
|
||||
function usePresence(member: boolean) {
|
||||
useEffect(() => {
|
||||
if (!member) return;
|
||||
const ping = () => {
|
||||
if (document.visibilityState === "visible") api("/forum/presence", { method: "POST" }).catch(() => {});
|
||||
};
|
||||
const timer = window.setInterval(ping, 60_000);
|
||||
document.addEventListener("visibilitychange", ping);
|
||||
return () => {
|
||||
window.clearInterval(timer);
|
||||
document.removeEventListener("visibilitychange", ping);
|
||||
};
|
||||
}, [member]);
|
||||
}
|
||||
|
||||
function Icon({ name }: { name: "forum" | "followed" | "new" | "profile" }) {
|
||||
return (
|
||||
<svg viewBox="0 0 24 24" aria-hidden="true" className="fn-icon">
|
||||
{name === "forum" && (
|
||||
<>
|
||||
<path d="M4 5h12a2 2 0 0 1 2 2v6a2 2 0 0 1-2 2H9l-4 3v-3H4a2 2 0 0 1-2-2V7a2 2 0 0 1 2-2z" />
|
||||
<path d="M20 9h1a1 1 0 0 1 1 1v8l-3-2h-6" />
|
||||
</>
|
||||
)}
|
||||
{name === "followed" && (
|
||||
<>
|
||||
<path d="M6 16V11a6 6 0 0 1 12 0v5l1.5 2h-15z" />
|
||||
<path d="M10 20.5a2 2 0 0 0 4 0" />
|
||||
</>
|
||||
)}
|
||||
{name === "new" && (
|
||||
<>
|
||||
<circle cx="12" cy="12" r="9" />
|
||||
<path d="M12 8v8M8 12h8" />
|
||||
</>
|
||||
)}
|
||||
{name === "profile" && (
|
||||
<>
|
||||
<circle cx="12" cy="8" r="4" />
|
||||
<path d="M4.5 20.5c0-3.8 3.4-6 7.5-6s7.5 2.2 7.5 6" />
|
||||
</>
|
||||
)}
|
||||
</svg>
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* The forum's own menu: a bar at the bottom of the screen on phones, tabs
|
||||
* above the content on wider screens. `unread`: new replies in followed threads.
|
||||
*/
|
||||
export function ForumNav({ member, loggedIn, unread }: { member: string | null; loggedIn: boolean; unread: number }) {
|
||||
const path = usePathname();
|
||||
usePresence(member !== null);
|
||||
const items = [
|
||||
{
|
||||
href: "/forum",
|
||||
label: "Fórum",
|
||||
icon: "forum" as const,
|
||||
current: path === "/forum" || path.startsWith("/forum/szal"),
|
||||
},
|
||||
{
|
||||
href: loggedIn ? "/forum/kovetett" : "/belepes?vissza=/forum/kovetett",
|
||||
label: "Követett",
|
||||
icon: "followed" as const,
|
||||
current: path.startsWith("/forum/kovetett"),
|
||||
badge: unread,
|
||||
},
|
||||
{
|
||||
href: loggedIn ? "/forum/uj" : "/belepes?vissza=/forum/uj",
|
||||
label: "Új szál",
|
||||
icon: "new" as const,
|
||||
current: path.startsWith("/forum/uj"),
|
||||
},
|
||||
{
|
||||
href: member
|
||||
? `/forum/tag/${encodeURIComponent(member)}`
|
||||
: loggedIn
|
||||
? "/forum/beallitasok"
|
||||
: "/belepes?vissza=/forum",
|
||||
label: member ? "Profilom" : loggedIn ? "Álnév" : "Belépés",
|
||||
icon: "profile" as const,
|
||||
current: path.startsWith("/forum/tag/") || path.startsWith("/forum/beallitasok"),
|
||||
},
|
||||
];
|
||||
return (
|
||||
<nav className="forum-nav" aria-label="Fórum menü">
|
||||
{items.map((item) => (
|
||||
<Link key={item.label} href={item.href} aria-current={item.current ? "page" : undefined} className="fn-item">
|
||||
<span className="fn-icon-wrap">
|
||||
<Icon name={item.icon} />
|
||||
{item.badge ? (
|
||||
<span className="fn-badge" aria-label={`${item.badge} új`}>
|
||||
{item.badge > 99 ? "99+" : item.badge}
|
||||
</span>
|
||||
) : null}
|
||||
</span>
|
||||
<span className="fn-label">{item.label}</span>
|
||||
</Link>
|
||||
))}
|
||||
</nav>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
/** A post's text: paragraphs and line breaks as typed; links stay plain text. */
|
||||
export function PostBody({ text }: { text: string }) {
|
||||
return (
|
||||
<div className="fp-body">
|
||||
{text.split(/\n{2,}/).map((para, i) => (
|
||||
<p key={i}>
|
||||
{para.split("\n").map((line, j) => (
|
||||
<span key={j}>
|
||||
{j > 0 && <br />}
|
||||
{line}
|
||||
</span>
|
||||
))}
|
||||
</p>
|
||||
))}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
"use client";
|
||||
|
||||
import { useState } from "react";
|
||||
|
||||
import { FORUM_THEME_COOKIE, type ForumTheme } from "@/lib/forum";
|
||||
|
||||
/**
|
||||
* Light (the forum's default) or dark. Remembered in a cookie, so the server
|
||||
* renders the chosen one and nothing flashes on load.
|
||||
*/
|
||||
export function ThemeToggle({ initial }: { initial: ForumTheme }) {
|
||||
const [theme, setTheme] = useState<ForumTheme>(initial);
|
||||
const next: ForumTheme = theme === "light" ? "dark" : "light";
|
||||
|
||||
function toggle() {
|
||||
document.cookie = `${FORUM_THEME_COOKIE}=${next}; path=/; max-age=${60 * 60 * 24 * 365}; samesite=lax`;
|
||||
document.querySelector<HTMLElement>(".forum")?.setAttribute("data-theme", next);
|
||||
setTheme(next);
|
||||
}
|
||||
|
||||
return (
|
||||
<button
|
||||
type="button"
|
||||
className="forum-theme"
|
||||
onClick={toggle}
|
||||
aria-label={next === "dark" ? "Sötét téma" : "Világos téma"}
|
||||
title={next === "dark" ? "Sötét téma" : "Világos téma"}
|
||||
>
|
||||
<svg viewBox="0 0 24 24" aria-hidden="true">
|
||||
{next === "dark" ? (
|
||||
<path d="M20 14.5A8 8 0 0 1 9.5 4a8 8 0 1 0 10.5 10.5z" />
|
||||
) : (
|
||||
<>
|
||||
<circle cx="12" cy="12" r="4" />
|
||||
<path d="M12 2.5v2M12 19.5v2M2.5 12h2M19.5 12h2M5.3 5.3l1.4 1.4M17.3 17.3l1.4 1.4M5.3 18.7l1.4-1.4M17.3 6.7l1.4-1.4" />
|
||||
</>
|
||||
)}
|
||||
</svg>
|
||||
<span className="forum-theme-label">{next === "dark" ? "Sötét" : "Világos"}</span>
|
||||
</button>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,86 @@
|
||||
import Link from "next/link";
|
||||
|
||||
import { INTENTS, type ThreadCard, ago, threadHref } from "@/lib/forum";
|
||||
|
||||
import { Avatar } from "./Avatar";
|
||||
|
||||
export function IntentTag({ intent, long = false }: { intent: ThreadCard["intent"]; long?: boolean }) {
|
||||
if (!intent) return null;
|
||||
const text = long ? INTENTS[intent].label : INTENTS[intent].short;
|
||||
return <span className={`ft-intent ft-intent-${intent}`}>{text}</span>;
|
||||
}
|
||||
|
||||
function UnreadPill({ n }: { n: number | null }) {
|
||||
if (n === null) return null;
|
||||
if (n === 0) return <span className="ft-read">olvasva</span>;
|
||||
return <span className="ft-new">{n > 99 ? "99+" : n} új</span>;
|
||||
}
|
||||
|
||||
/** Threads in a list: title, topic, replies, the starter, what is new. */
|
||||
export function ThreadList({ threads, showTopic = true }: { threads: ThreadCard[]; showTopic?: boolean }) {
|
||||
return (
|
||||
<ul className="ft-list">
|
||||
{threads.map((t) => (
|
||||
<li key={t.id}>
|
||||
<Link href={threadHref(t)} className="ft-row">
|
||||
<span className="ft-main">
|
||||
<span className="ft-title">
|
||||
{t.pinned && <span className="ft-pin">Kitűzve</span>}
|
||||
{t.locked && <span className="ft-pin">Lezárva</span>}
|
||||
{t.title}
|
||||
</span>
|
||||
<span className="ft-meta">
|
||||
{t.author && <Avatar avatar={t.author.avatar} size={20} online={t.author.online} />}
|
||||
<span>
|
||||
{t.author?.nickname ?? "Törölt tag"}
|
||||
{showTopic && ` · ${t.topic.name}`}
|
||||
<span className="ft-m-narrow">
|
||||
{" "}
|
||||
· {t.reply_count} válasz ·{" "}
|
||||
<time suppressHydrationWarning dateTime={t.last_post_at}>
|
||||
{ago(t.last_post_at)}
|
||||
</time>
|
||||
</span>
|
||||
</span>
|
||||
</span>
|
||||
</span>
|
||||
<span className="ft-col ft-col-replies">
|
||||
<strong>{t.reply_count}</strong> válasz
|
||||
{t.participants > 1 && <span className="hint">{t.participants} résztvevő</span>}
|
||||
</span>
|
||||
<span className="ft-col ft-col-last">
|
||||
<time suppressHydrationWarning dateTime={t.last_post_at}>
|
||||
{ago(t.last_post_at)}
|
||||
</time>
|
||||
</span>
|
||||
<UnreadPill n={t.unread} />
|
||||
</Link>
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
);
|
||||
}
|
||||
|
||||
/** "Várják a válaszod": a thread without replies, with the starter's wish and a reply button. */
|
||||
export function WaitingCard({ thread }: { thread: ThreadCard }) {
|
||||
return (
|
||||
<article className="ft-waiting">
|
||||
<IntentTag intent={thread.intent} long />
|
||||
<Link href={threadHref(thread)} className="ft-waiting-title">
|
||||
{thread.title}
|
||||
</Link>
|
||||
<span className="ft-meta">
|
||||
{thread.author && <Avatar avatar={thread.author.avatar} size={24} online={thread.author.online} />}
|
||||
<span>
|
||||
{thread.author?.nickname ?? "Törölt tag"} · {thread.topic.name} ·{" "}
|
||||
<time suppressHydrationWarning dateTime={thread.created_at}>
|
||||
{ago(thread.created_at)}
|
||||
</time>
|
||||
</span>
|
||||
</span>
|
||||
<Link href={`${threadHref(thread)}#valasz`} className="btn btn-sm ft-answer">
|
||||
Válaszolok
|
||||
</Link>
|
||||
</article>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,632 @@
|
||||
"use client";
|
||||
|
||||
import Link from "next/link";
|
||||
import { useCallback, useEffect, useMemo, useRef, useState } from "react";
|
||||
|
||||
import { api, errorText } from "@/lib/api";
|
||||
import { type ForumPost, INTENTS, REACTIONS, type ReactionKind, type ThreadPage, memberHref } from "@/lib/forum";
|
||||
|
||||
import { AuthorLine, signsText } from "./AuthorLine";
|
||||
import { Avatar } from "./Avatar";
|
||||
import { Composer } from "./Composer";
|
||||
import { PostBody } from "./PostBody";
|
||||
|
||||
/** How often the open thread looks for new replies (while the page is in front). */
|
||||
const POLL_MS = 30_000;
|
||||
|
||||
type Actions = {
|
||||
busy: boolean;
|
||||
react: (post: ForumPost, kind: ReactionKind | "down") => void;
|
||||
replyTo: (post: ForumPost) => void;
|
||||
edit: (post: ForumPost, body: string) => Promise<boolean>;
|
||||
remove: (post: ForumPost) => void;
|
||||
restore: (post: ForumPost) => void;
|
||||
helped: (post: ForumPost) => void;
|
||||
};
|
||||
|
||||
function ReactionGrid({ post, enabled, onReact }: { post: ForumPost; enabled: boolean; onReact: Actions["react"] }) {
|
||||
return (
|
||||
<div className="fr-grid" role="group" aria-label="Reakciók">
|
||||
{REACTIONS.map((r) => (
|
||||
<button
|
||||
key={r.kind}
|
||||
type="button"
|
||||
className="fr-big"
|
||||
aria-pressed={post.mine === r.kind}
|
||||
disabled={!enabled}
|
||||
onClick={() => onReact(post, r.kind)}
|
||||
>
|
||||
<span aria-hidden="true">{r.emoji}</span>
|
||||
<span className="fr-big-label">{r.label}</span>
|
||||
<span className="fr-count">{post.reactions[r.kind]}</span>
|
||||
</button>
|
||||
))}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
function ReactionRow({
|
||||
post,
|
||||
enabled,
|
||||
canDownvote,
|
||||
onReact,
|
||||
}: {
|
||||
post: ForumPost;
|
||||
enabled: boolean;
|
||||
canDownvote: boolean;
|
||||
onReact: Actions["react"];
|
||||
}) {
|
||||
const [open, setOpen] = useState(false);
|
||||
const given = REACTIONS.filter((r) => post.reactions[r.kind] > 0 || post.mine === r.kind);
|
||||
return (
|
||||
<div className="fr-row" role="group" aria-label="Reakciók">
|
||||
{given.map((r) => (
|
||||
<button
|
||||
key={r.kind}
|
||||
type="button"
|
||||
className="fr-chip"
|
||||
aria-pressed={post.mine === r.kind}
|
||||
aria-label={`${r.label}, ${post.reactions[r.kind]}`}
|
||||
disabled={!enabled}
|
||||
onClick={() => onReact(post, r.kind)}
|
||||
>
|
||||
{r.emoji} {post.reactions[r.kind]}
|
||||
</button>
|
||||
))}
|
||||
{enabled && (
|
||||
<span className="fr-more">
|
||||
<button
|
||||
type="button"
|
||||
className="fr-chip fr-add"
|
||||
aria-label="Reakció hozzáadása"
|
||||
aria-expanded={open}
|
||||
onClick={() => setOpen((o) => !o)}
|
||||
>
|
||||
+
|
||||
</button>
|
||||
{open && (
|
||||
<span className="fr-pop" role="menu">
|
||||
{REACTIONS.map((r) => (
|
||||
<button
|
||||
key={r.kind}
|
||||
type="button"
|
||||
role="menuitem"
|
||||
className="fr-pop-item"
|
||||
onClick={() => {
|
||||
setOpen(false);
|
||||
onReact(post, r.kind);
|
||||
}}
|
||||
>
|
||||
<span aria-hidden="true">{r.emoji}</span> {r.label}
|
||||
</button>
|
||||
))}
|
||||
</span>
|
||||
)}
|
||||
</span>
|
||||
)}
|
||||
{canDownvote && enabled && (
|
||||
<button
|
||||
type="button"
|
||||
className="fr-chip fr-down"
|
||||
aria-pressed={post.mine === "down"}
|
||||
aria-label="Nem visz előre"
|
||||
title="Nem visz előre"
|
||||
onClick={() => onReact(post, "down")}
|
||||
>
|
||||
⌄
|
||||
</button>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
/** The author column of wide screens: avatar, nickname, rank, badges, signs one per line. */
|
||||
function AuthorPanel({ author, starter }: { author: ForumPost["author"]; starter: boolean }) {
|
||||
if (!author) {
|
||||
return (
|
||||
<aside className="fp-author">
|
||||
<Avatar avatar={null} size={56} />
|
||||
<span className="fp-author-name muted">Törölt tag</span>
|
||||
</aside>
|
||||
);
|
||||
}
|
||||
const signs = signsText(author.signs);
|
||||
return (
|
||||
<aside className="fp-author">
|
||||
<Link href={memberHref(author.nickname)} tabIndex={-1} aria-hidden="true">
|
||||
<Avatar avatar={author.avatar} size={56} online={author.online} />
|
||||
</Link>
|
||||
<Link href={memberHref(author.nickname)} className="fp-author-name">
|
||||
{author.nickname}
|
||||
</Link>
|
||||
{author.online && <span className="sr-only">(online)</span>}
|
||||
<span className="fa-rank">{author.rank_name}</span>
|
||||
{author.moderator && <span className="fa-badge fa-badge-mod">Moderátor</span>}
|
||||
{starter && <span className="fa-badge fa-badge-starter">Szálindító</span>}
|
||||
{signs && (
|
||||
<span className="fp-author-signs sym">
|
||||
{signs.split(" · ").map((line) => (
|
||||
<span key={line}>{line}</span>
|
||||
))}
|
||||
</span>
|
||||
)}
|
||||
</aside>
|
||||
);
|
||||
}
|
||||
|
||||
function PostCard({
|
||||
post,
|
||||
page,
|
||||
actions,
|
||||
isNew,
|
||||
}: {
|
||||
post: ForumPost;
|
||||
page: ThreadPage;
|
||||
actions: Actions;
|
||||
isNew: boolean;
|
||||
}) {
|
||||
const [editing, setEditing] = useState(false);
|
||||
const [showCollapsed, setShowCollapsed] = useState(false);
|
||||
const { viewer, thread, access } = page;
|
||||
const writer = viewer.member !== null && !viewer.member.banned;
|
||||
const starter = post.author !== null && post.author.nickname === thread.author?.nickname;
|
||||
const canReact = writer && !post.own && !post.deleted && !thread.locked;
|
||||
|
||||
if (post.deleted && !viewer.moderator) {
|
||||
return (
|
||||
<article className="fp fp-removed" id={`h${post.id}`}>
|
||||
<span>
|
||||
{post.deleted.by_moderator
|
||||
? "A moderátor eltávolította ezt a hozzászólást."
|
||||
: "A szerző törölte ezt a hozzászólást."}
|
||||
</span>
|
||||
{post.deleted.reason && <span className="hint">Ok: {post.deleted.reason}</span>}
|
||||
</article>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<article className={post.is_opening ? "fp fp-opening" : "fp"} id={`h${post.id}`}>
|
||||
{/* Wide screens: the old forums' author column. */}
|
||||
<AuthorPanel author={post.author} starter={starter && !post.is_opening} />
|
||||
<div className="fp-content">
|
||||
<div className="fp-head">
|
||||
<AuthorLine
|
||||
author={post.author}
|
||||
size={post.is_opening ? 44 : 36}
|
||||
time={post.created_at}
|
||||
edited={post.edited_at !== null}
|
||||
badges={
|
||||
<>
|
||||
{starter && !post.is_opening && <span className="fa-badge fa-badge-starter">Szálindító</span>}
|
||||
{isNew && <span className="fa-badge fa-badge-new">új</span>}
|
||||
</>
|
||||
}
|
||||
/>
|
||||
</div>
|
||||
<p className="fp-when">
|
||||
<time suppressHydrationWarning dateTime={post.created_at}>
|
||||
{new Date(post.created_at).toLocaleString("hu-HU", {
|
||||
timeZone: "Europe/Budapest",
|
||||
month: "long",
|
||||
day: "numeric",
|
||||
hour: "2-digit",
|
||||
minute: "2-digit",
|
||||
})}
|
||||
</time>
|
||||
{post.edited_at && " · szerkesztve"}
|
||||
{isNew && <span className="fa-badge fa-badge-new">új</span>}
|
||||
</p>
|
||||
{post.deleted && (
|
||||
<p className="fp-mod-note">
|
||||
Eltávolítva{post.deleted.reason ? ` (ok: ${post.deleted.reason})` : " a szerző által"}. Csak a moderátorok
|
||||
látják.
|
||||
</p>
|
||||
)}
|
||||
{post.collapsed && !showCollapsed ? (
|
||||
<button type="button" className="fp-collapsed" onClick={() => setShowCollapsed(true)}>
|
||||
Sokan jelezték, hogy ez nem visz előre. Megjelenítés
|
||||
</button>
|
||||
) : editing ? (
|
||||
<Composer
|
||||
id={`szerk-${post.id}`}
|
||||
label="Hozzászólás szerkesztése"
|
||||
initial={post.body ?? ""}
|
||||
submitLabel="Mentés"
|
||||
busy={actions.busy}
|
||||
autoFocus
|
||||
onCancel={() => setEditing(false)}
|
||||
onSubmit={async (text) => {
|
||||
const ok = await actions.edit(post, text);
|
||||
if (ok) setEditing(false);
|
||||
return ok;
|
||||
}}
|
||||
/>
|
||||
) : (
|
||||
post.body !== null && <PostBody text={post.body} />
|
||||
)}
|
||||
{post.helped && (
|
||||
<p className="fp-helped">
|
||||
<svg viewBox="0 0 24 24" aria-hidden="true">
|
||||
<path d="M5 12.5l4.5 4.5L19 7.5" />
|
||||
</svg>
|
||||
{thread.author?.nickname ?? "A szál indítója"} szerint ez segített
|
||||
</p>
|
||||
)}
|
||||
{!post.deleted && !editing && (
|
||||
<>
|
||||
{post.is_opening ? (
|
||||
<ReactionGrid post={post} enabled={canReact} onReact={actions.react} />
|
||||
) : (
|
||||
<div className="fp-actions">
|
||||
<ReactionRow
|
||||
post={post}
|
||||
enabled={canReact}
|
||||
canDownvote={access?.can_downvote ?? false}
|
||||
onReact={actions.react}
|
||||
/>
|
||||
<span className="fp-spacer" />
|
||||
{access?.can_reply && writer && (
|
||||
<button type="button" className="fp-link" onClick={() => actions.replyTo(post)}>
|
||||
Válasz
|
||||
</button>
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
<div className="fp-tools">
|
||||
{access?.is_thread_author && !post.is_opening && !post.own && writer && (
|
||||
<button
|
||||
type="button"
|
||||
className="fp-tool"
|
||||
onClick={() => actions.helped(post)}
|
||||
aria-pressed={post.helped}
|
||||
>
|
||||
{post.helped ? "Segített ✓" : "Ez segített"}
|
||||
</button>
|
||||
)}
|
||||
{post.own && writer && !thread.locked && (
|
||||
<button type="button" className="fp-tool" onClick={() => setEditing(true)}>
|
||||
Szerkesztés
|
||||
</button>
|
||||
)}
|
||||
{post.own && (
|
||||
<button type="button" className="fp-tool" onClick={() => actions.remove(post)}>
|
||||
Törlés
|
||||
</button>
|
||||
)}
|
||||
{viewer.moderator && !post.own && (
|
||||
<button type="button" className="fp-tool fp-tool-mod" onClick={() => actions.remove(post)}>
|
||||
Eltávolítás
|
||||
</button>
|
||||
)}
|
||||
{viewer.moderator && typeof post.down === "number" && post.down > 0 && (
|
||||
<span className="hint">⌄ {post.down}</span>
|
||||
)}
|
||||
</div>
|
||||
</>
|
||||
)}
|
||||
{post.deleted && viewer.moderator && (
|
||||
<div className="fp-tools">
|
||||
<button type="button" className="fp-tool" onClick={() => actions.restore(post)}>
|
||||
Visszaállítás (admin)
|
||||
</button>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</article>
|
||||
);
|
||||
}
|
||||
|
||||
/** The thread page: posts, reactions, replies, read marks, new replies while open. */
|
||||
export function ThreadView({ initial }: { initial: ThreadPage }) {
|
||||
const [page, setPage] = useState(initial);
|
||||
const [incoming, setIncoming] = useState<ThreadPage | null>(null);
|
||||
const [replyTo, setReplyTo] = useState<ForumPost | null>(null);
|
||||
const [busy, setBusy] = useState(false);
|
||||
const [error, setError] = useState<string | null>(null);
|
||||
// Where the visitor stopped reading when they opened the page.
|
||||
const [readUpTo] = useState(initial.access?.last_read_post_id ?? null);
|
||||
const composer = useRef<HTMLDivElement>(null);
|
||||
const { viewer, thread, access } = page;
|
||||
const member = viewer.member !== null;
|
||||
const base = `/forum/threads/${thread.id}`;
|
||||
|
||||
const lastId = page.posts.length ? page.posts[page.posts.length - 1].id : 0;
|
||||
|
||||
// Mark read up to the newest post shown.
|
||||
useEffect(() => {
|
||||
if (!member || lastId === 0) return;
|
||||
api(`${base}/read`, { body: { post_id: lastId } }).catch(() => {});
|
||||
}, [member, lastId, base]);
|
||||
|
||||
// New replies while the page is open: offered, not pushed into the text being read.
|
||||
const poll = useCallback(async () => {
|
||||
if (document.visibilityState !== "visible" || thread.deleted) return;
|
||||
try {
|
||||
const fresh = await api<ThreadPage>(base);
|
||||
const freshLast = fresh.posts.length ? fresh.posts[fresh.posts.length - 1].id : 0;
|
||||
if (freshLast > lastId) setIncoming(fresh);
|
||||
} catch {
|
||||
/* a missed poll is retried later */
|
||||
}
|
||||
}, [base, lastId, thread.deleted]);
|
||||
useEffect(() => {
|
||||
const timer = window.setInterval(poll, POLL_MS);
|
||||
return () => window.clearInterval(timer);
|
||||
}, [poll]);
|
||||
|
||||
const newCount = incoming ? incoming.posts.filter((p) => p.id > lastId && !p.own).length : 0;
|
||||
|
||||
async function run<T>(work: () => Promise<T>): Promise<T | null> {
|
||||
setBusy(true);
|
||||
setError(null);
|
||||
try {
|
||||
return await work();
|
||||
} catch (e) {
|
||||
setError(errorText(e));
|
||||
return null;
|
||||
} finally {
|
||||
setBusy(false);
|
||||
}
|
||||
}
|
||||
|
||||
const replacePost = useCallback((post: ForumPost) => {
|
||||
setPage((p) => ({ ...p, posts: p.posts.map((x) => (x.id === post.id ? post : x)) }));
|
||||
}, []);
|
||||
|
||||
const reload = useCallback(async () => {
|
||||
const fresh = await api<ThreadPage>(base);
|
||||
setPage(fresh);
|
||||
setIncoming(null);
|
||||
}, [base]);
|
||||
|
||||
const actions: Actions = {
|
||||
busy,
|
||||
react: (post, kind) =>
|
||||
void run(async () => {
|
||||
const updated =
|
||||
post.mine === kind
|
||||
? await api<ForumPost>(`/forum/posts/${post.id}/reaction`, { method: "DELETE" })
|
||||
: await api<ForumPost>(`/forum/posts/${post.id}/reaction`, { method: "PUT", body: { kind } });
|
||||
replacePost(updated);
|
||||
}),
|
||||
replyTo: (post) => {
|
||||
setReplyTo(post);
|
||||
composer.current?.scrollIntoView({ behavior: "smooth", block: "center" });
|
||||
},
|
||||
edit: async (post, body) => {
|
||||
const updated = await run(() => api<ForumPost>(`/forum/posts/${post.id}`, { method: "PATCH", body: { body } }));
|
||||
if (updated) replacePost(updated);
|
||||
return updated !== null;
|
||||
},
|
||||
remove: (post) => {
|
||||
let reason: string | null = null;
|
||||
if (post.own) {
|
||||
if (!window.confirm("Biztosan törlöd a hozzászólásodat?")) return;
|
||||
} else {
|
||||
reason = window.prompt("Miért távolítod el? Az indoklás a hozzászólás helyén látszik.");
|
||||
if (!reason) return;
|
||||
}
|
||||
void run(async () => {
|
||||
await api(`/forum/posts/${post.id}`, { method: "DELETE", body: { reason } });
|
||||
await reload();
|
||||
});
|
||||
},
|
||||
restore: (post) =>
|
||||
void run(async () => {
|
||||
await api(`/forum/posts/${post.id}/restore`, { method: "POST" });
|
||||
await reload();
|
||||
}),
|
||||
helped: (post) =>
|
||||
void run(async () => {
|
||||
const updated = await api<ForumPost>(`/forum/posts/${post.id}/helped`, {
|
||||
method: post.helped ? "DELETE" : "PUT",
|
||||
});
|
||||
replacePost(updated);
|
||||
}),
|
||||
};
|
||||
|
||||
async function sendReply(text: string): Promise<boolean> {
|
||||
const post = await run(() =>
|
||||
api<ForumPost>(`${base}/posts`, { body: { body: text, parent_id: replyTo?.id ?? null } }),
|
||||
);
|
||||
if (!post) return false;
|
||||
setReplyTo(null);
|
||||
await reload().catch(() => setPage((p) => ({ ...p, posts: [...p.posts, post] })));
|
||||
requestAnimationFrame(() => document.getElementById(`h${post.id}`)?.scrollIntoView({ block: "center" }));
|
||||
return true;
|
||||
}
|
||||
|
||||
async function toggleFollow() {
|
||||
const following = access?.following ?? false;
|
||||
await run(() => api(`${base}/follow`, { method: following ? "DELETE" : "PUT" }));
|
||||
setPage((p) => (p.access ? { ...p, access: { ...p.access, following: !following } } : p));
|
||||
}
|
||||
|
||||
async function moderateThread(change: { locked?: boolean; pinned?: boolean }) {
|
||||
await run(() => api(base, { method: "PATCH", body: change }));
|
||||
await reload();
|
||||
}
|
||||
|
||||
async function removeThread() {
|
||||
const reason = window.prompt("Miért távolítod el az egész szálat? Az indoklás látszik a helyén.");
|
||||
if (!reason) return;
|
||||
await run(() => api(base, { method: "DELETE", body: { reason } }));
|
||||
await reload();
|
||||
}
|
||||
|
||||
const opening = page.posts.find((p) => p.is_opening);
|
||||
const replies = useMemo(() => page.posts.filter((p) => !p.is_opening), [page.posts]);
|
||||
const tops = replies.filter((p) => p.parent_id === null);
|
||||
const childrenOf = (id: number) => replies.filter((p) => p.parent_id === id);
|
||||
// "Itt hagytad abba": before the first post by someone else after the last visit.
|
||||
const firstUnread = readUpTo !== null ? (replies.find((p) => p.id > readUpTo && !p.own)?.id ?? null) : null;
|
||||
const unreadCount = firstUnread !== null ? replies.filter((p) => p.id >= firstUnread && !p.own).length : 0;
|
||||
const topOf = (id: number) => {
|
||||
const p = replies.find((x) => x.id === id);
|
||||
return p?.parent_id ?? id;
|
||||
};
|
||||
const markerTop = firstUnread !== null ? topOf(firstUnread) : null;
|
||||
const intent = thread.intent ? INTENTS[thread.intent] : null;
|
||||
const starter = thread.author?.nickname ?? "A szál indítója";
|
||||
|
||||
return (
|
||||
<div className="ftv">
|
||||
<nav className="forum-crumbs" aria-label="Morzsamenü">
|
||||
<Link href="/forum">Fórum</Link>
|
||||
<span aria-hidden="true">›</span>
|
||||
<Link href={`/forum/${thread.topic.slug}`}>{thread.topic.name}</Link>
|
||||
</nav>
|
||||
|
||||
<div className="ftv-toolbar">
|
||||
{member && access && (
|
||||
<button type="button" className="btn btn-sm" aria-pressed={access.following} onClick={toggleFollow}>
|
||||
{access.following ? "Követem ✓" : "Követem"}
|
||||
</button>
|
||||
)}
|
||||
{viewer.moderator && !thread.deleted && (
|
||||
<details className="ftv-mod">
|
||||
<summary className="btn btn-sm btn-ghost">Moderálás</summary>
|
||||
<div className="ftv-mod-menu">
|
||||
<button type="button" onClick={() => moderateThread({ locked: !thread.locked })}>
|
||||
{thread.locked ? "Szál feloldása" : "Szál lezárása"}
|
||||
</button>
|
||||
<button type="button" onClick={() => moderateThread({ pinned: !thread.pinned })}>
|
||||
{thread.pinned ? "Kitűzés levétele" : "Kitűzés"}
|
||||
</button>
|
||||
<button type="button" className="danger" onClick={removeThread}>
|
||||
Szál eltávolítása
|
||||
</button>
|
||||
</div>
|
||||
</details>
|
||||
)}
|
||||
</div>
|
||||
|
||||
{thread.deleted ? (
|
||||
<div className="fp fp-removed">
|
||||
<span>A moderátor eltávolította ezt a szálat.</span>
|
||||
{thread.deleted.reason && <span className="hint">Ok: {thread.deleted.reason}</span>}
|
||||
</div>
|
||||
) : null}
|
||||
|
||||
{intent && thread.intent === "listen" && (
|
||||
<div className="ftv-intent">
|
||||
<strong>{intent.label}</strong>
|
||||
<span>{starter} most nem kér tanácsot. Elég, ha jelen vagy, és leírod, ha veled is történt hasonló.</span>
|
||||
</div>
|
||||
)}
|
||||
{intent && thread.intent === "advice" && (
|
||||
<div className="ftv-intent ftv-intent-advice">
|
||||
<strong>{intent.label}</strong>
|
||||
<span>{starter} kíváncsi a véleményetekre és a tapasztalataitokra.</span>
|
||||
</div>
|
||||
)}
|
||||
|
||||
<h1 className="ftv-title">
|
||||
{thread.pinned && <span className="ft-pin">Kitűzve</span>}
|
||||
{thread.locked && <span className="ft-pin">Lezárva</span>}
|
||||
{thread.title}
|
||||
</h1>
|
||||
|
||||
{opening && <PostCard post={opening} page={page} actions={actions} isNew={false} />}
|
||||
|
||||
{(replies.length > 0 || !thread.deleted) && (
|
||||
<div className="ftv-count">
|
||||
<h2>{replies.filter((p) => !p.deleted).length} válasz</h2>
|
||||
<span className="hint">időrendben</span>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{tops.map((top) => (
|
||||
<div key={top.id} className="ftv-branch">
|
||||
{markerTop === top.id && (
|
||||
<div className="ftv-marker" role="separator" aria-label={`Itt hagytad abba, ${unreadCount} új`}>
|
||||
<span>Itt hagytad abba · {unreadCount} új</span>
|
||||
</div>
|
||||
)}
|
||||
<PostCard
|
||||
post={top}
|
||||
page={page}
|
||||
actions={actions}
|
||||
isNew={firstUnread !== null && top.id >= firstUnread && !top.own}
|
||||
/>
|
||||
{childrenOf(top.id).length > 0 && (
|
||||
<div className="ftv-children">
|
||||
{childrenOf(top.id).map((child) => (
|
||||
<PostCard
|
||||
key={child.id}
|
||||
post={child}
|
||||
page={page}
|
||||
actions={actions}
|
||||
isNew={firstUnread !== null && child.id >= firstUnread && !child.own}
|
||||
/>
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
))}
|
||||
|
||||
{newCount > 0 && (
|
||||
<button
|
||||
type="button"
|
||||
className="ftv-incoming"
|
||||
onClick={() => incoming && (setPage(incoming), setIncoming(null))}
|
||||
>
|
||||
{newCount === 1 ? "1 új válasz érkezett" : `${newCount} új válasz érkezett`}
|
||||
</button>
|
||||
)}
|
||||
|
||||
{error && (
|
||||
<p className="msg msg-error" role="alert">
|
||||
{error}
|
||||
</p>
|
||||
)}
|
||||
|
||||
<div className="ftv-compose" id="valasz" ref={composer}>
|
||||
{thread.deleted ? null : !viewer.logged_in ? (
|
||||
<p className="ftv-gate">
|
||||
<Link href={`/belepes?vissza=/forum/szal/${thread.id}-${thread.slug}`}>Lépj be</Link>, hogy hozzászólhass.
|
||||
</p>
|
||||
) : viewer.needs_nickname ? (
|
||||
<p className="ftv-gate">
|
||||
<Link href={`/forum/beallitasok?vissza=/forum/szal/${thread.id}-${thread.slug}`}>Válassz álnevet</Link>,
|
||||
hogy hozzászólhass.
|
||||
</p>
|
||||
) : viewer.member?.banned ? (
|
||||
<p className="ftv-gate">Most nem írhatsz a fórumba.</p>
|
||||
) : !access?.can_reply ? (
|
||||
<p className="ftv-gate">Ez a szál le van zárva, új hozzászólás nem írható.</p>
|
||||
) : (
|
||||
<>
|
||||
{thread.intent === "listen" && (
|
||||
<p className="ftv-hint">
|
||||
{starter} meghallgatást kér: tanács helyett írd le, ha veled is történt hasonló, vagy csak azt, hogy itt
|
||||
vagy.
|
||||
</p>
|
||||
)}
|
||||
{replyTo && (
|
||||
<p className="ftv-replyto">
|
||||
Válasz neki: <strong>{replyTo.author?.nickname ?? "Törölt tag"}</strong>
|
||||
<button
|
||||
type="button"
|
||||
className="fp-link"
|
||||
onClick={() => setReplyTo(null)}
|
||||
aria-label="Válasz visszavonása"
|
||||
>
|
||||
×
|
||||
</button>
|
||||
</p>
|
||||
)}
|
||||
<Composer
|
||||
id="valasz-szoveg"
|
||||
label="Válaszod"
|
||||
placeholder={thread.topic.listening ? "Írd le, ami benned van…" : "Írd meg a válaszod…"}
|
||||
busy={busy}
|
||||
onSubmit={sendReply}
|
||||
/>
|
||||
</>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -58,6 +58,7 @@ export const ROLE_LABELS: Record<string, string> = {
|
||||
premium: "Prémium",
|
||||
vip: "VIP",
|
||||
creator: "Szerző",
|
||||
moderator: "Moderátor",
|
||||
admin: "Admin",
|
||||
};
|
||||
|
||||
|
||||
@@ -0,0 +1,259 @@
|
||||
// The forum's data as the forum service sends it, and small helpers shared
|
||||
// by its server and client components.
|
||||
|
||||
/** The forum's colours: light by default, dark on request (a cookie). */
|
||||
export const FORUM_THEME_COOKIE = "sf_forum_theme";
|
||||
export type ForumTheme = "light" | "dark";
|
||||
|
||||
export type Rank = "vandor" | "kereso" | "fono" | "csillagfono" | "sorsfono";
|
||||
export type ReactionKind = "with_you" | "thanks" | "me_too" | "insight";
|
||||
export type ChartShare = "none" | "sun" | "big3" | "planets";
|
||||
|
||||
/** How a member appears next to what they wrote. */
|
||||
export interface ForumAuthor {
|
||||
nickname: string;
|
||||
avatar: string;
|
||||
rank: Rank;
|
||||
rank_name: string;
|
||||
moderator: boolean;
|
||||
online: boolean;
|
||||
/** Planet (or `ascendant`) → sign, as the member chose to share. */
|
||||
signs: Record<string, string> | null;
|
||||
}
|
||||
|
||||
export interface ForumViewer {
|
||||
logged_in: boolean;
|
||||
needs_nickname: boolean;
|
||||
moderator: boolean;
|
||||
member: { nickname: string; avatar: string; rank: Rank; rank_name: string; banned: boolean } | null;
|
||||
}
|
||||
|
||||
export interface TopicRef {
|
||||
slug: string;
|
||||
name: string;
|
||||
}
|
||||
|
||||
export interface ForumTopic extends TopicRef {
|
||||
id: number;
|
||||
description: string;
|
||||
visibility: "public" | "members" | "restricted";
|
||||
listening: boolean;
|
||||
readable: boolean;
|
||||
thread_count?: number;
|
||||
new_count?: number | null;
|
||||
last?: { author: ForumAuthor | null; at: string } | null;
|
||||
}
|
||||
|
||||
export interface ThreadCard {
|
||||
id: number;
|
||||
slug: string;
|
||||
title: string;
|
||||
intent: "listen" | "advice" | null;
|
||||
topic: TopicRef;
|
||||
author: ForumAuthor | null;
|
||||
created_at: string;
|
||||
last_post_at: string;
|
||||
reply_count: number;
|
||||
participants: number;
|
||||
pinned: boolean;
|
||||
locked: boolean;
|
||||
unread: number | null;
|
||||
}
|
||||
|
||||
export interface ForumHome {
|
||||
viewer: ForumViewer;
|
||||
followed: { new_replies: number; threads: number } | null;
|
||||
topics: ForumTopic[];
|
||||
unanswered: ThreadCard[];
|
||||
hot: ThreadCard[];
|
||||
}
|
||||
|
||||
export interface TopicPage {
|
||||
viewer: ForumViewer;
|
||||
topic: TopicRef & { description: string; visibility: string; listening: boolean };
|
||||
threads: ThreadCard[];
|
||||
page: number;
|
||||
has_more: boolean;
|
||||
}
|
||||
|
||||
export interface ForumPost {
|
||||
id: number;
|
||||
parent_id: number | null;
|
||||
is_opening: boolean;
|
||||
author: ForumAuthor | null;
|
||||
own: boolean;
|
||||
body: string | null;
|
||||
deleted: { by_moderator: boolean; reason: string | null } | null;
|
||||
created_at: string;
|
||||
edited_at: string | null;
|
||||
helped: boolean;
|
||||
reactions: Record<ReactionKind, number>;
|
||||
score: number;
|
||||
collapsed: boolean;
|
||||
mine: ReactionKind | "down" | null;
|
||||
/** Moderators only. */
|
||||
down?: number;
|
||||
}
|
||||
|
||||
export interface ThreadPage {
|
||||
viewer: ForumViewer;
|
||||
thread: {
|
||||
id: number;
|
||||
slug: string;
|
||||
title: string;
|
||||
intent: "listen" | "advice" | null;
|
||||
topic: TopicRef & { visibility: string; listening: boolean };
|
||||
author: ForumAuthor | null;
|
||||
created_at: string;
|
||||
locked: boolean;
|
||||
pinned: boolean;
|
||||
deleted: { reason: string | null } | null;
|
||||
};
|
||||
posts: ForumPost[];
|
||||
access?: {
|
||||
can_reply: boolean;
|
||||
can_downvote: boolean;
|
||||
is_thread_author: boolean;
|
||||
following: boolean;
|
||||
last_read_post_id: number | null;
|
||||
};
|
||||
}
|
||||
|
||||
export interface ForumMe {
|
||||
viewer: ForumViewer;
|
||||
member: {
|
||||
nickname: string;
|
||||
avatar: string;
|
||||
bio: string;
|
||||
chart_share: ChartShare;
|
||||
invisible: boolean;
|
||||
points: number;
|
||||
post_count: number;
|
||||
created_at: string;
|
||||
rank: Rank;
|
||||
rank_name: string;
|
||||
next_rank: { rank: Rank; name: string; points: number; days: number } | null;
|
||||
nickname_change_after: string | null;
|
||||
banned_until: string | null;
|
||||
ban_reason: string | null;
|
||||
} | null;
|
||||
chart: Record<Exclude<ChartShare, "none">, Record<string, string> | null> | null;
|
||||
}
|
||||
|
||||
export interface MemberProfile {
|
||||
viewer: ForumViewer;
|
||||
member: {
|
||||
author: ForumAuthor;
|
||||
bio: string;
|
||||
created_at: string;
|
||||
post_count: number;
|
||||
thread_count: number;
|
||||
last_seen: "online" | "day" | "week" | "earlier" | null;
|
||||
own: boolean;
|
||||
banned_until: string | null;
|
||||
ban_reason: string | null;
|
||||
};
|
||||
recent: {
|
||||
id: number;
|
||||
thread_id: number;
|
||||
thread_slug: string;
|
||||
thread_title: string;
|
||||
topic: TopicRef;
|
||||
created_at: string;
|
||||
excerpt: string;
|
||||
is_opening: boolean;
|
||||
}[];
|
||||
}
|
||||
|
||||
export interface ModLogEntry {
|
||||
id: number;
|
||||
actor: string | null;
|
||||
actor_kind: "human" | "ai";
|
||||
action: string;
|
||||
target: string | null;
|
||||
thread: { id: number; title: string | null } | null;
|
||||
post_id: number | null;
|
||||
reason: string | null;
|
||||
until: string | null;
|
||||
created_at: string;
|
||||
}
|
||||
|
||||
export const REACTIONS: { kind: ReactionKind; emoji: string; label: string }[] = [
|
||||
{ kind: "with_you", emoji: "🤍", label: "Veled vagyok" },
|
||||
{ kind: "thanks", emoji: "🙏", label: "Köszönöm" },
|
||||
{ kind: "me_too", emoji: "✨", label: "Rám is igaz" },
|
||||
{ kind: "insight", emoji: "💡", label: "Érdekes gondolat" },
|
||||
];
|
||||
|
||||
export const INTENTS = {
|
||||
listen: { label: "Csak meghallgatást kér", short: "Meghallgatást kér" },
|
||||
advice: { label: "Tanácsot, véleményt kér", short: "Tanácsot kér" },
|
||||
} as const;
|
||||
|
||||
/** The emoji offered first in the composer: the Moon, the signs, warmth. */
|
||||
export const EMOJI = [
|
||||
"🙂",
|
||||
"😊",
|
||||
"🤍",
|
||||
"🙏",
|
||||
"✨",
|
||||
"🌙",
|
||||
"🌕",
|
||||
"🌑",
|
||||
"⭐",
|
||||
"🌸",
|
||||
"🍀",
|
||||
"🕯️",
|
||||
"🌿",
|
||||
"☕",
|
||||
"😢",
|
||||
"🤗",
|
||||
"♈",
|
||||
"♉",
|
||||
"♊",
|
||||
"♋",
|
||||
"♌",
|
||||
"♍",
|
||||
"♎",
|
||||
"♏",
|
||||
"♐",
|
||||
"♑",
|
||||
"♒",
|
||||
"♓",
|
||||
];
|
||||
|
||||
/** `/forum/szal/123-nem-tudom-elengedni`: the number decides, the words are for reading. */
|
||||
export function threadHref(t: { id: number; slug: string }, postId?: number): string {
|
||||
const path = t.slug ? `/forum/szal/${t.id}-${t.slug}` : `/forum/szal/${t.id}`;
|
||||
return postId ? `${path}#h${postId}` : path;
|
||||
}
|
||||
|
||||
export function memberHref(nickname: string): string {
|
||||
return `/forum/tag/${encodeURIComponent(nickname)}`;
|
||||
}
|
||||
|
||||
/** "most", "12 perce", "3 órája", "tegnap", "4 napja", then the date. */
|
||||
export function ago(iso: string, now: Date = new Date()): string {
|
||||
const then = new Date(iso);
|
||||
const minutes = Math.floor((now.getTime() - then.getTime()) / 60000);
|
||||
if (minutes < 1) return "most";
|
||||
if (minutes < 60) return `${minutes} perce`;
|
||||
const hours = Math.floor(minutes / 60);
|
||||
if (hours < 24) return `${hours} órája`;
|
||||
const days = Math.floor(hours / 24);
|
||||
if (days === 1) return "tegnap";
|
||||
if (days < 7) return `${days} napja`;
|
||||
return then.toLocaleDateString("hu-HU", {
|
||||
timeZone: "Europe/Budapest",
|
||||
year: then.getFullYear() === now.getFullYear() ? undefined : "numeric",
|
||||
month: "long",
|
||||
day: "numeric",
|
||||
});
|
||||
}
|
||||
|
||||
/** A ban's end as the member reads it. */
|
||||
export function banText(until: string | null): string {
|
||||
if (!until) return "";
|
||||
if (until === "infinity") return "véglegesen";
|
||||
return `eddig: ${new Date(until).toLocaleString("hu-HU", { timeZone: "Europe/Budapest", month: "long", day: "numeric", hour: "2-digit", minute: "2-digit" })}`;
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
// Forum service calls from server components, with the visitor's session.
|
||||
// Without FORUM_URL the forum is switched off (no menu item, its pages 404).
|
||||
import "server-only";
|
||||
|
||||
import { cookies } from "next/headers";
|
||||
|
||||
import { BackendError, SESSION_COOKIE } from "./server";
|
||||
|
||||
export const FORUM_URL = (process.env.FORUM_URL ?? "").replace(/\/$/, "");
|
||||
|
||||
export function forumEnabled(): boolean {
|
||||
return FORUM_URL !== "";
|
||||
}
|
||||
|
||||
/** The answer of a forum GET: the data, or why there is none. */
|
||||
export type ForumResult<T> = { ok: true; data: T } | { ok: false; status: 401 | 404 };
|
||||
|
||||
/** GET from the forum service as the visitor (logged in or not). */
|
||||
export async function forumGet<T>(path: string): Promise<ForumResult<T>> {
|
||||
if (!forumEnabled()) return { ok: false, status: 404 };
|
||||
const token = (await cookies()).get(SESSION_COOKIE)?.value;
|
||||
const headers: HeadersInit = token ? { authorization: `Bearer ${token}` } : {};
|
||||
const res = await fetch(`${FORUM_URL}${path}`, { headers, cache: "no-store" });
|
||||
if (res.status === 401 || res.status === 404) return { ok: false, status: res.status };
|
||||
// Not allowed (e.g. the moderation log for a member): the page does not exist for them.
|
||||
if (res.status === 403) return { ok: false, status: 404 };
|
||||
if (!res.ok) throw new BackendError(res.status, `${path}: HTTP ${res.status}`);
|
||||
return { ok: true, data: (await res.json()) as T };
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
// Shapes of the backend responses the frontend uses.
|
||||
|
||||
export type Role = "admin" | "creator" | "premium" | "vip" | "user";
|
||||
export type Role = "admin" | "creator" | "moderator" | "premium" | "vip" | "user";
|
||||
|
||||
export interface User {
|
||||
id: string;
|
||||
|
||||
Reference in New Issue
Block a user