From 35386350c6122644fd163a2200f371cc30a1f845 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9my=20Rialland?= Date: Wed, 27 Sep 2023 16:08:44 +0200 Subject: [PATCH] Remove unused code --- .../components/utils/SituationContext.tsx | 58 ------------------- 1 file changed, 58 deletions(-) delete mode 100644 site/source/components/utils/SituationContext.tsx diff --git a/site/source/components/utils/SituationContext.tsx b/site/source/components/utils/SituationContext.tsx deleted file mode 100644 index 97c2c9724..000000000 --- a/site/source/components/utils/SituationContext.tsx +++ /dev/null @@ -1,58 +0,0 @@ -import Engine, { PublicodesExpression } from 'publicodes' -import { - createContext, - Dispatch, - SetStateAction, - useContext, - useRef, - useState, -} from 'react' - -import { safeSetSituation } from './EngineContext' - -export type Situation = Partial< - Record -> - -type SetSituation = Dispatch< - SetStateAction> -> - -export interface SituationState { - situation: Situation - setSituation: SetSituation -} - -/** - * Create a situation state synchronized with engine - * @param defaultSituation - * @returns situation state - */ -export const useSynchronizedSituationState = ( - engine: Engine, - defaultSituation: Situation | (() => Situation) = {} -): SituationState => { - const [localSituation, setLocalSituation] = - useState>(defaultSituation) - - const prevSituation = useRef | null>(null) - - if (prevSituation.current !== localSituation) { - prevSituation.current = localSituation - - safeSetSituation(engine, localSituation, ({ situation }) => - setLocalSituation(situation) - ) - } - - return { situation: localSituation, setSituation: setLocalSituation } -} - -export const SituationStateContext = createContext< - Partial> ->({}) - -export const SituationStateProvider = SituationStateContext.Provider - -export const useSituationState = () => - useContext(SituationStateContext) as Partial>