[Session] Extract resumeSession out (#3811)
This commit is contained in:
parent
dadf27fd2f
commit
5ec945b762
4 changed files with 43 additions and 36 deletions
|
@ -6,6 +6,7 @@ import {RootSiblingParent} from 'react-native-root-siblings'
|
|||
import {SafeAreaProvider} from 'react-native-safe-area-context'
|
||||
|
||||
import {Provider as StatsigProvider} from '#/lib/statsig/statsig'
|
||||
import {logger} from '#/logger'
|
||||
import {init as initPersistedState} from '#/state/persisted'
|
||||
import {Provider as LabelDefsProvider} from '#/state/preferences/label-defs'
|
||||
import {Provider as ModerationOptsProvider} from '#/state/preferences/moderation-opts'
|
||||
|
@ -22,6 +23,7 @@ import {Provider as PrefsStateProvider} from 'state/preferences'
|
|||
import {Provider as UnreadNotifsProvider} from 'state/queries/notifications/unread'
|
||||
import {
|
||||
Provider as SessionProvider,
|
||||
SessionAccount,
|
||||
useSession,
|
||||
useSessionApi,
|
||||
} from 'state/session'
|
||||
|
@ -36,19 +38,31 @@ import {Provider as PortalProvider} from '#/components/Portal'
|
|||
import I18nProvider from './locale/i18nProvider'
|
||||
|
||||
function InnerApp() {
|
||||
const {isInitialLoad, currentAccount} = useSession()
|
||||
const {resumeSession} = useSessionApi()
|
||||
const [isReady, setIsReady] = React.useState(false)
|
||||
const {currentAccount} = useSession()
|
||||
const {initSession} = useSessionApi()
|
||||
const theme = useColorModeTheme()
|
||||
useIntentHandler()
|
||||
|
||||
// init
|
||||
useEffect(() => {
|
||||
async function resumeSession(account?: SessionAccount) {
|
||||
try {
|
||||
if (account) {
|
||||
await initSession(account)
|
||||
}
|
||||
} catch (e) {
|
||||
logger.error(`session: resumeSession failed`, {message: e})
|
||||
} finally {
|
||||
setIsReady(true)
|
||||
}
|
||||
}
|
||||
const account = readLastActiveAccount()
|
||||
resumeSession(account)
|
||||
}, [resumeSession])
|
||||
}, [initSession])
|
||||
|
||||
// wait for session to resume
|
||||
if (isInitialLoad) return null
|
||||
if (!isReady) return null
|
||||
|
||||
return (
|
||||
<Alf theme={theme}>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue