Files
Mav-Mobile-UI/src/context/providers/IntegrationsContextProvider.tsx

50 lines
1.5 KiB
TypeScript
Raw Normal View History

import { useEffect, useReducer, useState, type ReactNode } from "react";
2025-10-27 09:35:59 +00:00
import type { DedupedSightings, ReducedSightingType } from "../../types/types";
import { IntegrationsContext } from "../IntegrationsContext";
import { useCameraBlackboard } from "../../hooks/useCameraBlackboard";
2025-10-27 09:35:59 +00:00
import { initialState, reducer } from "../reducers/IntegrationsContextReducer";
2025-08-29 10:07:59 +01:00
2025-10-27 09:35:59 +00:00
type IntegrationsProviderType = {
2025-08-29 10:07:59 +01:00
children: ReactNode;
};
2025-10-27 09:35:59 +00:00
export const IntegrationsProvider = ({ children }: IntegrationsProviderType) => {
const [state, dispatch] = useReducer(reducer, initialState);
const { mutation } = useCameraBlackboard();
const [sessionStarted, setSessionStarted] = useState(false);
const [sessionList, setSessionList] = useState<ReducedSightingType[]>([]);
const [sessionPaused, setSessionPaused] = useState(false);
const [savedSightings, setSavedSightings] = useState<DedupedSightings | []>([]);
2025-08-29 10:07:59 +01:00
useEffect(() => {
const fetchData = async () => {
const result = await mutation.mutateAsync({
operation: "VIEW",
path: "sessionStats",
});
if (!result.result) return;
setSavedSightings(result?.result);
};
fetchData();
}, []);
2025-10-27 09:35:59 +00:00
2025-08-29 10:07:59 +01:00
return (
2025-10-27 09:35:59 +00:00
<IntegrationsContext.Provider
value={{
setSessionStarted,
sessionStarted,
sessionList,
setSessionList,
sessionPaused,
setSessionPaused,
savedSightings,
setSavedSightings,
2025-10-27 09:35:59 +00:00
state,
dispatch,
}}
>
2025-08-29 10:07:59 +01:00
{children}
2025-10-27 09:35:59 +00:00
</IntegrationsContext.Provider>
2025-08-29 10:07:59 +01:00
);
};