mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-25 18:26:35 +00:00
Fix helper dialog close and add failsafe for similar cases (#23468)
This commit is contained in:
parent
c9082724a8
commit
cb0a48265a
@ -14,9 +14,16 @@ export interface NavigateOptions {
|
|||||||
data?: any;
|
data?: any;
|
||||||
}
|
}
|
||||||
|
|
||||||
export const navigate = async (path: string, options?: NavigateOptions) => {
|
// max time to wait for dialogs to close before navigating
|
||||||
|
const DIALOG_WAIT_TIMEOUT = 500;
|
||||||
|
|
||||||
|
export const navigate = async (
|
||||||
|
path: string,
|
||||||
|
options?: NavigateOptions,
|
||||||
|
timestamp = Date.now()
|
||||||
|
) => {
|
||||||
const { history } = mainWindow;
|
const { history } = mainWindow;
|
||||||
if (history.state?.dialog) {
|
if (history.state?.dialog && Date.now() - timestamp < DIALOG_WAIT_TIMEOUT) {
|
||||||
const closed = await closeAllDialogs();
|
const closed = await closeAllDialogs();
|
||||||
if (!closed) {
|
if (!closed) {
|
||||||
// eslint-disable-next-line no-console
|
// eslint-disable-next-line no-console
|
||||||
@ -26,7 +33,7 @@ export const navigate = async (path: string, options?: NavigateOptions) => {
|
|||||||
return new Promise<boolean>((resolve) => {
|
return new Promise<boolean>((resolve) => {
|
||||||
// need to wait for history state to be updated in case a dialog was closed
|
// need to wait for history state to be updated in case a dialog was closed
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
navigate(path, options).then(resolve);
|
navigate(path, options, timestamp).then(resolve);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -225,6 +225,7 @@ export const makeDialogManager = (
|
|||||||
};
|
};
|
||||||
|
|
||||||
const _handleClosedFocus = async (ev: HASSDomEvent<DialogClosedParams>) => {
|
const _handleClosedFocus = async (ev: HASSDomEvent<DialogClosedParams>) => {
|
||||||
|
if (!LOADED[ev.detail.dialog]) return;
|
||||||
const closedFocusTargets = LOADED[ev.detail.dialog].closedFocusTargets;
|
const closedFocusTargets = LOADED[ev.detail.dialog].closedFocusTargets;
|
||||||
delete LOADED[ev.detail.dialog].closedFocusTargets;
|
delete LOADED[ev.detail.dialog].closedFocusTargets;
|
||||||
if (!closedFocusTargets) return;
|
if (!closedFocusTargets) return;
|
||||||
|
@ -32,6 +32,7 @@ import { brandsUrl } from "../../../util/brands-url";
|
|||||||
import type { Helper, HelperDomain } from "./const";
|
import type { Helper, HelperDomain } from "./const";
|
||||||
import { isHelperDomain } from "./const";
|
import { isHelperDomain } from "./const";
|
||||||
import type { ShowDialogHelperDetailParams } from "./show-dialog-helper-detail";
|
import type { ShowDialogHelperDetailParams } from "./show-dialog-helper-detail";
|
||||||
|
import { fireEvent } from "../../../common/dom/fire_event";
|
||||||
|
|
||||||
type HelperCreators = {
|
type HelperCreators = {
|
||||||
[domain in HelperDomain]: {
|
[domain in HelperDomain]: {
|
||||||
@ -129,6 +130,7 @@ export class DialogHelperDetail extends LitElement {
|
|||||||
this._error = undefined;
|
this._error = undefined;
|
||||||
this._domain = undefined;
|
this._domain = undefined;
|
||||||
this._params = undefined;
|
this._params = undefined;
|
||||||
|
fireEvent(this, "dialog-closed", { dialog: this.localName });
|
||||||
}
|
}
|
||||||
|
|
||||||
protected render() {
|
protected render() {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user