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 {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'
|
2023-11-16 02:17:50 +01:00
|
|
|
import {init as initReminders} from '#/state/shell/reminders'
|
2023-11-07 23:06:17 +01:00
|
|
|
import {useColorMode} from 'state/shell'
|
2023-06-15 23:45:14 +02:00
|
|
|
import * as analytics from 'lib/analytics/analytics'
|
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-16 03:17:03 +01:00
|
|
|
import {Provider as LightboxStateProvider} from 'state/lightbox'
|
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'
|
2023-11-13 03:13:11 +01:00
|
|
|
import {Provider as UnreadNotifsProvider} from 'state/queries/notifications/unread'
|
2023-11-10 00:14:51 +01:00
|
|
|
import * as persisted from '#/state/persisted'
|
2022-06-09 20:03:25 +02:00
|
|
|
|
2023-11-16 21:53:43 +01:00
|
|
|
function InnerApp() {
|
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-06-09 20:03:25 +02:00
|
|
|
|
|
|
|
// init
|
2023-11-10 00:14:51 +01:00
|
|
|
useEffect(() => {
|
2023-11-16 02:17:50 +01:00
|
|
|
initReminders()
|
|
|
|
analytics.init()
|
|
|
|
dynamicActivate(defaultLocale) // async import of locale data
|
|
|
|
|
2023-11-10 00:14:51 +01:00
|
|
|
const account = persisted.get('session').currentAccount
|
|
|
|
resumeSession(account)
|
|
|
|
}, [resumeSession])
|
2022-06-09 20:03:25 +02:00
|
|
|
|
|
|
|
// show nothing prior to init
|
2023-11-16 21:53:43 +01:00
|
|
|
if (isInitialLoad) {
|
2023-11-10 00:14:51 +01:00
|
|
|
// TODO add a loading state
|
2022-06-09 20:03:25 +02:00
|
|
|
return null
|
|
|
|
}
|
|
|
|
|
2023-11-14 23:54:02 +01:00
|
|
|
/*
|
|
|
|
* Session and initial state should be loaded prior to rendering below.
|
|
|
|
*/
|
|
|
|
|
2023-11-07 23:06:17 +01:00
|
|
|
return (
|
2023-11-14 23:54:02 +01:00
|
|
|
<UnreadNotifsProvider>
|
|
|
|
<ThemeProvider theme={colorMode}>
|
|
|
|
<analytics.Provider>
|
2023-11-16 21:53:43 +01:00
|
|
|
<I18nProvider i18n={i18n}>
|
|
|
|
{/* All components should be within this provider */}
|
|
|
|
<RootSiblingParent>
|
|
|
|
<SafeAreaProvider>
|
|
|
|
<Shell />
|
|
|
|
</SafeAreaProvider>
|
|
|
|
</RootSiblingParent>
|
|
|
|
</I18nProvider>
|
|
|
|
<ToastContainer />
|
2023-11-14 23:54:02 +01:00
|
|
|
</analytics.Provider>
|
|
|
|
</ThemeProvider>
|
|
|
|
</UnreadNotifsProvider>
|
2023-11-07 23:06:17 +01:00
|
|
|
)
|
2023-11-16 21:53:43 +01:00
|
|
|
}
|
2023-11-07 23:06:17 +01:00
|
|
|
|
|
|
|
function App() {
|
|
|
|
const [isReady, setReady] = useState(false)
|
|
|
|
|
|
|
|
React.useEffect(() => {
|
|
|
|
initPersistedState().then(() => setReady(true))
|
|
|
|
}, [])
|
|
|
|
|
|
|
|
if (!isReady) {
|
|
|
|
return null
|
|
|
|
}
|
|
|
|
|
2023-11-14 23:54:02 +01:00
|
|
|
/*
|
|
|
|
* NOTE: only nothing here can depend on other data or session state, since
|
|
|
|
* that is set up in the InnerApp component above.
|
|
|
|
*/
|
2022-06-09 20:03:25 +02:00
|
|
|
return (
|
2023-11-13 03:13:11 +01:00
|
|
|
<QueryClientProvider client={queryClient}>
|
|
|
|
<SessionProvider>
|
|
|
|
<ShellStateProvider>
|
|
|
|
<PrefsStateProvider>
|
|
|
|
<MutedThreadsProvider>
|
2023-11-14 23:54:02 +01:00
|
|
|
<InvitesStateProvider>
|
|
|
|
<ModalStateProvider>
|
2023-11-16 03:17:03 +01:00
|
|
|
<LightboxStateProvider>
|
|
|
|
<InnerApp />
|
|
|
|
</LightboxStateProvider>
|
2023-11-14 23:54:02 +01:00
|
|
|
</ModalStateProvider>
|
|
|
|
</InvitesStateProvider>
|
2023-11-13 03:13:11 +01:00
|
|
|
</MutedThreadsProvider>
|
|
|
|
</PrefsStateProvider>
|
|
|
|
</ShellStateProvider>
|
|
|
|
</SessionProvider>
|
|
|
|
</QueryClientProvider>
|
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
|