Files
sorsfonalak/services/frontend/src/app/forum/moderalas/TopicsAdmin.tsx
T
fecoandClaude Opus 5.5 de629a068d
CI / test (push) Successful in 3m10s
CI / build (push) Skipped
CI / deploy (push) Skipped
Forum photos, a one-row bottom menu, and the site's own question windows
Photos in posts and replies: a "Fotó" button in the new thread form and the
reply boxes. The browser makes the picture small before uploading it (1600
pixels at most, WebP, JPEG where WebP cannot be made); the forum checks it
is a still picture, strips its metadata and makes a square preview
(forum-photos/ in the storage). Five a member a day, five a post; one taken
off before sending is deleted and does not count. Under the post a row of
square previews; a click opens a viewer paged with arrows, swipes and keys.
Seen by whoever may read the thread (long public cache only for public
topics). Unsent photos go after a day, those of removed posts after a year;
removed with the account and listed in the data export. Terms and privacy
notice updated.

The forum's bottom menu keeps its five items in one row (the fifth wrapped
to a second row). On iPhones, when the keyboard goes away without the usual
tap (a photo picker opening over it), the page is put back in place instead
of the menu floating mid-screen over an empty strip.

The browser's own confirm() and prompt() windows (23 places: deleting,
revoking, blocking, muting, moderators' reasons, admin actions) are replaced
by a question window in the site's look, following the forum's light or
dark theme, with named buttons and a text box for reasons.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012vLHzh5qUhFtmJhzkcTbXL
2026-11-27 00:34:59 +00:00

263 lines
9.3 KiB
TypeScript

"use client";
import { useRouter } from "next/navigation";
import { useState } from "react";
import { Avatar } from "@/components/forum/Avatar";
import { RankBadge } from "@/components/forum/Badges";
import { api, errorText } from "@/lib/api";
import { type ForumTopic, type TopicRequest, ago } from "@/lib/forum";
import { confirmDialog } from "@/components/Dialogs";
const VISIBILITY: Record<string, string> = {
public: "Nyilvános (a keresők is látják)",
members: "Csak tagoknak",
restricted: "Zárt (jóváhagyással)",
};
/** Moderators: requests to join restricted topics. Admins also: opening and editing topics. */
export function TopicsAdmin({
requests,
topics,
admin,
}: {
requests: TopicRequest[];
topics: ForumTopic[];
admin: boolean;
}) {
const router = useRouter();
const [busy, setBusy] = useState(false);
const [error, setError] = useState<string | null>(null);
const [form, setForm] = useState({ name: "", description: "", visibility: "restricted", listening: false });
async function act(work: () => Promise<unknown>) {
setBusy(true);
setError(null);
try {
await work();
router.refresh();
} catch (e) {
setError(errorText(e));
} finally {
setBusy(false);
}
}
const decide = (r: TopicRequest, action: "approve" | "reject" | "remove") =>
act(() =>
api("/forum/mod/topic-requests", {
body: { topic: r.topic.slug, nickname: r.member?.nickname ?? "", action },
}),
);
const pending = requests.filter((r) => r.status === "pending");
const approved = requests.filter((r) => r.status === "approved");
return (
<>
{error && (
<p className="msg msg-error" role="alert">
{error}
</p>
)}
<section className="fh-section" aria-labelledby="ftop-pending">
<h2 id="ftop-pending" className="fmsg-h">
Jelentkezések zárt témákba ({pending.length})
</h2>
{pending.length === 0 ? (
<p className="fh-card fh-empty">Nincs várakozó jelentkezés.</p>
) : (
pending.map((r) => (
<article key={`${r.topic.slug}-${r.member?.nickname}`} className="fh-card fmod-report">
<div className="fmod-report-head">
<span className="fh-online-item">
<Avatar avatar={r.member?.avatar} size={28} />
<strong>{r.member?.nickname ?? "?"}</strong>
{r.member && <RankBadge rank={r.member.rank} name={r.member.rank_name} />}
</span>
<span className="hint">
{r.topic.name} ·{" "}
<time suppressHydrationWarning dateTime={r.requested_at}>
{ago(r.requested_at)}
</time>
</span>
</div>
{r.note && <p className="fmod-note">„{r.note}”</p>}
<div className="fmsg-actions">
<button
type="button"
className="btn btn-sm btn-primary"
disabled={busy}
onClick={() => decide(r, "approve")}
>
Jóváhagyom
</button>
<button
type="button"
className="btn btn-sm btn-ghost"
disabled={busy}
onClick={() => decide(r, "reject")}
>
Elutasítom
</button>
</div>
</article>
))
)}
</section>
{approved.length > 0 && (
<section className="fh-section" aria-labelledby="ftop-members">
<h2 id="ftop-members" className="fmsg-h">
Zárt témák tagjai
</h2>
<ul className="fh-card fh-flush fmodlog">
{approved.map((r) => (
<li key={`${r.topic.slug}-${r.member?.nickname}`} className="ftop-member">
<span className="fh-online-item">
<Avatar avatar={r.member?.avatar} size={24} />
{r.member?.nickname ?? "?"}
<span className="hint">· {r.topic.name}</span>
</span>
<button
type="button"
className="btn btn-sm btn-ghost"
disabled={busy}
onClick={async () => {
const ok = await confirmDialog({
title: `Eltávolítod ${r.member?.nickname ?? "a tagot"} a(z) „${r.topic.name}” témából?`,
confirm: "Eltávolítás",
danger: true,
});
if (ok) decide(r, "remove");
}}
>
Eltávolítom
</button>
</li>
))}
</ul>
</section>
)}
{admin && (
<section className="fh-section" aria-labelledby="ftop-admin">
<h2 id="ftop-admin" className="fmsg-h">
Témák (admin)
</h2>
<ul className="fh-card fh-flush fmodlog">
{topics.map((t) => (
<li key={t.slug} className="ftop-member">
<span>
<strong>{t.name}</strong> <span className="hint">· {VISIBILITY[t.visibility] ?? t.visibility}</span>
{t.archived && <span className="hint"> · archivált</span>}
</span>
<button
type="button"
className="btn btn-sm btn-ghost"
disabled={busy}
onClick={async () => {
const ok =
t.archived ||
(await confirmDialog({
title: `Archiválod a(z) „${t.name}” témát?`,
text: "A szálai olvashatók maradnak, de új szál és hozzászólás nem írható bele, és lekerül a főoldalról.",
confirm: "Archiválás",
}));
if (ok)
act(() => api(`/forum/topics/${t.slug}`, { method: "PATCH", body: { archived: !t.archived } }));
}}
>
{t.archived ? "Visszaállítás" : "Archiválás"}
</button>
<select
className="inp ftop-vis"
aria-label={`${t.name} láthatósága`}
value={t.visibility}
disabled={busy}
onChange={(e) =>
act(() => api(`/forum/topics/${t.slug}`, { method: "PATCH", body: { visibility: e.target.value } }))
}
>
{Object.entries(VISIBILITY).map(([value, label]) => (
<option key={value} value={value}>
{label}
</option>
))}
</select>
</li>
))}
</ul>
<form
className="fh-card fnew"
onSubmit={(e) => {
e.preventDefault();
void act(async () => {
await api("/forum/topics", { body: form });
setForm({ name: "", description: "", visibility: "restricted", listening: false });
});
}}
>
<strong>Új téma</strong>
<div className="field">
<label htmlFor="ftop-name">Név</label>
<input
id="ftop-name"
className="inp"
value={form.name}
maxLength={60}
onChange={(e) => setForm({ ...form, name: e.target.value })}
required
/>
</div>
<div className="field">
<label htmlFor="ftop-desc">Rövid leírás</label>
<input
id="ftop-desc"
className="inp"
value={form.description}
maxLength={160}
onChange={(e) => setForm({ ...form, description: e.target.value })}
required
/>
</div>
<div className="field">
<label htmlFor="ftop-visibility">Láthatóság</label>
<select
id="ftop-visibility"
className="inp"
value={form.visibility}
onChange={(e) => setForm({ ...form, visibility: e.target.value })}
>
{Object.entries(VISIBILITY).map(([value, label]) => (
<option key={value} value={value}>
{label}
</option>
))}
</select>
</div>
<label className="fprof-check">
<input
type="checkbox"
checked={form.listening}
onChange={(e) => setForm({ ...form, listening: e.target.checked })}
/>
<span>
<strong>Meghallgatós téma</strong>
<span className="hint">Az új szálak alapból meghallgatást kérnek, nem tanácsot.</span>
</span>
</label>
<button
type="submit"
className="btn btn-primary"
disabled={busy || !form.name.trim() || !form.description.trim()}
>
Téma létrehozása
</button>
</form>
</section>
)}
</>
);
}