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,46 +679,53 @@ export function ParcelSyncModule() {
/* No-geometry scan */ /* No-geometry scan */
/* ════════════════════════════════════════════════════════════ */ /* ════════════════════════════════════════════════════════════ */
const handleNoGeomScan = useCallback(async () => { const handleNoGeomScan = useCallback(
if (!siruta || noGeomScanning) return; async (targetSiruta?: string) => {
setNoGeomScanning(true); const s = targetSiruta ?? siruta;
setNoGeomScan(null); if (!s) return;
try { setNoGeomScanning(true);
const res = await fetch("/api/eterra/no-geom-scan", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ siruta }),
});
const data = (await res.json()) as {
totalImmovables?: number;
totalInDb?: number;
noGeomCount?: number;
error?: string;
};
if (data.error) {
setNoGeomScan(null);
} else {
setNoGeomScan({
totalImmovables: data.totalImmovables ?? 0,
totalInDb: data.totalInDb ?? 0,
noGeomCount: data.noGeomCount ?? 0,
});
setNoGeomScanSiruta(siruta);
}
} catch {
setNoGeomScan(null); setNoGeomScan(null);
} setNoGeomScanSiruta(s);
setNoGeomScanning(false); try {
}, [siruta, noGeomScanning]); const res = await fetch("/api/eterra/no-geom-scan", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ siruta: s }),
});
const data = (await res.json()) as {
totalImmovables?: number;
totalInDb?: number;
noGeomCount?: number;
error?: string;
};
if (data.error) {
// Show zero result instead of hiding the card entirely
setNoGeomScan({ totalImmovables: 0, totalInDb: 0, noGeomCount: 0 });
} else {
setNoGeomScan({
totalImmovables: data.totalImmovables ?? 0,
totalInDb: data.totalInDb ?? 0,
noGeomCount: data.noGeomCount ?? 0,
});
}
} catch {
// Show zero result on network error
setNoGeomScan({ totalImmovables: 0, totalInDb: 0, noGeomCount: 0 });
}
setNoGeomScanning(false);
},
[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 */