- 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 { dispatch } = useAlertHitContext();
|
||||||
const { sessionStarted, setSessionList, sessionList } = useNPEDContext();
|
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 => {
|
const reduceObject = (obj: SightingType): ReducedSightingType => {
|
||||||
return {
|
return {
|
||||||
vrm: obj.vrm,
|
vrm: obj.vrm,
|
||||||
@@ -84,9 +89,6 @@ export default function SightingHistoryWidget({
|
|||||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||||
}, [mostRecent, sessionStarted, setSessionList]);
|
}, [mostRecent, sessionStarted, setSessionList]);
|
||||||
|
|
||||||
const hasAutoOpenedRef = useRef(false);
|
|
||||||
const npedRef = useRef(false);
|
|
||||||
|
|
||||||
const onRowClick = useCallback(
|
const onRowClick = useCallback(
|
||||||
(sighting: SightingType) => {
|
(sighting: SightingType) => {
|
||||||
if (!sighting) return;
|
if (!sighting) return;
|
||||||
@@ -101,6 +103,40 @@ export default function SightingHistoryWidget({
|
|||||||
[sightings]
|
[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(() => {
|
useEffect(() => {
|
||||||
rows?.forEach((obj) => {
|
rows?.forEach((obj) => {
|
||||||
const isNPEDHitA = obj?.metadata?.npedJSON?.["NPED CATEGORY"] === "A";
|
const isNPEDHitA = obj?.metadata?.npedJSON?.["NPED CATEGORY"] === "A";
|
||||||
@@ -132,7 +168,6 @@ export default function SightingHistoryWidget({
|
|||||||
|
|
||||||
if (firstNPED) {
|
if (firstNPED) {
|
||||||
setSelectedSighting(firstNPED);
|
setSelectedSighting(firstNPED);
|
||||||
console.log("first");
|
|
||||||
npedSound();
|
npedSound();
|
||||||
setSightingModalOpen(true);
|
setSightingModalOpen(true);
|
||||||
npedRef.current = true;
|
npedRef.current = true;
|
||||||
@@ -144,13 +179,7 @@ export default function SightingHistoryWidget({
|
|||||||
setSightingModalOpen(true);
|
setSightingModalOpen(true);
|
||||||
hasAutoOpenedRef.current = true;
|
hasAutoOpenedRef.current = true;
|
||||||
}
|
}
|
||||||
}, [
|
}, [hotlistsound, npedSound, setSelectedSighting]);
|
||||||
hotlistsound,
|
|
||||||
npedSound,
|
|
||||||
rows,
|
|
||||||
setSelectedSighting,
|
|
||||||
setSightingModalOpen,
|
|
||||||
]);
|
|
||||||
|
|
||||||
const handleClose = () => {
|
const handleClose = () => {
|
||||||
setSightingModalOpen(false);
|
setSightingModalOpen(false);
|
||||||
|
|||||||
Reference in New Issue
Block a user