mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-22 16:56:35 +00:00
Simplify dialog history logic (#23271)
This commit is contained in:
parent
0a413cba03
commit
df4d5a4567
@ -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;
|
||||
|
@ -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";
|
||||
|
||||
@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
@ -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();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
Loading…
x
Reference in New Issue
Block a user