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:
@@ -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>
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user