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'
|
|
|
|
|
2024-01-09 02:43:56 +01:00
|
|
|
import {ThemeProvider as Alf} from '#/alf'
|
2023-11-07 23:06:17 +01:00
|
|
|
import {init as initPersistedState} from '#/state/persisted'
|
|
|
|
import {useColorMode} from 'state/shell'
|
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-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-24 23:31:33 +01:00
|
|
|
import {Provider as LoggedOutViewProvider} from 'state/shell/logged-out'
|
2023-11-20 22:29:27 +01:00
|
|
|
import I18nProvider from './locale/i18nProvider'
|
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'
|
2024-01-09 02:43:56 +01:00
|
|
|
import {useColorModeTheme} from '#/alf/util/useColorModeTheme'
|
2023-11-17 07:20:08 +01:00
|
|
|
|
2023-11-16 21:53:43 +01:00
|
|
|
function InnerApp() {
|
2023-12-10 00:10:12 +01:00
|
|
|
const {isInitialLoad, currentAccount} = useSession()
|
2023-11-10 00:14:51 +01:00
|
|
|
const {resumeSession} = useSessionApi()
|
2023-11-07 23:06:17 +01:00
|
|
|
const colorMode = useColorMode()
|
2024-01-09 02:43:56 +01:00
|
|
|
const theme = useColorModeTheme(colorMode)
|
2022-06-09 20:03:25 +02:00
|
|
|
|
|
|
|
// init
|
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
|
|
|
|
2023-12-10 00:10:12 +01:00
|
|
|
// wait for session to resume
|
|
|
|
if (isInitialLoad) return null
|
|
|
|
|
2023-11-07 23:06:17 +01:00
|
|
|
return (
|
2024-01-09 02:43:56 +01:00
|
|
|
<Alf theme={theme}>
|
|
|
|
<React.Fragment
|
|
|
|
// Resets the entire tree below when it changes:
|
|
|
|
key={currentAccount?.did}>
|
|
|
|
<LoggedOutViewProvider>
|
|
|
|
<UnreadNotifsProvider>
|
|
|
|
<ThemeProvider theme={colorMode}>
|
|
|
|
{/* All components should be within this provider */}
|
|
|
|
<RootSiblingParent>
|
|
|
|
<SafeAreaProvider>
|
|
|
|
<Shell />
|
|
|
|
</SafeAreaProvider>
|
|
|
|
</RootSiblingParent>
|
|
|
|
<ToastContainer />
|
|
|
|
</ThemeProvider>
|
|
|
|
</UnreadNotifsProvider>
|
|
|
|
</LoggedOutViewProvider>
|
|
|
|
</React.Fragment>
|
|
|
|
</Alf>
|
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>
|
2023-11-20 22:29:27 +01:00
|
|
|
<I18nProvider>
|
|
|
|
<InnerApp />
|
|
|
|
</I18nProvider>
|
2023-11-16 03:17:03 +01:00
|
|
|
</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
|