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>