Add back isInitialLoad to session (#2155)
parent
6b3eb401b0
commit
97b54b51c6
|
@ -39,7 +39,7 @@ SplashScreen.preventAutoHideAsync()
|
||||||
|
|
||||||
function InnerApp() {
|
function InnerApp() {
|
||||||
const colorMode = useColorMode()
|
const colorMode = useColorMode()
|
||||||
const {currentAccount} = useSession()
|
const {isInitialLoad, currentAccount} = useSession()
|
||||||
const {resumeSession} = useSessionApi()
|
const {resumeSession} = useSessionApi()
|
||||||
|
|
||||||
// init
|
// init
|
||||||
|
@ -53,6 +53,9 @@ function InnerApp() {
|
||||||
resumeSession(account)
|
resumeSession(account)
|
||||||
}, [resumeSession])
|
}, [resumeSession])
|
||||||
|
|
||||||
|
// wait for session to resume
|
||||||
|
if (isInitialLoad) return null
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<React.Fragment
|
<React.Fragment
|
||||||
// Resets the entire tree below when it changes:
|
// Resets the entire tree below when it changes:
|
||||||
|
|
|
@ -30,7 +30,7 @@ import {Provider as UnreadNotifsProvider} from 'state/queries/notifications/unre
|
||||||
import * as persisted from '#/state/persisted'
|
import * as persisted from '#/state/persisted'
|
||||||
|
|
||||||
function InnerApp() {
|
function InnerApp() {
|
||||||
const {currentAccount} = useSession()
|
const {isInitialLoad, currentAccount} = useSession()
|
||||||
const {resumeSession} = useSessionApi()
|
const {resumeSession} = useSessionApi()
|
||||||
const colorMode = useColorMode()
|
const colorMode = useColorMode()
|
||||||
|
|
||||||
|
@ -40,6 +40,9 @@ function InnerApp() {
|
||||||
resumeSession(account)
|
resumeSession(account)
|
||||||
}, [resumeSession])
|
}, [resumeSession])
|
||||||
|
|
||||||
|
// wait for session to resume
|
||||||
|
if (isInitialLoad) return null
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<React.Fragment
|
<React.Fragment
|
||||||
// Resets the entire tree below when it changes:
|
// Resets the entire tree below when it changes:
|
||||||
|
|
|
@ -28,6 +28,7 @@ export function getAgent() {
|
||||||
export type SessionAccount = persisted.PersistedAccount
|
export type SessionAccount = persisted.PersistedAccount
|
||||||
|
|
||||||
export type SessionState = {
|
export type SessionState = {
|
||||||
|
isInitialLoad: boolean
|
||||||
isSwitchingAccounts: boolean
|
isSwitchingAccounts: boolean
|
||||||
accounts: SessionAccount[]
|
accounts: SessionAccount[]
|
||||||
currentAccount: SessionAccount | undefined
|
currentAccount: SessionAccount | undefined
|
||||||
|
@ -75,6 +76,7 @@ export type ApiContext = {
|
||||||
}
|
}
|
||||||
|
|
||||||
const StateContext = React.createContext<StateContext>({
|
const StateContext = React.createContext<StateContext>({
|
||||||
|
isInitialLoad: true,
|
||||||
isSwitchingAccounts: false,
|
isSwitchingAccounts: false,
|
||||||
accounts: [],
|
accounts: [],
|
||||||
currentAccount: undefined,
|
currentAccount: undefined,
|
||||||
|
@ -150,6 +152,7 @@ export function Provider({children}: React.PropsWithChildren<{}>) {
|
||||||
const queryClient = useQueryClient()
|
const queryClient = useQueryClient()
|
||||||
const isDirty = React.useRef(false)
|
const isDirty = React.useRef(false)
|
||||||
const [state, setState] = React.useState<SessionState>({
|
const [state, setState] = React.useState<SessionState>({
|
||||||
|
isInitialLoad: true,
|
||||||
isSwitchingAccounts: false,
|
isSwitchingAccounts: false,
|
||||||
accounts: persisted.get('session').accounts,
|
accounts: persisted.get('session').accounts,
|
||||||
currentAccount: undefined, // assume logged out to start
|
currentAccount: undefined, // assume logged out to start
|
||||||
|
@ -434,6 +437,11 @@ export function Provider({children}: React.PropsWithChildren<{}>) {
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
logger.error(`session: resumeSession failed`, {error: e})
|
logger.error(`session: resumeSession failed`, {error: e})
|
||||||
|
} finally {
|
||||||
|
setState(s => ({
|
||||||
|
...s,
|
||||||
|
isInitialLoad: false,
|
||||||
|
}))
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
[initSession],
|
[initSession],
|
||||||
|
|
Loading…
Reference in New Issue