From 7121809a9ef7bb4065394f2ddc56f2fcce1bace5 Mon Sep 17 00:00:00 2001 From: Toba Ojo Date: Tue, 14 Oct 2025 08:50:06 +0100 Subject: [PATCH] - refactored fetching NPED Category --- src/components/HistoryList/AlertItem.tsx | 9 +++++---- src/components/SightingModal/SightingModal.tsx | 9 +++++---- src/components/SightingsWidget/InfoBar.tsx | 10 +--------- src/utils/utils.ts | 2 +- 4 files changed, 12 insertions(+), 18 deletions(-) diff --git a/src/components/HistoryList/AlertItem.tsx b/src/components/HistoryList/AlertItem.tsx index ccae950..cc75e13 100644 --- a/src/components/HistoryList/AlertItem.tsx +++ b/src/components/HistoryList/AlertItem.tsx @@ -9,7 +9,7 @@ import { useCameraBlackboard } from "../../hooks/useCameraBlackboard"; 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"; +import { checkIsHotListHit, getNPEDCategory } from "../../utils/utils"; type AlertItemProps = { item: SightingType; @@ -24,9 +24,10 @@ const AlertItem = ({ item }: AlertItemProps) => { const motionAway = (item?.motion ?? "").toUpperCase() === "AWAY"; 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"; + const cat = getNPEDCategory(item); + const isNPEDHitA = cat === "A"; + const isNPEDHitB = cat === "B"; + const isNPEDHitC = cat === "C"; const handleClick = () => { setIsModalOpen(true); diff --git a/src/components/SightingModal/SightingModal.tsx b/src/components/SightingModal/SightingModal.tsx index a9fa5b7..81d1c3f 100644 --- a/src/components/SightingModal/SightingModal.tsx +++ b/src/components/SightingModal/SightingModal.tsx @@ -10,7 +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"; +import { checkIsHotListHit, getNPEDCategory } from "../../utils/utils"; type SightingModalProps = { isSightingModalOpen: boolean; @@ -68,9 +68,10 @@ const SightingModal = ({ const motionAway = (sighting?.motion ?? "").toUpperCase() === "AWAY"; 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"; + const cat = getNPEDCategory(sighting); + const isNPEDHitA = cat === "A"; + const isNPEDHitB = cat === "B"; + const isNPEDHitC = cat === "C"; return ( <> diff --git a/src/components/SightingsWidget/InfoBar.tsx b/src/components/SightingsWidget/InfoBar.tsx index b19f192..d40e998 100644 --- a/src/components/SightingsWidget/InfoBar.tsx +++ b/src/components/SightingsWidget/InfoBar.tsx @@ -5,8 +5,6 @@ type InfoBarprops = { obj: SightingType; }; const InfoBar = ({ obj }: InfoBarprops) => { - const isNPEDHitD = obj?.metadata?.npedJSON?.["NPED CATEGORY"] === "D"; - return (
@@ -18,13 +16,7 @@ const InfoBar = ({ obj }: InfoBarprops) => {
-
- {isNPEDHitD ? ( - NPED HIT CAT D - ) : ( - "" - )} -
+
); }; diff --git a/src/utils/utils.ts b/src/utils/utils.ts index f016291..4e031ec 100644 --- a/src/utils/utils.ts +++ b/src/utils/utils.ts @@ -141,5 +141,5 @@ export const checkIsHotListHit = (sigthing: SightingType | null) => { } }; -export const getNPEDCategory = (r?: SightingType) => +export const getNPEDCategory = (r?: SightingType | null) => r?.metadata?.npedJSON?.["NPED CATEGORY"] as "A" | "B" | "C" | undefined;