- added hotlists being displayed
- functionality to delete hotlist
This commit is contained in:
@@ -2,6 +2,7 @@ import { useEffect, useReducer, type ReactNode } from "react";
|
||||
import { IntegrationsContext } from "../IntegrationsContext";
|
||||
import { useCameraBlackboard } from "../../hooks/useCameraBlackboard";
|
||||
import { initialState, reducer } from "../reducers/IntegrationsContextReducer";
|
||||
import { useHotlistData } from "../../hooks/useHotListData";
|
||||
|
||||
type IntegrationsProviderType = {
|
||||
children: ReactNode;
|
||||
@@ -10,6 +11,7 @@ type IntegrationsProviderType = {
|
||||
export const IntegrationsProvider = ({ children }: IntegrationsProviderType) => {
|
||||
const [state, dispatch] = useReducer(reducer, initialState);
|
||||
const { mutation } = useCameraBlackboard();
|
||||
const { query } = useHotlistData();
|
||||
|
||||
useEffect(() => {
|
||||
let isMounted = true;
|
||||
@@ -50,6 +52,13 @@ export const IntegrationsProvider = ({ children }: IntegrationsProviderType) =>
|
||||
};
|
||||
}, []);
|
||||
|
||||
useEffect(() => {
|
||||
const fetchHotlistData = async () => {
|
||||
dispatch({ type: "SETHOTLISTS", payload: query?.data?.hotlists });
|
||||
};
|
||||
fetchHotlistData();
|
||||
}, [query?.data]);
|
||||
|
||||
return (
|
||||
<IntegrationsContext.Provider
|
||||
value={{
|
||||
|
||||
@@ -12,6 +12,7 @@ export const initialState = {
|
||||
catC: true,
|
||||
catD: false,
|
||||
},
|
||||
hotlistFiles: [],
|
||||
};
|
||||
|
||||
export function reducer(state: NPEDSTATE, action: NPEDACTION) {
|
||||
@@ -56,6 +57,17 @@ export function reducer(state: NPEDSTATE, action: NPEDACTION) {
|
||||
...state,
|
||||
iscatEnabled: action.payload,
|
||||
};
|
||||
|
||||
case "SETHOTLISTS":
|
||||
return {
|
||||
...state,
|
||||
hotlistFiles: action.payload,
|
||||
};
|
||||
case "DELETEHOTLIST":
|
||||
return {
|
||||
...state,
|
||||
hotlistFiles: state.hotlistFiles.filter((hotlist) => hotlist.filename !== action.payload),
|
||||
};
|
||||
default:
|
||||
return { ...state };
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user