mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-14 21:06:34 +00:00
fix
This commit is contained in:
parent
48f5d17060
commit
a6cbbfe1a4
@ -14,42 +14,46 @@ export interface NavigateOptions {
|
|||||||
data?: any;
|
data?: any;
|
||||||
}
|
}
|
||||||
|
|
||||||
export const navigate = async (path: string, options?: NavigateOptions) => {
|
export const navigate = async (path: string, options?: NavigateOptions) =>
|
||||||
const { history } = mainWindow;
|
new Promise<boolean>((resolve) => {
|
||||||
let replace = options?.replace || false;
|
// need to wait for history state to be updated in case a dialog was closed before calling navigate
|
||||||
|
setTimeout(async () => {
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
// if there were open dialogs, we discard the current state
|
||||||
|
replace = true;
|
||||||
|
}
|
||||||
|
|
||||||
if (history.state?.dialog) {
|
if (__DEMO__) {
|
||||||
const closed = await closeAllDialogs();
|
if (replace) {
|
||||||
if (!closed) {
|
history.replaceState(
|
||||||
// eslint-disable-next-line no-console
|
history.state?.root ? { root: true } : (options?.data ?? null),
|
||||||
console.warn("Navigation blocked, because dialog refused to close");
|
"",
|
||||||
return false;
|
`${mainWindow.location.pathname}#${path}`
|
||||||
}
|
);
|
||||||
// if there were open dialogs, we discard the current state
|
} else {
|
||||||
replace = true;
|
mainWindow.location.hash = path;
|
||||||
}
|
}
|
||||||
|
} else if (replace) {
|
||||||
if (__DEMO__) {
|
history.replaceState(
|
||||||
if (replace) {
|
history.state?.root ? { root: true } : (options?.data ?? null),
|
||||||
history.replaceState(
|
"",
|
||||||
history.state?.root ? { root: true } : (options?.data ?? null),
|
path
|
||||||
"",
|
);
|
||||||
`${mainWindow.location.pathname}#${path}`
|
} else {
|
||||||
);
|
history.pushState(options?.data ?? null, "", path);
|
||||||
} else {
|
}
|
||||||
mainWindow.location.hash = path;
|
fireEvent(mainWindow, "location-changed", {
|
||||||
}
|
replace,
|
||||||
} else if (replace) {
|
});
|
||||||
history.replaceState(
|
resolve(true);
|
||||||
history.state?.root ? { root: true } : (options?.data ?? null),
|
});
|
||||||
"",
|
|
||||||
path
|
|
||||||
);
|
|
||||||
} else {
|
|
||||||
history.pushState(options?.data ?? null, "", path);
|
|
||||||
}
|
|
||||||
fireEvent(mainWindow, "location-changed", {
|
|
||||||
replace,
|
|
||||||
});
|
});
|
||||||
return true;
|
|
||||||
};
|
|
||||||
|
@ -171,11 +171,21 @@ export const closeLastDialog = async () => {
|
|||||||
""
|
""
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
return closed;
|
||||||
}
|
}
|
||||||
|
return true;
|
||||||
};
|
};
|
||||||
|
|
||||||
export const closeAllDialogs = () =>
|
export const closeAllDialogs = async () => {
|
||||||
Promise.all(OPEN_DIALOG_STACK.map((state) => closeDialog(state.dialogTag)));
|
while (OPEN_DIALOG_STACK.length) {
|
||||||
|
// eslint-disable-next-line no-await-in-loop
|
||||||
|
const closed = await closeLastDialog();
|
||||||
|
if (!closed) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
};
|
||||||
|
|
||||||
const _handleClosed = async (ev: HASSDomEvent<DialogClosedParams>) => {
|
const _handleClosed = async (ev: HASSDomEvent<DialogClosedParams>) => {
|
||||||
// If not closed by navigating back, remove the open state from history
|
// If not closed by navigating back, remove the open state from history
|
||||||
|
Loading…
x
Reference in New Issue
Block a user