2025-10-27 08:28:44 +00:00
|
|
|
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";
|
2025-10-27 08:28:44 +00:00
|
|
|
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) => {
|
2025-10-27 08:28:44 +00:00
|
|
|
const [state, dispatch] = useReducer(reducer, initialState);
|
|
|
|
|
const { mutation } = useCameraBlackboard();
|
2025-09-25 10:38:49 +01:00
|
|
|
const [sessionStarted, setSessionStarted] = useState(false);
|
2025-10-08 15:46:54 +01:00
|
|
|
const [sessionList, setSessionList] = useState<ReducedSightingType[]>([]);
|
2025-10-24 12:10:10 +01:00
|
|
|
const [sessionPaused, setSessionPaused] = useState(false);
|
2025-10-27 08:28:44 +00:00
|
|
|
const [savedSightings, setSavedSightings] = useState<DedupedSightings | []>([]);
|
2025-08-29 10:07:59 +01:00
|
|
|
|
2025-10-27 08:28:44 +00: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
|
2025-09-25 10:38:49 +01:00
|
|
|
value={{
|
|
|
|
|
setSessionStarted,
|
|
|
|
|
sessionStarted,
|
|
|
|
|
sessionList,
|
|
|
|
|
setSessionList,
|
2025-10-24 12:10:10 +01:00
|
|
|
sessionPaused,
|
|
|
|
|
setSessionPaused,
|
2025-10-27 08:28:44 +00:00
|
|
|
savedSightings,
|
|
|
|
|
setSavedSightings,
|
2025-10-27 09:35:59 +00:00
|
|
|
state,
|
|
|
|
|
dispatch,
|
2025-09-25 10:38:49 +01:00
|
|
|
}}
|
|
|
|
|
>
|
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
|
|
|
);
|
|
|
|
|
};
|