mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-10 10:56:34 +00:00
Fix navigate
with replace when there are open dialogs (#23268)
This commit is contained in:
parent
18cce45b88
commit
93947d76a2
@ -14,23 +14,20 @@ export interface NavigateOptions {
|
||||
data?: any;
|
||||
}
|
||||
|
||||
export const navigate = async (path: string, options?: NavigateOptions) =>
|
||||
new Promise<boolean>((resolve) => {
|
||||
// need to wait for history state to be updated in case a dialog was closed before calling navigate
|
||||
setTimeout(async () => {
|
||||
export const navigate = async (path: string, options?: NavigateOptions) => {
|
||||
const { history } = mainWindow;
|
||||
let replace = options?.replace || false;
|
||||
if (history.state?.dialog) {
|
||||
const closed = await closeAllDialogs();
|
||||
if (!closed) {
|
||||
// eslint-disable-next-line no-console
|
||||
console.warn("Navigation blocked, because dialog refused to close");
|
||||
resolve(false);
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
// if there were open dialogs, we discard the current state
|
||||
replace = true;
|
||||
}
|
||||
return new Promise<boolean>((resolve) => {
|
||||
// need to wait for history state to be updated in case a dialog was closed
|
||||
setTimeout(async () => {
|
||||
const replace = options?.replace || false;
|
||||
|
||||
if (__DEMO__) {
|
||||
if (replace) {
|
||||
@ -57,3 +54,4 @@ export const navigate = async (path: string, options?: NavigateOptions) =>
|
||||
resolve(true);
|
||||
});
|
||||
});
|
||||
};
|
||||
|
@ -177,9 +177,9 @@ export const closeLastDialog = async () => {
|
||||
};
|
||||
|
||||
export const closeAllDialogs = async () => {
|
||||
while (OPEN_DIALOG_STACK.length) {
|
||||
for (let i = OPEN_DIALOG_STACK.length - 1; i >= 0; i--) {
|
||||
// eslint-disable-next-line no-await-in-loop
|
||||
const closed = await closeLastDialog();
|
||||
const closed = await closeDialog(OPEN_DIALOG_STACK[i].dialogTag);
|
||||
if (!closed) {
|
||||
return false;
|
||||
}
|
||||
@ -187,7 +187,7 @@ export const closeAllDialogs = async () => {
|
||||
return true;
|
||||
};
|
||||
|
||||
const _handleClosed = async (ev: HASSDomEvent<DialogClosedParams>) => {
|
||||
const _handleClosed = (ev: HASSDomEvent<DialogClosedParams>) => {
|
||||
// If not closed by navigating back, remove the open state from history
|
||||
const dialogIndex = OPEN_DIALOG_STACK.findIndex(
|
||||
(state) => state.dialogTag === ev.detail.dialog
|
||||
|
Loading…
x
Reference in New Issue
Block a user