From 7f7d89c745d190d4c95c96f5419555840f62e4fb Mon Sep 17 00:00:00 2001 From: Bram Kragten Date: Mon, 29 Mar 2021 11:29:43 +0200 Subject: [PATCH] Hopefully fix some back button issues (#8708) --- src/dialogs/generic/dialog-box.ts | 8 ++++---- src/layouts/hass-tabs-subpage.ts | 3 +-- src/state/url-sync-mixin.ts | 13 +++++++++++-- 3 files changed, 16 insertions(+), 8 deletions(-) diff --git a/src/dialogs/generic/dialog-box.ts b/src/dialogs/generic/dialog-box.ts index f76c7ae959..3dcbbd37f8 100644 --- a/src/dialogs/generic/dialog-box.ts +++ b/src/dialogs/generic/dialog-box.ts @@ -36,11 +36,11 @@ class DialogBox extends LitElement { public closeDialog(): boolean { if (this._params?.confirmation || this._params?.prompt) { - this._dismiss(); - return true; + return false; } if (this._params) { - return false; + this._dismiss(); + return true; } return true; } @@ -140,7 +140,7 @@ class DialogBox extends LitElement { } private _dialogClosed(ev) { - if (this._params?.prompt && ev.detail.action === "ignore") { + if (ev.detail.action === "ignore") { return; } this._dismiss(); diff --git a/src/layouts/hass-tabs-subpage.ts b/src/layouts/hass-tabs-subpage.ts index 180dfe26dd..ed4d1e57ac 100644 --- a/src/layouts/hass-tabs-subpage.ts +++ b/src/layouts/hass-tabs-subpage.ts @@ -186,7 +186,7 @@ class HassTabsSubpage extends LitElement { } private _tabTapped(ev: Event): void { - navigate(this, (ev.currentTarget as any).path, true); + navigate(this, (ev.currentTarget as any).path); } private _backTapped(): void { @@ -230,7 +230,6 @@ class HassTabsSubpage extends LitElement { padding: 0 16px; box-sizing: border-box; } - #tabbar { display: flex; font-size: 14px; diff --git a/src/state/url-sync-mixin.ts b/src/state/url-sync-mixin.ts index 546cc24895..1976a06a14 100644 --- a/src/state/url-sync-mixin.ts +++ b/src/state/url-sync-mixin.ts @@ -40,6 +40,12 @@ export const urlSyncMixin = < ) => { if (DEBUG) { console.log("dialog closed", ev.detail.dialog); + console.log( + "open", + history.state?.open, + "dialog", + history.state?.dialog + ); } // If not closed by navigating back, and not a new dialog is open, remove the open state from history if ( @@ -56,8 +62,11 @@ export const urlSyncMixin = < private _popstateChangeListener = (ev: PopStateEvent) => { if (this._ignoreNextPopState) { - if (ev.state?.oldState?.replaced) { - // if the previous dialog was replaced, and the current dialog is closed, we should also remove the replaced dialog from history + if ( + ev.state?.oldState?.replaced || + ev.state?.oldState?.dialogParams === null + ) { + // if the previous dialog was replaced, or we could not copy the params, and the current dialog is closed, we should also remove the previous dialog from history if (DEBUG) { console.log("remove old state", ev.state.oldState); }