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>
This commit is contained in:
parent
bfe196bac5
commit
96d8faf4b0
13 changed files with 467 additions and 76 deletions
|
@ -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 (
|
||||
<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>
|
||||
</ShellStateProvider>
|
||||
<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>
|
||||
<InnerApp />
|
||||
</ShellStateProvider>
|
||||
)
|
||||
}
|
||||
|
||||
export default App
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue