diff --git a/src/components/HistoryList/AlertItem.tsx b/src/components/HistoryList/AlertItem.tsx index 13053d6..48c12ce 100644 --- a/src/components/HistoryList/AlertItem.tsx +++ b/src/components/HistoryList/AlertItem.tsx @@ -8,6 +8,7 @@ import { useAlertHitContext } from "../../context/AlertHitContext"; import NPED_CAT_A from "/NPED_Cat_A.svg"; import NPED_CAT_B from "/NPED_Cat_B.svg"; import NPED_CAT_C from "/NPED_Cat_C.svg"; +import { checkIsHotListHit } from "../../utils/utils"; type AlertItemProps = { item: SightingType; @@ -19,9 +20,8 @@ const AlertItem = ({ item }: AlertItemProps) => { // const {d} = useCameraBlackboard(); const motionAway = (item?.motion ?? "").toUpperCase() === "AWAY"; - // [34].metadata.hotlistMatches["MAV_Hotlist.csv"] - //check if true is in any hotlist property - const isHotListHit = item?.metadata?.hotlistMatches?.Hotlist0 === true; + + const isHotListHit = checkIsHotListHit(item); const isNPEDHitA = item?.metadata?.npedJSON?.["NPED CATEGORY"] === "A"; const isNPEDHitB = item?.metadata?.npedJSON?.["NPED CATEGORY"] === "B"; const isNPEDHitC = item?.metadata?.npedJSON?.["NPED CATEGORY"] === "C"; diff --git a/src/components/SightingModal/SightingModal.tsx b/src/components/SightingModal/SightingModal.tsx index ad2b65e..aef4981 100644 --- a/src/components/SightingModal/SightingModal.tsx +++ b/src/components/SightingModal/SightingModal.tsx @@ -10,6 +10,7 @@ import HotListImg from "/Hotlist_Hit.svg"; import NPED_CAT_A from "/NPED_Cat_A.svg"; import NPED_CAT_B from "/NPED_Cat_B.svg"; import NPED_CAT_C from "/NPED_Cat_C.svg"; +import { checkIsHotListHit } from "../../utils/utils"; type SightingModalProps = { isSightingModalOpen: boolean; @@ -65,7 +66,7 @@ const SightingModal = ({ }; const motionAway = (sighting?.motion ?? "").toUpperCase() === "AWAY"; - const isHotListHit = sighting?.metadata?.hotlistMatches?.Hotlist0 === true; + const isHotListHit = checkIsHotListHit(sighting); const isNPEDHitA = sighting?.metadata?.npedJSON?.["NPED CATEGORY"] === "A"; const isNPEDHitB = sighting?.metadata?.npedJSON?.["NPED CATEGORY"] === "B"; const isNPEDHitC = sighting?.metadata?.npedJSON?.["NPED CATEGORY"] === "C"; diff --git a/src/components/SightingsWidget/InfoBar.tsx b/src/components/SightingsWidget/InfoBar.tsx index c9ff970..b19f192 100644 --- a/src/components/SightingsWidget/InfoBar.tsx +++ b/src/components/SightingsWidget/InfoBar.tsx @@ -5,7 +5,6 @@ type InfoBarprops = { obj: SightingType; }; const InfoBar = ({ obj }: InfoBarprops) => { - // const isNPEDHit = obj?.metadata?.npedJSON?.status_code === 404; const isNPEDHitD = obj?.metadata?.npedJSON?.["NPED CATEGORY"] === "D"; return ( diff --git a/src/components/SightingsWidget/SightingWidget.tsx b/src/components/SightingsWidget/SightingWidget.tsx index 754e03e..1e730f7 100644 --- a/src/components/SightingsWidget/SightingWidget.tsx +++ b/src/components/SightingsWidget/SightingWidget.tsx @@ -13,10 +13,12 @@ import NPED_CAT_A from "/NPED_Cat_A.svg"; import NPED_CAT_B from "/NPED_Cat_B.svg"; import NPED_CAT_C from "/NPED_Cat_C.svg"; import popup from "../../assets/sounds/ui/popup_open.mp3"; +import notification from "../../assets/sounds/ui/notification.mp3"; 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"; function useNow(tickMs = 1000) { const [, setNow] = useState(() => Date.now()); @@ -43,11 +45,16 @@ export default function SightingHistoryWidget({ useNow(1000); const { state } = useSoundContext(); - const soundSrc = useMemo(() => { + const soundSrcNped = useMemo(() => { return getSoundFileURL(state.NPEDsound) ?? popup; }, [state.NPEDsound]); - const { play } = useSound(soundSrc); + const soundSrcHotlist = useMemo(() => { + return getSoundFileURL(state?.hotlists?.[0]?.sound) ?? notification; + }, [state.hotlists]); + + const { play: npedSound } = useSound(soundSrcNped); + const { play: hotlistsound } = useSound(soundSrcHotlist); const { sightings, setSelectedSighting, @@ -78,6 +85,7 @@ export default function SightingHistoryWidget({ }, [mostRecent, sessionStarted, setSessionList]); const hasAutoOpenedRef = useRef(false); + const npedRef = useRef(false); const onRowClick = useCallback( (sighting: SightingType) => { @@ -106,24 +114,43 @@ export default function SightingHistoryWidget({ }); } }); - }, [dispatch, rows]); + }, [dispatch]); useEffect(() => { - if (hasAutoOpenedRef.current) return; - const firstHot = rows?.find((r) => { - const isHotListHit = r?.metadata?.hotlistMatches?.Hotlist0 === true; + 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"; - return isNPEDHitA || isNPEDHitB || isNPEDHitC || isHotListHit; + return isNPEDHitA || isNPEDHitB || isNPEDHitC; }); + const firstHot = rows?.find((r) => { + const isHotListHit = checkIsHotListHit(r); + + return isHotListHit; + }); + + if (firstNPED) { + setSelectedSighting(firstNPED); + console.log("first"); + npedSound(); + setSightingModalOpen(true); + npedRef.current = true; + } + if (firstHot) { setSelectedSighting(firstHot); - play(); + hotlistsound(); setSightingModalOpen(true); hasAutoOpenedRef.current = true; } - }, [play, rows, setSelectedSighting, setSightingModalOpen]); + }, [ + hotlistsound, + npedSound, + rows, + setSelectedSighting, + setSightingModalOpen, + ]); const handleClose = () => { setSightingModalOpen(false); @@ -152,11 +179,8 @@ export default function SightingHistoryWidget({ obj?.metadata?.npedJSON?.["NPED CATEGORY"] === "B"; const isNPEDHitC = obj?.metadata?.npedJSON?.["NPED CATEGORY"] === "C"; - const isNPEDHitD = - obj?.metadata?.npedJSON?.["NPED CATEGORY"] === "D"; const motionAway = (obj?.motion ?? "").toUpperCase() === "AWAY"; - const isHotListHit = - obj?.metadata?.hotlistMatches?.Hotlist0 === true; + const isHotListHit = checkIsHotListHit(obj); return (