- refactored state for sessionlist, and session active and pause states
This commit is contained in:
@@ -1,5 +1,4 @@
|
||||
import { useEffect, useReducer, useState, type ReactNode } from "react";
|
||||
import type { DedupedSightings, ReducedSightingType } from "../../types/types";
|
||||
import { useEffect, useReducer, type ReactNode } from "react";
|
||||
import { IntegrationsContext } from "../IntegrationsContext";
|
||||
import { useCameraBlackboard } from "../../hooks/useCameraBlackboard";
|
||||
import { initialState, reducer } from "../reducers/IntegrationsContextReducer";
|
||||
@@ -11,10 +10,6 @@ type IntegrationsProviderType = {
|
||||
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 | []>([]);
|
||||
|
||||
useEffect(() => {
|
||||
const fetchData = async () => {
|
||||
@@ -22,23 +17,15 @@ export const IntegrationsProvider = ({ children }: IntegrationsProviderType) =>
|
||||
operation: "VIEW",
|
||||
path: "sessionStats",
|
||||
});
|
||||
if (!result.result) return;
|
||||
setSavedSightings(result?.result);
|
||||
if (!result.result || typeof result.result === "string") return;
|
||||
|
||||
dispatch({ type: "UPDATE", payload: result?.result });
|
||||
};
|
||||
fetchData();
|
||||
}, []);
|
||||
|
||||
return (
|
||||
<IntegrationsContext.Provider
|
||||
value={{
|
||||
setSessionStarted,
|
||||
sessionStarted,
|
||||
sessionList,
|
||||
setSessionList,
|
||||
sessionPaused,
|
||||
setSessionPaused,
|
||||
savedSightings,
|
||||
setSavedSightings,
|
||||
state,
|
||||
dispatch,
|
||||
}}
|
||||
|
||||
Reference in New Issue
Block a user