2023-11-01 16:15:37 +01:00
|
|
|
import 'lib/sentry' // must be near top
|
|
|
|
|
2022-06-09 20:03:25 +02:00
|
|
|
import React, {useState, useEffect} from 'react'
|
2023-11-01 16:15:37 +01:00
|
|
|
import {observer} from 'mobx-react-lite'
|
|
|
|
import {QueryClientProvider} from '@tanstack/react-query'
|
2023-01-26 19:53:46 +01:00
|
|
|
import {SafeAreaProvider} from 'react-native-safe-area-context'
|
2023-03-13 22:01:43 +01:00
|
|
|
import {RootSiblingParent} from 'react-native-root-siblings'
|
2023-11-01 16:15:37 +01:00
|
|
|
|
|
|
|
import 'view/icons'
|
|
|
|
|
2023-11-07 23:06:17 +01:00
|
|
|
import {init as initPersistedState} from '#/state/persisted'
|
|
|
|
import {useColorMode} from 'state/shell'
|
2023-06-15 23:45:14 +02:00
|
|
|
import * as analytics from 'lib/analytics/analytics'
|
2022-07-19 22:37:24 +02:00
|
|
|
import {RootStoreModel, setupState, RootStoreProvider} from './state'
|
2023-11-01 16:15:37 +01:00
|
|
|
import {Shell} from 'view/shell/index'
|
|
|
|
import {ToastContainer} from 'view/com/util/Toast.web'
|
2023-04-13 03:49:40 +02:00
|
|
|
import {ThemeProvider} from 'lib/ThemeContext'
|
2023-09-15 18:32:44 +02:00
|
|
|
import {queryClient} from 'lib/react-query'
|
2023-11-07 20:37:47 +01:00
|
|
|
import {Provider as ShellStateProvider} from 'state/shell'
|
2023-11-08 19:34:10 +01:00
|
|
|
import {Provider as ModalStateProvider} from 'state/modals'
|
2023-11-08 18:08:42 +01:00
|
|
|
import {Provider as MutedThreadsProvider} from 'state/muted-threads'
|
2023-11-08 18:10:59 +01:00
|
|
|
import {Provider as InvitesStateProvider} from 'state/invites'
|
2023-11-08 18:38:28 +01:00
|
|
|
import {Provider as PrefsStateProvider} from 'state/preferences'
|
2022-06-09 20:03:25 +02:00
|
|
|
|
2023-11-07 23:06:17 +01:00
|
|
|
const InnerApp = observer(function AppImpl() {
|
|
|
|
const colorMode = useColorMode()
|
2022-07-19 22:37:24 +02:00
|
|
|
const [rootStore, setRootStore] = useState<RootStoreModel | undefined>(
|
|
|
|
undefined,
|
|
|
|
)
|
2022-06-09 20:03:25 +02:00
|
|
|
|
|
|
|
// init
|
|
|
|
useEffect(() => {
|
2023-02-23 22:52:12 +01:00
|
|
|
setupState().then(store => {
|
|
|
|
setRootStore(store)
|
2023-04-04 20:01:38 +02:00
|
|
|
analytics.init(store)
|
2023-02-23 22:52:12 +01:00
|
|
|
})
|
2022-06-09 20:03:25 +02:00
|
|
|
}, [])
|
|
|
|
|
|
|
|
// show nothing prior to init
|
|
|
|
if (!rootStore) {
|
|
|
|
return null
|
|
|
|
}
|
|
|
|
|
2023-11-07 23:06:17 +01:00
|
|
|
return (
|
|
|
|
<QueryClientProvider client={queryClient}>
|
|
|
|
<ThemeProvider theme={colorMode}>
|
|
|
|
<RootSiblingParent>
|
|
|
|
<analytics.Provider>
|
|
|
|
<RootStoreProvider value={rootStore}>
|
|
|
|
<SafeAreaProvider>
|
|
|
|
<Shell />
|
|
|
|
</SafeAreaProvider>
|
|
|
|
<ToastContainer />
|
|
|
|
</RootStoreProvider>
|
|
|
|
</analytics.Provider>
|
|
|
|
</RootSiblingParent>
|
|
|
|
</ThemeProvider>
|
|
|
|
</QueryClientProvider>
|
|
|
|
)
|
|
|
|
})
|
|
|
|
|
|
|
|
function App() {
|
|
|
|
const [isReady, setReady] = useState(false)
|
|
|
|
|
|
|
|
React.useEffect(() => {
|
|
|
|
initPersistedState().then(() => setReady(true))
|
|
|
|
}, [])
|
|
|
|
|
|
|
|
if (!isReady) {
|
|
|
|
return null
|
|
|
|
}
|
|
|
|
|
2022-06-09 20:03:25 +02:00
|
|
|
return (
|
2023-11-07 20:37:47 +01:00
|
|
|
<ShellStateProvider>
|
2023-11-08 18:38:28 +01:00
|
|
|
<PrefsStateProvider>
|
|
|
|
<MutedThreadsProvider>
|
|
|
|
<InvitesStateProvider>
|
2023-11-08 19:34:10 +01:00
|
|
|
<ModalStateProvider>
|
|
|
|
<InnerApp />
|
|
|
|
</ModalStateProvider>
|
2023-11-08 18:38:28 +01:00
|
|
|
</InvitesStateProvider>
|
|
|
|
</MutedThreadsProvider>
|
|
|
|
</PrefsStateProvider>
|
2023-11-07 20:37:47 +01:00
|
|
|
</ShellStateProvider>
|
2022-06-09 20:03:25 +02:00
|
|
|
)
|
2023-11-07 23:06:17 +01:00
|
|
|
}
|
2022-06-09 20:03:25 +02:00
|
|
|
|
|
|
|
export default App
|