update camera base URL, enhance alert context, and improve history list functionality
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
import { useReducer, type ReactNode } from "react";
|
||||
import { useEffect, useReducer, type ReactNode } from "react";
|
||||
import AlertHitContext from "../AlertHitContext";
|
||||
import { reducer, initalState } from "../reducers/AlertReducers";
|
||||
import { useCameraBlackboard } from "../../hooks/useCameraBlackboard";
|
||||
import type { SightingType } from "../../types/types";
|
||||
|
||||
type AlertHitProviderTypeProps = {
|
||||
children: ReactNode;
|
||||
@@ -8,9 +10,30 @@ type AlertHitProviderTypeProps = {
|
||||
|
||||
export const AlertHitProvider = ({ children }: AlertHitProviderTypeProps) => {
|
||||
const [state, dispatch] = useReducer(reducer, initalState);
|
||||
const { query } = useCameraBlackboard();
|
||||
|
||||
useEffect(() => {
|
||||
if (query.data) {
|
||||
query?.data?.alertHistory?.forEach((element: SightingType) => {
|
||||
dispatch({ type: "ADD", payload: element });
|
||||
});
|
||||
} else if (query.error) {
|
||||
console.error("Error fetching alert hits:", query.error);
|
||||
} else {
|
||||
console.log("Loading alert hits...");
|
||||
}
|
||||
}, [query.data, query.error, query.isLoading]);
|
||||
|
||||
return (
|
||||
<AlertHitContext.Provider value={{ state, dispatch }}>
|
||||
<AlertHitContext.Provider
|
||||
value={{
|
||||
state,
|
||||
dispatch,
|
||||
isLoading: query.isLoading,
|
||||
isError: query.isError,
|
||||
error: query.error,
|
||||
}}
|
||||
>
|
||||
{children}
|
||||
</AlertHitContext.Provider>
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user