- bugfix: fixed notification and modal for multiple hotlist hits
This commit is contained in:
@@ -68,6 +68,11 @@ export default function SightingHistoryWidget({
|
||||
const { dispatch } = useAlertHitContext();
|
||||
const { sessionStarted, setSessionList, sessionList } = useNPEDContext();
|
||||
|
||||
const processedRefs = useRef<Set<number | string>>(new Set());
|
||||
|
||||
const hasAutoOpenedRef = useRef(false);
|
||||
const npedRef = useRef(false);
|
||||
|
||||
const reduceObject = (obj: SightingType): ReducedSightingType => {
|
||||
return {
|
||||
vrm: obj.vrm,
|
||||
@@ -84,9 +89,6 @@ export default function SightingHistoryWidget({
|
||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||
}, [mostRecent, sessionStarted, setSessionList]);
|
||||
|
||||
const hasAutoOpenedRef = useRef(false);
|
||||
const npedRef = useRef(false);
|
||||
|
||||
const onRowClick = useCallback(
|
||||
(sighting: SightingType) => {
|
||||
if (!sighting) return;
|
||||
@@ -101,6 +103,40 @@ export default function SightingHistoryWidget({
|
||||
[sightings]
|
||||
);
|
||||
|
||||
useEffect(() => {
|
||||
if (!rows?.length) return;
|
||||
|
||||
for (const sighting of rows) {
|
||||
const id = sighting.vrm;
|
||||
console.log(processedRefs.current.has(id));
|
||||
if (processedRefs.current.has(id)) continue;
|
||||
const isHot = checkIsHotListHit(sighting);
|
||||
const cat = sighting?.metadata?.npedJSON?.["NPED CATEGORY"];
|
||||
|
||||
if (cat === "A" || cat === "B" || cat === "C") {
|
||||
npedSound();
|
||||
setSelectedSighting(sighting);
|
||||
setSightingModalOpen(true);
|
||||
processedRefs.current.add(id);
|
||||
break; // stop after one new open per render cycle
|
||||
}
|
||||
|
||||
if (isHot) {
|
||||
hotlistsound();
|
||||
setSelectedSighting(sighting);
|
||||
setSightingModalOpen(true);
|
||||
processedRefs.current.add(id);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}, [
|
||||
rows,
|
||||
hotlistsound,
|
||||
npedSound,
|
||||
setSightingModalOpen,
|
||||
setSelectedSighting,
|
||||
]);
|
||||
|
||||
useEffect(() => {
|
||||
rows?.forEach((obj) => {
|
||||
const isNPEDHitA = obj?.metadata?.npedJSON?.["NPED CATEGORY"] === "A";
|
||||
@@ -132,7 +168,6 @@ export default function SightingHistoryWidget({
|
||||
|
||||
if (firstNPED) {
|
||||
setSelectedSighting(firstNPED);
|
||||
console.log("first");
|
||||
npedSound();
|
||||
setSightingModalOpen(true);
|
||||
npedRef.current = true;
|
||||
@@ -144,13 +179,7 @@ export default function SightingHistoryWidget({
|
||||
setSightingModalOpen(true);
|
||||
hasAutoOpenedRef.current = true;
|
||||
}
|
||||
}, [
|
||||
hotlistsound,
|
||||
npedSound,
|
||||
rows,
|
||||
setSelectedSighting,
|
||||
setSightingModalOpen,
|
||||
]);
|
||||
}, [hotlistsound, npedSound, setSelectedSighting]);
|
||||
|
||||
const handleClose = () => {
|
||||
setSightingModalOpen(false);
|
||||
|
||||
Reference in New Issue
Block a user