diff options
author | Eric Bailey <git@esb.lol> | 2023-11-07 16:06:17 -0600 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-11-07 14:06:17 -0800 |
commit | 96d8faf4b052060b8774ac38c3400ab7d75451ad (patch) | |
tree | 9e3483160c623cc5a40d0a34d3d6e2b61ce38c8a /src/App.native.tsx | |
parent | bfe196bac5e618bfbeab4f6fabef3e5a18194868 (diff) | |
download | voidsky-96d8faf4b052060b8774ac38c3400ab7d75451ad.tar.zst |
Add persistent state provider (#1830)
* Add persistent state provider * Catch write error * Handle read errors, update error msgs * Fix lint * Don't provide initial state to loader * Remove colorMode from shell state * Idea: hook into persisted context from other files * Migrate settings to new hook * Rework persisted state to split individual contexts * Tweak persisted schema and validation --------- Co-authored-by: Paul Frazee <pfrazee@gmail.com>
Diffstat (limited to 'src/App.native.tsx')
-rw-r--r-- | src/App.native.tsx | 51 |
1 files changed, 35 insertions, 16 deletions
diff --git a/src/App.native.tsx b/src/App.native.tsx index a99dbc951..f5d35cf74 100644 --- a/src/App.native.tsx +++ b/src/App.native.tsx @@ -10,6 +10,8 @@ import {QueryClientProvider} from '@tanstack/react-query' import 'view/icons' +import {init as initPersistedState} from '#/state/persisted' +import {useColorMode} from 'state/shell' import {ThemeProvider} from 'lib/ThemeContext' import {s} from 'lib/styles' import {RootStoreModel, setupState, RootStoreProvider} from './state' @@ -23,7 +25,8 @@ import {Provider as ShellStateProvider} from 'state/shell' SplashScreen.preventAutoHideAsync() -const App = observer(function AppImpl() { +const InnerApp = observer(function AppImpl() { + const colorMode = useColorMode() const [rootStore, setRootStore] = useState<RootStoreModel | undefined>( undefined, ) @@ -45,23 +48,39 @@ const App = observer(function AppImpl() { return null } return ( + <QueryClientProvider client={queryClient}> + <ThemeProvider theme={colorMode}> + <RootSiblingParent> + <analytics.Provider> + <RootStoreProvider value={rootStore}> + <GestureHandlerRootView style={s.h100pct}> + <TestCtrls /> + <Shell /> + </GestureHandlerRootView> + </RootStoreProvider> + </analytics.Provider> + </RootSiblingParent> + </ThemeProvider> + </QueryClientProvider> + ) +}) + +function App() { + const [isReady, setReady] = useState(false) + + React.useEffect(() => { + initPersistedState().then(() => setReady(true)) + }, []) + + if (!isReady) { + return null + } + + return ( <ShellStateProvider> - <QueryClientProvider client={queryClient}> - <ThemeProvider theme={rootStore.shell.colorMode}> - <RootSiblingParent> - <analytics.Provider> - <RootStoreProvider value={rootStore}> - <GestureHandlerRootView style={s.h100pct}> - <TestCtrls /> - <Shell /> - </GestureHandlerRootView> - </RootStoreProvider> - </analytics.Provider> - </RootSiblingParent> - </ThemeProvider> - </QueryClientProvider> + <InnerApp /> </ShellStateProvider> ) -}) +} export default App |