mirror of
https://github.com/home-assistant/frontend.git
synced 2025-11-12 04:20:28 +00:00
Fix navigate with replace when there are open dialogs (#23268)
This commit is contained in:
@@ -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
|
||||
export const navigate = async (path: string, options?: NavigateOptions) => {
|
||||
const { history } = mainWindow;
|
||||
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");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return new Promise<boolean>((resolve) => {
|
||||
// need to wait for history state to be updated in case a dialog was closed
|
||||
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;
|
||||
}
|
||||
const replace = options?.replace || false;
|
||||
|
||||
if (__DEMO__) {
|
||||
if (replace) {
|
||||
@@ -57,3 +54,4 @@ export const navigate = async (path: string, options?: NavigateOptions) =>
|
||||
resolve(true);
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user