- 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 { 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 */}
<div className="flex flex-col">
{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 (

View File

@@ -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;