2026-11-26 13:02:38 +00:00
|
|
|
"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";
|
|
|
|
|
|
|
|
|
|
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={() =>
|
|
|
|
|
window.confirm(`Eltávolítod ${r.member?.nickname} tagot a(z) „${r.topic.name}” témából?`) &&
|
|
|
|
|
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>
|
2026-11-26 14:31:05 +00:00
|
|
|
{t.archived && <span className="hint"> · archivált</span>}
|
2026-11-26 13:02:38 +00:00
|
|
|
</span>
|
2026-11-26 14:31:05 +00:00
|
|
|
<button
|
|
|
|
|
type="button"
|
|
|
|
|
className="btn btn-sm btn-ghost"
|
|
|
|
|
disabled={busy}
|
|
|
|
|
onClick={() =>
|
|
|
|
|
(t.archived ||
|
|
|
|
|
window.confirm(
|
|
|
|
|
`Archiválod a(z) „${t.name}” témát? 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.`,
|
|
|
|
|
)) &&
|
|
|
|
|
act(() => api(`/forum/topics/${t.slug}`, { method: "PATCH", body: { archived: !t.archived } }))
|
|
|
|
|
}
|
|
|
|
|
>
|
|
|
|
|
{t.archived ? "Visszaállítás" : "Archiválás"}
|
|
|
|
|
</button>
|
2026-11-26 13:02:38 +00:00
|
|
|
<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>
|
|
|
|
|
)}
|
|
|
|
|
</>
|
|
|
|
|
);
|
|
|
|
|
}
|