diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/state/index.ts | 1 | ||||
-rw-r--r-- | src/state/models/me.ts | 12 | ||||
-rw-r--r-- | src/state/models/navigation.ts | 5 | ||||
-rw-r--r-- | src/state/models/root-store.ts | 6 | ||||
-rw-r--r-- | src/state/models/session.ts | 11 |
5 files changed, 29 insertions, 6 deletions
diff --git a/src/state/index.ts b/src/state/index.ts index c833ad9f6..07a15f56a 100644 --- a/src/state/index.ts +++ b/src/state/index.ts @@ -32,7 +32,6 @@ export async function setupState() { }) await rootStore.session.setup() - await rootStore.me.load() console.log(rootStore.me) return rootStore diff --git a/src/state/models/me.ts b/src/state/models/me.ts index 17a372381..0a3627217 100644 --- a/src/state/models/me.ts +++ b/src/state/models/me.ts @@ -11,6 +11,13 @@ export class MeModel { makeAutoObservable(this, {rootStore: false}, {autoBind: true}) } + clear() { + this.did = undefined + this.name = undefined + this.displayName = undefined + this.description = undefined + } + async load() { const sess = this.rootStore.session if (sess.isAuthed && sess.data) { @@ -29,10 +36,7 @@ export class MeModel { } }) } else { - this.did = undefined - this.name = undefined - this.displayName = undefined - this.description = undefined + this.clear() } } } diff --git a/src/state/models/navigation.ts b/src/state/models/navigation.ts index b7e15a290..f70360bed 100644 --- a/src/state/models/navigation.ts +++ b/src/state/models/navigation.ts @@ -168,6 +168,11 @@ export class NavigationModel { }) } + clear() { + this.tabs = [new NavigationTabModel()] + this.tabIndex = 0 + } + // accessors // = diff --git a/src/state/models/root-store.ts b/src/state/models/root-store.ts index 59bed4a6a..33f4f4085 100644 --- a/src/state/models/root-store.ts +++ b/src/state/models/root-store.ts @@ -55,6 +55,12 @@ export class RootStoreModel { } } } + + clearAll() { + this.session.clear() + this.nav.clear() + this.me.clear() + } } const throwawayInst = new RootStoreModel(AdxApi.service('http://localhost')) // this will be replaced by the loader diff --git a/src/state/models/session.ts b/src/state/models/session.ts index ec3a7fc03..ced7ceeb0 100644 --- a/src/state/models/session.ts +++ b/src/state/models/session.ts @@ -124,6 +124,9 @@ export class SessionModel { try { const sess = await this.rootStore.api.todo.adx.getSession({}) if (sess.success && this.data && this.data.userdid === sess.data.did) { + this.rootStore.me.load().catch(e => { + console.error('Failed to fetch local user information', e) + }) return // success } } catch (e: any) {} @@ -156,6 +159,9 @@ export class SessionModel { userdid: res.data.did, }) this.configureApi() + this.rootStore.me.load().catch(e => { + console.error('Failed to fetch local user information', e) + }) } } @@ -186,6 +192,9 @@ export class SessionModel { }) this.setOnboardingStage(OnboardingStage.Init) this.configureApi() + this.rootStore.me.load().catch(e => { + console.error('Failed to fetch local user information', e) + }) } } @@ -195,7 +204,7 @@ export class SessionModel { console.error('(Minor issue) Failed to delete session on the server', e) }) } - this.clear() + this.rootStore.clearAll() } setOnboardingStage(stage: OnboardingStage | null) { |