diff --git a/src/components/SightingsWidget/SightingWidget.tsx b/src/components/SightingsWidget/SightingWidget.tsx index 240ae39..731166d 100644 --- a/src/components/SightingsWidget/SightingWidget.tsx +++ b/src/components/SightingsWidget/SightingWidget.tsx @@ -18,7 +18,7 @@ import { useSound } from "react-sounds"; import { useNPEDContext } from "../../context/NPEDUserContext"; import { useSoundContext } from "../../context/SoundContext"; import Loading from "../UI/Loading"; -import { checkIsHotListHit } from "../../utils/utils"; +import { checkIsHotListHit, getNPEDCategory } from "../../utils/utils"; function useNow(tickMs = 1000) { const [, setNow] = useState(() => Date.now()); @@ -108,7 +108,7 @@ export default function SightingHistoryWidget({ 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"]; @@ -139,10 +139,10 @@ export default function SightingHistoryWidget({ useEffect(() => { rows?.forEach((obj) => { - const isNPEDHitA = obj?.metadata?.npedJSON?.["NPED CATEGORY"] === "A"; - const isNPEDHitB = obj?.metadata?.npedJSON?.["NPED CATEGORY"] === "B"; - const isNPEDHitC = obj?.metadata?.npedJSON?.["NPED CATEGORY"] === "C"; - + const cat = getNPEDCategory(obj); + const isNPEDHitA = cat === "A"; + const isNPEDHitB = cat === "B"; + const isNPEDHitC = cat === "C"; if (isNPEDHitA || isNPEDHitB || isNPEDHitC) { dispatch({ type: "ADD", @@ -155,9 +155,10 @@ export default function SightingHistoryWidget({ useEffect(() => { if (hasAutoOpenedRef.current || npedRef.current) return; const firstNPED = rows.find((r) => { - const isNPEDHitA = r?.metadata?.npedJSON?.["NPED CATEGORY"] === "A"; - const isNPEDHitB = r?.metadata?.npedJSON?.["NPED CATEGORY"] === "B"; - const isNPEDHitC = r?.metadata?.npedJSON?.["NPED CATEGORY"] === "C"; + const cat = getNPEDCategory(r); + const isNPEDHitA = cat === "A"; + const isNPEDHitB = cat === "B"; + const isNPEDHitC = cat === "C"; return isNPEDHitA || isNPEDHitB || isNPEDHitC; }); const firstHot = rows?.find((r) => { @@ -202,12 +203,10 @@ export default function SightingHistoryWidget({ {/* Rows */}
{rows?.map((obj) => { - const isNPEDHitA = - obj?.metadata?.npedJSON?.["NPED CATEGORY"] === "A"; - const isNPEDHitB = - obj?.metadata?.npedJSON?.["NPED CATEGORY"] === "B"; - const isNPEDHitC = - obj?.metadata?.npedJSON?.["NPED CATEGORY"] === "C"; + const cat = getNPEDCategory(obj); + const isNPEDHitA = cat === "A"; + const isNPEDHitB = cat === "B"; + const isNPEDHitC = cat === "C"; const motionAway = (obj?.motion ?? "").toUpperCase() === "AWAY"; const isHotListHit = checkIsHotListHit(obj); return ( diff --git a/src/utils/utils.ts b/src/utils/utils.ts index 8394450..f016291 100644 --- a/src/utils/utils.ts +++ b/src/utils/utils.ts @@ -140,3 +140,6 @@ export const checkIsHotListHit = (sigthing: SightingType | null) => { return isHotListHit; } }; + +export const getNPEDCategory = (r?: SightingType) => + r?.metadata?.npedJSON?.["NPED CATEGORY"] as "A" | "B" | "C" | undefined;