fix: auto-scan race condition for no-geometry scan

- handleNoGeomScan accepts optional targetSiruta parameter
- useRef tracks last auto-scanned siruta to prevent duplicate scans
- Show zero result on error instead of hiding card (null)
- Fixes: FELEACU scan disappearing after 2s while COSBUC worked
This commit is contained in:
AI Assistant
2026-03-07 16:35:26 +02:00
parent 5861e06ddb
commit ddde2db900
@@ -679,15 +679,18 @@ export function ParcelSyncModule() {
/* No-geometry scan */ /* No-geometry scan */
/* ════════════════════════════════════════════════════════════ */ /* ════════════════════════════════════════════════════════════ */
const handleNoGeomScan = useCallback(async () => { const handleNoGeomScan = useCallback(
if (!siruta || noGeomScanning) return; async (targetSiruta?: string) => {
const s = targetSiruta ?? siruta;
if (!s) return;
setNoGeomScanning(true); setNoGeomScanning(true);
setNoGeomScan(null); setNoGeomScan(null);
setNoGeomScanSiruta(s);
try { try {
const res = await fetch("/api/eterra/no-geom-scan", { const res = await fetch("/api/eterra/no-geom-scan", {
method: "POST", method: "POST",
headers: { "Content-Type": "application/json" }, headers: { "Content-Type": "application/json" },
body: JSON.stringify({ siruta }), body: JSON.stringify({ siruta: s }),
}); });
const data = (await res.json()) as { const data = (await res.json()) as {
totalImmovables?: number; totalImmovables?: number;
@@ -696,29 +699,33 @@ export function ParcelSyncModule() {
error?: string; error?: string;
}; };
if (data.error) { if (data.error) {
setNoGeomScan(null); // Show zero result instead of hiding the card entirely
setNoGeomScan({ totalImmovables: 0, totalInDb: 0, noGeomCount: 0 });
} else { } else {
setNoGeomScan({ setNoGeomScan({
totalImmovables: data.totalImmovables ?? 0, totalImmovables: data.totalImmovables ?? 0,
totalInDb: data.totalInDb ?? 0, totalInDb: data.totalInDb ?? 0,
noGeomCount: data.noGeomCount ?? 0, noGeomCount: data.noGeomCount ?? 0,
}); });
setNoGeomScanSiruta(siruta);
} }
} catch { } catch {
setNoGeomScan(null); // Show zero result on network error
setNoGeomScan({ totalImmovables: 0, totalInDb: 0, noGeomCount: 0 });
} }
setNoGeomScanning(false); setNoGeomScanning(false);
}, [siruta, noGeomScanning]); },
[siruta],
);
// Auto-scan for no-geometry parcels when UAT is selected + connected // Auto-scan for no-geometry parcels when UAT is selected + connected
const noGeomAutoScanRef = useRef("");
useEffect(() => { useEffect(() => {
if (!siruta || !session.connected || noGeomScanning) return; if (!siruta || !session.connected) return;
// Don't re-scan if we already scanned this siruta // Don't re-scan if we already scanned (or are scanning) this siruta
if (noGeomScanSiruta === siruta && noGeomScan !== null) return; if (noGeomAutoScanRef.current === siruta) return;
void handleNoGeomScan(); noGeomAutoScanRef.current = siruta;
// eslint-disable-next-line react-hooks/exhaustive-deps void handleNoGeomScan(siruta);
}, [siruta, session.connected]); }, [siruta, session.connected, handleNoGeomScan]);
/* ════════════════════════════════════════════════════════════ */ /* ════════════════════════════════════════════════════════════ */
/* Layer feature counts */ /* Layer feature counts */