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-09 19:04:16 +01:00
|
|
|
import {i18n} from '@lingui/core'
|
|
|
|
import {I18nProvider} from '@lingui/react'
|
|
|
|
import {defaultLocale, dynamicActivate} from './locale/i18n'
|
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'
|
2023-11-10 00:14:51 +01:00
|
|
|
import {
|
|
|
|
Provider as SessionProvider,
|
|
|
|
useSession,
|
|
|
|
useSessionApi,
|
|
|
|
} from 'state/session'
|
|
|
|
import * as persisted from '#/state/persisted'
|
2022-06-09 20:03:25 +02:00
|
|
|
|
2023-11-07 23:06:17 +01:00
|
|
|
const InnerApp = observer(function AppImpl() {
|
2023-11-10 00:14:51 +01:00
|
|
|
const {isInitialLoad} = useSession()
|
|
|
|
const {resumeSession} = useSessionApi()
|
2023-11-07 23:06:17 +01:00
|
|
|
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
|
|
|
})
|
2023-11-09 19:04:16 +01:00
|
|
|
dynamicActivate(defaultLocale) // async import of locale data
|
2023-11-10 00:35:25 +01:00
|
|
|
}, [])
|
2023-11-10 00:14:51 +01:00
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
const account = persisted.get('session').currentAccount
|
|
|
|
resumeSession(account)
|
|
|
|
}, [resumeSession])
|
2022-06-09 20:03:25 +02:00
|
|
|
|
|
|
|
// show nothing prior to init
|
2023-11-10 00:14:51 +01:00
|
|
|
if (!rootStore || isInitialLoad) {
|
|
|
|
// TODO add a loading state
|
2022-06-09 20:03:25 +02:00
|
|
|
return null
|
|
|
|
}
|
|
|
|
|
2023-11-07 23:06:17 +01:00
|
|
|
return (
|
|
|
|
<QueryClientProvider client={queryClient}>
|
|
|
|
<ThemeProvider theme={colorMode}>
|
|
|
|
<RootSiblingParent>
|
|
|
|
<analytics.Provider>
|
|
|
|
<RootStoreProvider value={rootStore}>
|
2023-11-09 19:04:16 +01:00
|
|
|
<I18nProvider i18n={i18n}>
|
|
|
|
<SafeAreaProvider>
|
|
|
|
<Shell />
|
|
|
|
</SafeAreaProvider>
|
|
|
|
</I18nProvider>
|
2023-11-07 23:06:17 +01:00
|
|
|
<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-10 00:14:51 +01:00
|
|
|
<SessionProvider>
|
|
|
|
<ShellStateProvider>
|
|
|
|
<PrefsStateProvider>
|
|
|
|
<MutedThreadsProvider>
|
|
|
|
<InvitesStateProvider>
|
|
|
|
<ModalStateProvider>
|
|
|
|
<InnerApp />
|
|
|
|
</ModalStateProvider>
|
|
|
|
</InvitesStateProvider>
|
|
|
|
</MutedThreadsProvider>
|
|
|
|
</PrefsStateProvider>
|
|
|
|
</ShellStateProvider>
|
|
|
|
</SessionProvider>
|
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
|