- updated NPED function to make it less expensive

This commit is contained in:
2025-10-13 16:18:59 +01:00
parent 213477640b
commit 666b90d078
2 changed files with 17 additions and 15 deletions

View File

@@ -18,7 +18,7 @@ import { useSound } from "react-sounds";
import { useNPEDContext } from "../../context/NPEDUserContext"; import { useNPEDContext } from "../../context/NPEDUserContext";
import { useSoundContext } from "../../context/SoundContext"; import { useSoundContext } from "../../context/SoundContext";
import Loading from "../UI/Loading"; import Loading from "../UI/Loading";
import { checkIsHotListHit } from "../../utils/utils"; import { checkIsHotListHit, getNPEDCategory } from "../../utils/utils";
function useNow(tickMs = 1000) { function useNow(tickMs = 1000) {
const [, setNow] = useState(() => Date.now()); const [, setNow] = useState(() => Date.now());
@@ -108,7 +108,7 @@ export default function SightingHistoryWidget({
for (const sighting of rows) { for (const sighting of rows) {
const id = sighting.vrm; const id = sighting.vrm;
console.log(processedRefs.current.has(id));
if (processedRefs.current.has(id)) continue; if (processedRefs.current.has(id)) continue;
const isHot = checkIsHotListHit(sighting); const isHot = checkIsHotListHit(sighting);
const cat = sighting?.metadata?.npedJSON?.["NPED CATEGORY"]; const cat = sighting?.metadata?.npedJSON?.["NPED CATEGORY"];
@@ -139,10 +139,10 @@ export default function SightingHistoryWidget({
useEffect(() => { useEffect(() => {
rows?.forEach((obj) => { rows?.forEach((obj) => {
const isNPEDHitA = obj?.metadata?.npedJSON?.["NPED CATEGORY"] === "A"; const cat = getNPEDCategory(obj);
const isNPEDHitB = obj?.metadata?.npedJSON?.["NPED CATEGORY"] === "B"; const isNPEDHitA = cat === "A";
const isNPEDHitC = obj?.metadata?.npedJSON?.["NPED CATEGORY"] === "C"; const isNPEDHitB = cat === "B";
const isNPEDHitC = cat === "C";
if (isNPEDHitA || isNPEDHitB || isNPEDHitC) { if (isNPEDHitA || isNPEDHitB || isNPEDHitC) {
dispatch({ dispatch({
type: "ADD", type: "ADD",
@@ -155,9 +155,10 @@ export default function SightingHistoryWidget({
useEffect(() => { useEffect(() => {
if (hasAutoOpenedRef.current || npedRef.current) return; if (hasAutoOpenedRef.current || npedRef.current) return;
const firstNPED = rows.find((r) => { const firstNPED = rows.find((r) => {
const isNPEDHitA = r?.metadata?.npedJSON?.["NPED CATEGORY"] === "A"; const cat = getNPEDCategory(r);
const isNPEDHitB = r?.metadata?.npedJSON?.["NPED CATEGORY"] === "B"; const isNPEDHitA = cat === "A";
const isNPEDHitC = r?.metadata?.npedJSON?.["NPED CATEGORY"] === "C"; const isNPEDHitB = cat === "B";
const isNPEDHitC = cat === "C";
return isNPEDHitA || isNPEDHitB || isNPEDHitC; return isNPEDHitA || isNPEDHitB || isNPEDHitC;
}); });
const firstHot = rows?.find((r) => { const firstHot = rows?.find((r) => {
@@ -202,12 +203,10 @@ export default function SightingHistoryWidget({
{/* Rows */} {/* Rows */}
<div className="flex flex-col"> <div className="flex flex-col">
{rows?.map((obj) => { {rows?.map((obj) => {
const isNPEDHitA = const cat = getNPEDCategory(obj);
obj?.metadata?.npedJSON?.["NPED CATEGORY"] === "A"; const isNPEDHitA = cat === "A";
const isNPEDHitB = const isNPEDHitB = cat === "B";
obj?.metadata?.npedJSON?.["NPED CATEGORY"] === "B"; const isNPEDHitC = cat === "C";
const isNPEDHitC =
obj?.metadata?.npedJSON?.["NPED CATEGORY"] === "C";
const motionAway = (obj?.motion ?? "").toUpperCase() === "AWAY"; const motionAway = (obj?.motion ?? "").toUpperCase() === "AWAY";
const isHotListHit = checkIsHotListHit(obj); const isHotListHit = checkIsHotListHit(obj);
return ( return (

View File

@@ -140,3 +140,6 @@ export const checkIsHotListHit = (sigthing: SightingType | null) => {
return isHotListHit; return isHotListHit;
} }
}; };
export const getNPEDCategory = (r?: SightingType) =>
r?.metadata?.npedJSON?.["NPED CATEGORY"] as "A" | "B" | "C" | undefined;