Skip to content

Commit

Permalink
Simplify dialog history logic (#23271)
Browse files Browse the repository at this point in the history
  • Loading branch information
MindFreeze authored Dec 12, 2024
1 parent 0a413cb commit df4d5a4
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 26 deletions.
19 changes: 0 additions & 19 deletions src/dialogs/make-dialog-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,25 +125,6 @@ export const showDialog = async (
return true;
};

export const showDialogFromHistory = async (dialogTag: string) => {
const dialogState = OPEN_DIALOG_STACK.find(
(state) => state.dialogTag === dialogTag
);
if (dialogState) {
showDialog(
dialogState.element,
dialogState.root,
dialogTag,
dialogState.dialogParams,
dialogState.dialogImport,
false
);
} else {
// remove the dialog from history if already closed
mainWindow.history.back();
}
};

export const closeDialog = async (dialogTag: string): Promise<boolean> => {
if (!(dialogTag in LOADED)) {
return true;
Expand Down
13 changes: 6 additions & 7 deletions src/state/url-sync-mixin.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
/* eslint-disable no-console */
import type { PropertyValueMap, ReactiveElement } from "lit";
import { mainWindow } from "../common/dom/get_main_window";
import {
closeLastDialog,
showDialogFromHistory,
} from "../dialogs/make-dialog-manager";
import { closeLastDialog } from "../dialogs/make-dialog-manager";
import type { ProvideHassElement } from "../mixins/provide-hass-lit-mixin";
import type { Constructor } from "../types";

Expand Down Expand Up @@ -43,7 +40,9 @@ export const urlSyncMixin = <
): void {
super.firstUpdated(changedProperties);
if (mainWindow.history.state?.dialog) {
showDialogFromHistory(mainWindow.history.state.dialog);
// this is a page refresh with a dialog open
// the dialog stack must be empty in this case so this state should be cleaned up
mainWindow.history.back();
}
}

Expand All @@ -59,8 +58,8 @@ export const urlSyncMixin = <
}
if ("dialog" in ev.state) {
// coming to a dialog
// in practice the dialog stack is empty when navigating forward, so this is a no-op
showDialogFromHistory(ev.state.dialog);
// the dialog stack must be empty in this case so this state should be cleaned up
mainWindow.history.back();
}
}
};
Expand Down

0 comments on commit df4d5a4

Please sign in to comment.