diff --git a/src/app/(modules)/monitor/page.tsx b/src/app/(modules)/monitor/page.tsx index 681bd3f..e7999c5 100644 --- a/src/app/(modules)/monitor/page.tsx +++ b/src/app/(modules)/monitor/page.tsx @@ -235,43 +235,29 @@ export default function MonitorPage() { loading={actionLoading === "warm-cache"} onClick={triggerWarmCache} /> - { - setActionLoading("delta-test"); - addLog("info", "Pornire delta sync test pe Cluj-Napoca (54975)..."); - try { - const res = await fetch("/api/eterra/sync-background", { - method: "POST", - headers: { "Content-Type": "application/json" }, - body: JSON.stringify({ siruta: "54975", mode: "magic", includeNoGeometry: false }), - }); - const d = await res.json() as { jobId?: string; error?: string }; - if (!res.ok) { addLog("error", d.error ?? "Eroare start"); setActionLoading(""); return; } - addLog("ok", `Job pornit: ${d.jobId}`); - // Poll progress - const jid = d.jobId; - if (pollRef.current) clearInterval(pollRef.current); - pollRef.current = setInterval(async () => { - try { - const pr = await fetch(`/api/eterra/progress?jobId=${jid}`); - const pg = await pr.json() as { status?: string; phase?: string; downloaded?: number; total?: number; note?: string; message?: string }; - const pct = pg.total ? Math.round(((pg.downloaded ?? 0) / pg.total) * 100) : 0; - addLog("wait", `${pg.phase ?? "..."} (${pct}%)${pg.note ? " — " + pg.note : ""}`); - if (pg.status === "done" || pg.status === "error") { - addLog(pg.status === "done" ? "ok" : "error", pg.message ?? pg.phase ?? "Finalizat"); - if (pollRef.current) { clearInterval(pollRef.current); pollRef.current = null; } - setActionLoading(""); - } - } catch { /* continue */ } - }, 5000); - setTimeout(() => { - if (pollRef.current) { clearInterval(pollRef.current); pollRef.current = null; addLog("error", "Timeout 30min"); setActionLoading(""); } - }, 30 * 60_000); - } catch { addLog("error", "Eroare retea"); setActionLoading(""); } - }} + + {logs.length > 0 && ( @@ -366,3 +352,82 @@ function ActionButton({ label, description, loading, onClick }: { ); } + +function SyncTestButton({ label, description, siruta, mode, includeNoGeometry, actionKey, actionLoading, setActionLoading, addLog, pollRef }: { + label: string; description: string; siruta: string; mode: "base" | "magic"; + includeNoGeometry: boolean; actionKey: string; actionLoading: string; + setActionLoading: (v: string) => void; + addLog: (type: "info" | "ok" | "error" | "wait", msg: string) => void; + pollRef: React.MutableRefObject | null>; +}) { + const startTimeRef = useRef(0); + const formatElapsed = () => { + if (!startTimeRef.current) return ""; + const s = Math.round((Date.now() - startTimeRef.current) / 1000); + return s < 60 ? `${s}s` : `${Math.floor(s / 60)}m${String(s % 60).padStart(2, "0")}s`; + }; + + return ( + + ); +}