From ec5beb905cfd57e8e2e8ce59cd63176fe9180177 Mon Sep 17 00:00:00 2001 From: Eric Amodio Date: Wed, 3 May 2023 00:34:04 -0400 Subject: [PATCH] Fixes state not being restored on Home webview --- src/webviews/apps/commitDetails/commitDetails.ts | 5 ++++- src/webviews/apps/home/home.ts | 5 +++++ src/webviews/apps/plus/timeline/timeline.ts | 2 ++ src/webviews/home/homeWebview.ts | 26 ++++++++++++++---------- 4 files changed, 26 insertions(+), 12 deletions(-) diff --git a/src/webviews/apps/commitDetails/commitDetails.ts b/src/webviews/apps/commitDetails/commitDetails.ts index 745e69e..2ac843d 100644 --- a/src/webviews/apps/commitDetails/commitDetails.ts +++ b/src/webviews/apps/commitDetails/commitDetails.ts @@ -53,7 +53,7 @@ export class CommitDetailsApp extends App> { } override onInitialize() { - this.log(`onInitialize()`); + this.state = this.getState() ?? this.state; this.renderContent(); } @@ -117,6 +117,8 @@ export class CommitDetailsApp extends App> { // // } // this.state = newState; + // this.setState(this.state); + // this.renderRichContent(); // }); // break; @@ -125,6 +127,7 @@ export class CommitDetailsApp extends App> { assertsSerialized(params.state); this.state = params.state; + this.setState(this.state); this.renderContent(); }); break; diff --git a/src/webviews/apps/home/home.ts b/src/webviews/apps/home/home.ts index 12d7102..5413882 100644 --- a/src/webviews/apps/home/home.ts +++ b/src/webviews/apps/home/home.ts @@ -44,6 +44,7 @@ export class HomeApp extends App { this.$steps = [...document.querySelectorAll('stepped-section[id]')]; this.$cards = [...document.querySelectorAll('card-section[id]')]; + this.state = this.getState() ?? this.state; this.updateState(); } @@ -92,6 +93,7 @@ export class HomeApp extends App { this.state.completedActions = params.completedActions; this.state.avatar = params.avatar; this.state.pinStatus = params.pinStatus; + this.setState(this.state); this.updateState(); }); break; @@ -100,6 +102,7 @@ export class HomeApp extends App { onIpc(DidChangeRepositoriesType, msg, params => { this.state.repositories = { ...params }; + this.setState(this.state); this.updateNoRepo(); }); break; @@ -108,6 +111,7 @@ export class HomeApp extends App { onIpc(DidChangeConfigurationType, msg, params => { this.state.plusEnabled = params.plusEnabled; + this.setState(this.state); this.updatePlusContent(); }); break; @@ -116,6 +120,7 @@ export class HomeApp extends App { onIpc(DidChangeLayoutType, msg, params => { this.state.layout = params.layout; + this.setState(this.state); this.updateLayout(); }); break; diff --git a/src/webviews/apps/plus/timeline/timeline.ts b/src/webviews/apps/plus/timeline/timeline.ts index 808ab2d..f7dd36d 100644 --- a/src/webviews/apps/plus/timeline/timeline.ts +++ b/src/webviews/apps/plus/timeline/timeline.ts @@ -27,6 +27,7 @@ export class TimelineApp extends App { protected override onInitialize() { provideVSCodeDesignSystem().register(vsCodeButton(), vsCodeDropdown(), vsCodeOption()); + this.state = this.getState() ?? this.state; this.updateState(); } @@ -53,6 +54,7 @@ export class TimelineApp extends App { onIpc(DidChangeNotificationType, msg, params => { this.state = params.state; + this.setState(this.state); this.updateState(); }); break; diff --git a/src/webviews/home/homeWebview.ts b/src/webviews/home/homeWebview.ts index 486ddc3..68eda89 100644 --- a/src/webviews/home/homeWebview.ts +++ b/src/webviews/home/homeWebview.ts @@ -140,7 +140,7 @@ export class HomeWebviewProvider implements WebviewProvider { } } - private completeStep({ id, completed = false }: CompleteStepParams) { + private async completeStep({ id, completed = false }: CompleteStepParams) { const steps = this.container.storage.get('home:steps:completed', []); const hasStep = steps.includes(id); @@ -149,31 +149,35 @@ export class HomeWebviewProvider implements WebviewProvider { } else if (hasStep && !completed) { steps.splice(steps.indexOf(id), 1); } - void this.container.storage.store('home:steps:completed', steps); + + await this.container.storage.store('home:steps:completed', steps); + void this.notifyDidChangeData(); } - private dismissSection(params: DismissSectionParams) { + private async dismissSection(params: DismissSectionParams) { const sections = this.container.storage.get('home:sections:dismissed', []); - if (sections.includes(params.id)) { - return; - } + if (sections.includes(params.id)) return; sections.push(params.id); - void this.container.storage.store('home:sections:dismissed', sections); + + await this.container.storage.store('home:sections:dismissed', sections); + void this.notifyDidChangeData(); } - private dismissBanner(params: DismissBannerParams) { + private async dismissBanner(params: DismissBannerParams) { const banners = this.container.storage.get('home:banners:dismissed', []); if (!banners.includes(params.id)) { banners.push(params.id); } - void this.container.storage.store('home:banners:dismissed', banners); + await this.container.storage.store('home:banners:dismissed', banners); + void this.notifyDidChangeData(); } - private dismissPinStatus() { - void this.container.storage.store('home:status:pinned', false); + private async dismissPinStatus() { + await this.container.storage.store('home:status:pinned', false); + void this.notifyDidChangeData(); } includeBootstrap(): Promise {