From 11f213ad097f927795a48537876dfa6d62247ead Mon Sep 17 00:00:00 2001 From: Paul Frazee Date: Thu, 29 Sep 2022 13:55:07 -0500 Subject: [PATCH] Clear all state on signout --- src/state/index.ts | 1 - src/state/models/me.ts | 12 ++++++++---- src/state/models/navigation.ts | 5 +++++ src/state/models/root-store.ts | 6 ++++++ src/state/models/session.ts | 11 ++++++++++- todos.txt | 6 +++--- 6 files changed, 32 insertions(+), 9 deletions(-) diff --git a/src/state/index.ts b/src/state/index.ts index c833ad9f..07a15f56 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 17a37238..0a362721 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 b7e15a29..f70360be 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 59bed4a6..33f4f408 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 ec3a7fc0..ced7ceeb 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) { diff --git a/todos.txt b/todos.txt index 5237d934..a31ccb8e 100644 --- a/todos.txt +++ b/todos.txt @@ -14,8 +14,6 @@ Paul's todo list - Disable badges for now - Disable editing avi or banner - More button -- Search view - - * - Notifications view - * - Linking @@ -29,4 +27,6 @@ Paul's todo list - Bugs - Check that sub components arent reloading too much - Titles are getting screwed up (possibly swipe related) - - Likes, RTs? \ No newline at end of file + - Likes, RTs? + - Thread view sizing off + - Home feed not showing own posts \ No newline at end of file