Files
sorsfonalak/services/frontend/src/app/admin/hibak/ErrorLog.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

239 lines
7.7 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
"use client";
import { useCallback, useEffect, useState } from "react";
import { api, errorText } from "@/lib/api";
import { formatDate } from "@/lib/astro";
import type { GenerationError } from "@/lib/types";
import { confirmDialog } from "@/components/Dialogs";
const PAGE = 50;
const SOURCES: Record<string, string> = { analysis: "Elemzés", question: "Kérdés-válasz", preview: "Prompt-próba" };
const KINDS: Record<string, string> = {
summary: "összefoglaló",
natal: "képletelemzés",
synastry: "kapcsolati",
forecast: "előrejelzés",
celebrity: "híres ember",
question: "válasz",
};
const OUTCOMES: Record<GenerationError["outcome"], { label: string; tone: string }> = {
retry: { label: "újrapróbálva", tone: "neutral" },
fallback: { label: "tartalék modell vette át", tone: "neutral" },
failed: { label: "végleg sikertelen", tone: "tense" },
};
interface Page {
errors: GenerationError[];
total: number;
last_day: number;
}
/** The admin error log with filters and paging. */
export function ErrorLog() {
const [source, setSource] = useState("");
const [outcome, setOutcome] = useState("");
const [page, setPage] = useState(0);
const [errors, setErrors] = useState<GenerationError[] | null>(null);
const [total, setTotal] = useState(0);
const [lastDay, setLastDay] = useState(0);
const [busy, setBusy] = useState(false);
const [error, setError] = useState<string | null>(null);
const filter = useCallback(() => {
const params = new URLSearchParams();
if (source) params.set("source", source);
if (outcome) params.set("outcome", outcome);
return params;
}, [source, outcome]);
const load = useCallback(async () => {
setBusy(true);
setError(null);
const params = filter();
params.set("limit", String(PAGE));
params.set("offset", String(page * PAGE));
try {
const res = await api<Page>(`/admin/errors?${params}`);
// The last page emptied by deleting: one page back.
if (res.errors.length === 0 && page > 0) return setPage(Math.max(0, Math.ceil(res.total / PAGE) - 1));
setErrors(res.errors);
setTotal(res.total);
setLastDay(res.last_day);
} catch (e) {
setError(errorText(e));
} finally {
setBusy(false);
}
}, [filter, page]);
useEffect(() => {
load();
}, [load]);
async function removeOne(id: number) {
setError(null);
try {
await api(`/admin/errors/${id}`, { method: "DELETE" });
await load();
} catch (e) {
setError(errorText(e));
}
}
async function removeMatching() {
const what = source || outcome ? `a szűrésnek megfelelő ${total} bejegyzést` : `mind a ${total} bejegyzést`;
const ok = await confirmDialog({
title: `Törlöd ${what}?`,
text: "Nem vonható vissza.",
confirm: "Törlés",
danger: true,
});
if (!ok) return;
setBusy(true);
setError(null);
try {
await api(`/admin/errors?${filter()}`, { method: "DELETE" });
setPage(0);
await load();
} catch (e) {
setError(errorText(e));
} finally {
setBusy(false);
}
}
const pages = Math.max(1, Math.ceil(total / PAGE));
return (
<section className="card" style={{ gap: 12 }}>
<div className="row" style={{ gap: 12, flexWrap: "wrap", alignItems: "flex-end" }}>
<div className="field">
<label htmlFor="error-source">Mi</label>
<select id="error-source" className="inp" value={source} onChange={(e) => {
setSource(e.target.value);
setPage(0);
}}
>
<option value="">mind</option>
{Object.entries(SOURCES).map(([v, l]) => (
<option key={v} value={v}>
{l}
</option>
))}
</select>
</div>
<div className="field">
<label htmlFor="error-outcome">Következmény</label>
<select id="error-outcome" className="inp" value={outcome} onChange={(e) => {
setOutcome(e.target.value);
setPage(0);
}}
>
<option value="">mind</option>
{Object.entries(OUTCOMES).map(([v, o]) => (
<option key={v} value={v}>
{o.label}
</option>
))}
</select>
</div>
<p className="hint" style={{ margin: 0 }}>
{total} bejegyzés, ebből {lastDay} az elmúlt 24 órában
</p>
<button type="button" className="btn btn-sm btn-ghost" onClick={load} disabled={busy}>
Frissítés
</button>
{total > 0 && (
<button type="button" className="btn btn-sm btn-danger" onClick={removeMatching} disabled={busy}>
{source || outcome ? `A szűrt ${total} törlése` : `Mind a ${total} törlése`}
</button>
)}
</div>
{error && (
<p className="msg msg-error" role="alert">
{error}
</p>
)}
{errors === null ? (
<p className="muted">Betöltés…</p>
) : errors.length === 0 ? (
<p className="muted">Nincs hiba. 🎉</p>
) : (
<div className="table-wrap">
<table className="error-log">
<thead>
<tr>
<th>Időpont</th>
<th>Mi</th>
<th>Modell</th>
<th>Kísérlet</th>
<th>Következmény</th>
<th>Hiba</th>
<th>
<span className="sr-only">Törlés</span>
</th>
</tr>
</thead>
<tbody>
{errors.map((e) => (
<tr key={e.id}>
<td className="num">{formatDate(e.created_at, true)}</td>
<td>
{SOURCES[e.source] ?? e.source}
{e.source !== "question" && ` (${KINDS[e.kind] ?? e.kind})`}
{e.user && <span className="hint">{e.user}</span>}
<code className="hint" title={e.item_id}>
{e.item_id.slice(0, 8)}
</code>
</td>
<td>
<code>{e.model}</code>
</td>
<td className="num">
{e.attempt}.{e.seconds !== null && <span className="hint">{e.seconds} mp</span>}
</td>
<td>
<span className={`outcome tone-${OUTCOMES[e.outcome].tone}`}>{OUTCOMES[e.outcome].label}</span>
</td>
<td className="error-text">{e.error}</td>
<td>
<button
type="button"
className="btn btn-sm btn-ghost"
onClick={() => removeOne(e.id)}
aria-label="Bejegyzés törlése"
title="Bejegyzés törlése"
>
✕
</button>
</td>
</tr>
))}
</tbody>
</table>
</div>
)}
{total > PAGE && (
<nav className="pager" aria-label="Lapozás">
<button type="button" className="btn btn-sm" disabled={busy || page === 0} onClick={() => setPage(page - 1)}>
‹ Újabbak
</button>
<span className="num">
{page * PAGE + 1}–{Math.min(total, (page + 1) * PAGE)} / {total} · {page + 1}/{pages}. oldal
</span>
<button
type="button"
className="btn btn-sm"
disabled={busy || page + 1 >= pages}
onClick={() => setPage(page + 1)}
>
Régebbiek ›
</button>
</nav>
)}
</section>
);
}