mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-23 17:26:42 +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;
|
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> => {
|
export const closeDialog = async (dialogTag: string): Promise<boolean> => {
|
||||||
if (!(dialogTag in LOADED)) {
|
if (!(dialogTag in LOADED)) {
|
||||||
return true;
|
return true;
|
||||||
|
@ -1,10 +1,7 @@
|
|||||||
/* eslint-disable no-console */
|
/* eslint-disable no-console */
|
||||||
import type { PropertyValueMap, ReactiveElement } from "lit";
|
import type { PropertyValueMap, ReactiveElement } from "lit";
|
||||||
import { mainWindow } from "../common/dom/get_main_window";
|
import { mainWindow } from "../common/dom/get_main_window";
|
||||||
import {
|
import { closeLastDialog } from "../dialogs/make-dialog-manager";
|
||||||
closeLastDialog,
|
|
||||||
showDialogFromHistory,
|
|
||||||
} from "../dialogs/make-dialog-manager";
|
|
||||||
import type { ProvideHassElement } from "../mixins/provide-hass-lit-mixin";
|
import type { ProvideHassElement } from "../mixins/provide-hass-lit-mixin";
|
||||||
import type { Constructor } from "../types";
|
import type { Constructor } from "../types";
|
||||||
|
|
||||||
@ -43,7 +40,9 @@ export const urlSyncMixin = <
|
|||||||
): void {
|
): void {
|
||||||
super.firstUpdated(changedProperties);
|
super.firstUpdated(changedProperties);
|
||||||
if (mainWindow.history.state?.dialog) {
|
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) {
|
if ("dialog" in ev.state) {
|
||||||
// coming to a dialog
|
// coming to a dialog
|
||||||
// in practice the dialog stack is empty when navigating forward, so this is a no-op
|
// the dialog stack must be empty in this case so this state should be cleaned up
|
||||||
showDialogFromHistory(ev.state.dialog);
|
mainWindow.history.back();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user