2025-10-08 11:08:41 +01:00
|
|
|
import { useEffect, useMemo, useReducer, type ReactNode } from "react";
|
2025-09-30 14:51:37 +01:00
|
|
|
import { SoundContext } from "../SoundContext";
|
2025-10-01 15:21:07 +01:00
|
|
|
import { initialState, reducer } from "../reducers/SoundContextReducer";
|
2025-10-08 11:08:41 +01:00
|
|
|
import { useCameraBlackboard } from "../../hooks/useCameraBlackboard";
|
2025-09-30 14:51:37 +01:00
|
|
|
|
|
|
|
|
type SoundContextProviderProps = {
|
|
|
|
|
children: ReactNode;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const SoundContextProvider = ({ children }: SoundContextProviderProps) => {
|
2025-10-01 15:21:07 +01:00
|
|
|
const [state, dispatch] = useReducer(reducer, initialState);
|
2025-10-08 11:08:41 +01:00
|
|
|
const { mutation } = useCameraBlackboard();
|
|
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
|
const fetchSound = async () => {
|
|
|
|
|
const result = await mutation.mutateAsync({
|
|
|
|
|
operation: "VIEW",
|
|
|
|
|
path: "soundSettings",
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
dispatch({ type: "UPDATE", payload: result.result });
|
|
|
|
|
};
|
|
|
|
|
fetchSound();
|
|
|
|
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
|
|
|
}, []);
|
2025-10-01 15:21:07 +01:00
|
|
|
const value = useMemo(() => ({ state, dispatch }), [state, dispatch]);
|
2025-09-30 14:51:37 +01:00
|
|
|
return (
|
2025-10-01 15:21:07 +01:00
|
|
|
<SoundContext.Provider value={value}>{children}</SoundContext.Provider>
|
2025-09-30 14:51:37 +01:00
|
|
|
);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export default SoundContextProvider;
|