- refactored state for sessionlist, and session active and pause states

This commit is contained in:
2025-10-27 11:04:53 +00:00
parent 251a2f5e7b
commit 2d5b264041
7 changed files with 44 additions and 41 deletions

View File

@@ -9,15 +9,18 @@ import VehicleSessionItem from "../UI/VehicleSessionItem";
import { useCameraBlackboard } from "../../hooks/useCameraBlackboard";
const SessionCard = () => {
const { sessionStarted, setSessionStarted, sessionList, setSessionPaused, sessionPaused, savedSightings } =
useIntegrationsContext();
const { state, dispatch } = useIntegrationsContext();
const { mutation } = useCameraBlackboard();
const sightings = [...new Map(sessionList.map((vehicle) => [vehicle.vrm, vehicle]))];
const sessionStarted = state.sessionStarted;
const sessionPaused = state.sessionPaused;
const sessionList = state.sessionList;
const sightings = [...new Map(sessionList?.map((vehicle) => [vehicle.vrm, vehicle]))];
const dedupedSightings = sightings.map((sighting) => sighting[1]);
const vehicles = savedSightings.reduce<Record<string, ReducedSightingType[]>>(
const vehicles = dedupedSightings.reduce<Record<string, ReducedSightingType[]>>(
(acc, item) => {
const hotlisthit = Object.values(item.metadata?.hotlistMatches ?? {}).includes(true);
if (item.metadata?.npedJSON["NPED CATEGORY"] === "A") acc.npedCatA.push(item);
@@ -43,13 +46,13 @@ const SessionCard = () => {
);
const handleStartClick = () => {
setSessionStarted(!sessionStarted);
setSessionPaused(false);
dispatch({ type: "SESSIONSTART", payload: !sessionStarted });
dispatch({ type: "SESSIONPAUSE", payload: false });
toast(`${sessionStarted ? "Vehicle tracking session ended" : "Vehicle tracking session started"}`);
};
const handlepauseClick = () => {
setSessionPaused(!sessionPaused);
dispatch({ type: "SESSIONPAUSE", payload: !sessionPaused });
toast(`${sessionStarted ? "Vehicle tracking session paused" : "Vehicle tracking session resumed"}`);
};