"use client"; import { useI18n } from "@/components/I18nProvider"; import { useEffect, useRef, useState } from "react"; import { api } from "@/lib/client-api"; import { refreshCapture, type MapCapture } from "@/shared/map-refresh"; import type { ProcessingJob } from "@/shared/processing-progress"; export function MapRefresh({ id, disabled, onQueued, refreshKey, job, }: { id: string; disabled: boolean; onQueued: () => void; refreshKey: number; job: ProcessingJob | null; }) { const { t, formatDate } = useI18n(); const [sources, setSources] = useState([]); const [source, setSource] = useState(""); const choice = useRef<{ mapId: string; sourceId: string } | null>(null); const [busy, setBusy] = useState(false); const [error, setError] = useState(""); useEffect(() => { let active = true; api<{ sources: typeof sources }>(`datasets/${id}/refresh-map`) .then((r) => { if (active) { setSources(r.sources); setSource( refreshCapture( r.sources, choice.current?.mapId === id ? choice.current.sourceId : undefined, ), ); setError(""); } }) .catch((e) => { if (active) setError(e.message); }); return () => { active = false; }; }, [id, refreshKey, job?.id, job?.state]); async function refresh() { setBusy(true); setError(""); try { await api(`datasets/${id}/refresh-map`, { sourceId: source }); onQueued(); } catch (e) { setError((e as Error).message); } finally { setBusy(false); } } return (
{t("THE MAP PLAYERS GUESS ON")}

{t("Refresh guessing map")}

{t( "Rebuild the overhead map from a processed capture. To show new buildings, export the same area again and upload it first. Select that capture here; its boundaries must match this map exactly.", )}

{t( "The newest eligible capture is selected automatically. Choose the original capture only if you want its older terrain.", )}

{t( "Panoramas stay unchanged. Refreshing uses no panorama slots, even at 24/24. Submit the finished map update for review to make it playable.", )}

{job?.kind === "map" && job.state === "complete" && (

{t("Last successful refresh used: {capture}.", { capture: job.source_dataset_id === id ? t("Original capture") : `${sources.find((s) => s.id === job.source_dataset_id)?.name ?? t("Terrain capture")} · ${job.source_dataset_id?.slice(0, 8) ?? ""}`, })}

)} {error && (

{t(error)}

)}
); }