Spaces:
Sleeping
Sleeping
Download src/context/AppContext.tsx from Samfredoly/jor: direct link, hf CLI and curl.
- Browser
- Download file 2.5 kB
-
https://huggingface.co/spaces/Samfredoly/jor/resolve/main/src/context/AppContext.tsx
- Command line
-
hf download hf://spaces/Samfredoly/jor/src/context/AppContext.tsx
-
curl -L -o AppContext.tsx https://huggingface.co/spaces/Samfredoly/jor/resolve/main/src/context/AppContext.tsx
2.5 kB
| import { useCallback, useMemo, useState, type ReactNode } from 'react' | |
| import { AppContext, type InvestigationIntent, type ProjectionInputs } from './context' | |
| import type { RunSetRecord, ScreenName } from '../types' | |
| export function AppProvider({ children }: { children: ReactNode }) { | |
| const [activeScreen, setActiveScreen] = useState<ScreenName>('Dashboard') | |
| const [toast, setToast] = useState('') | |
| const [investigationIntent, setInvestigationIntent] = useState<InvestigationIntent>(null) | |
| const [projectionSetupActive, setProjectionSetupActive] = useState(false) | |
| const [runSets, setRunSets] = useState<RunSetRecord[]>([]) | |
| const [activeExecutionRunSetId, setActiveExecutionRunSetId] = useState<string | null>(null) | |
| const [projectionInputs, setProjectionInputs] = useState<ProjectionInputs>({ | |
| model: null, | |
| inforce: null, | |
| assumptionTableIds: [], | |
| factorTableIds: [], | |
| scenario: null, | |
| draft: { | |
| name: '', | |
| formulaConfirmed: false, | |
| inforceConfirmed: false, | |
| assumptionValidated: false, | |
| factorValidated: false, | |
| scenarioCompatible: false, | |
| startMonth: '2026-01', | |
| endMonth: '2045-12', | |
| traceScope: [], | |
| }, | |
| }) | |
| const notify = useCallback((message: string) => { setToast(message); window.setTimeout(() => setToast(''), 2600) }, []) | |
| const openInvestigation = useCallback((intent: NonNullable<InvestigationIntent>) => { setInvestigationIntent(intent); setActiveScreen(intent.kind === 'mentor' ? 'Mentor' : 'Investigate') }, []) | |
| const clearInvestigationIntent = useCallback(() => setInvestigationIntent(null), []) | |
| const updateProjectionInputs = useCallback((update: (current: ProjectionInputs) => ProjectionInputs) => setProjectionInputs(update), []) | |
| const addRunSet = useCallback((runSet: RunSetRecord) => setRunSets(current => [runSet, ...current]), []) | |
| const value = useMemo(() => ({ activeScreen, setActiveScreen, toast, notify, investigationIntent, openInvestigation, clearInvestigationIntent, projectionInputs, updateProjectionInputs, projectionSetupActive, setProjectionSetupActive, runSets, addRunSet, activeExecutionRunSetId, setActiveExecutionRunSetId }), [activeScreen, toast, notify, investigationIntent, openInvestigation, clearInvestigationIntent, projectionInputs, updateProjectionInputs, projectionSetupActive, setProjectionSetupActive, runSets, addRunSet, activeExecutionRunSetId]) | |
| return <AppContext.Provider value={value}>{children}</AppContext.Provider> | |
| } | |