mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-25 18:26:35 +00:00
Don't open sidebar when a dialog is open (#16030)
This commit is contained in:
parent
d7b8823234
commit
a32e6a9ac9
@ -62,7 +62,7 @@ export const showDialog = async (
|
|||||||
dialogParams: unknown,
|
dialogParams: unknown,
|
||||||
dialogImport?: () => Promise<unknown>,
|
dialogImport?: () => Promise<unknown>,
|
||||||
addHistory = true
|
addHistory = true
|
||||||
) => {
|
): Promise<boolean> => {
|
||||||
if (!(dialogTag in LOADED)) {
|
if (!(dialogTag in LOADED)) {
|
||||||
if (!dialogImport) {
|
if (!dialogImport) {
|
||||||
if (__DEV__) {
|
if (__DEV__) {
|
||||||
@ -71,7 +71,7 @@ export const showDialog = async (
|
|||||||
"Asked to show dialog that's not loaded and can't be imported"
|
"Asked to show dialog that's not loaded and can't be imported"
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
return;
|
return false;
|
||||||
}
|
}
|
||||||
LOADED[dialogTag] = {
|
LOADED[dialogTag] = {
|
||||||
element: dialogImport().then(() => {
|
element: dialogImport().then(() => {
|
||||||
@ -128,6 +128,8 @@ export const showDialog = async (
|
|||||||
// so it's guaranteed to be on top of the other elements
|
// so it's guaranteed to be on top of the other elements
|
||||||
root.appendChild(dialogElement);
|
root.appendChild(dialogElement);
|
||||||
dialogElement.showDialog(dialogParams);
|
dialogElement.showDialog(dialogParams);
|
||||||
|
|
||||||
|
return true;
|
||||||
};
|
};
|
||||||
|
|
||||||
export const replaceDialog = (dialogElement: HassDialog) => {
|
export const replaceDialog = (dialogElement: HassDialog) => {
|
||||||
|
@ -6,6 +6,7 @@ This is the entry point for providing external app stuff from app entrypoint.
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import { fireEvent } from "../common/dom/fire_event";
|
import { fireEvent } from "../common/dom/fire_event";
|
||||||
|
import { mainWindow } from "../common/dom/get_main_window";
|
||||||
import { HomeAssistantMain } from "../layouts/home-assistant-main";
|
import { HomeAssistantMain } from "../layouts/home-assistant-main";
|
||||||
import type { EMIncomingMessageCommands } from "./external_messaging";
|
import type { EMIncomingMessageCommands } from "./external_messaging";
|
||||||
|
|
||||||
@ -45,6 +46,15 @@ const handleExternalMessage = (
|
|||||||
result: null,
|
result: null,
|
||||||
});
|
});
|
||||||
} else if (msg.command === "sidebar/toggle") {
|
} else if (msg.command === "sidebar/toggle") {
|
||||||
|
if (mainWindow.history.state?.open) {
|
||||||
|
bus.fireMessage({
|
||||||
|
id: msg.id,
|
||||||
|
type: "result",
|
||||||
|
success: false,
|
||||||
|
error: { code: "not_allowed", message: "dialog open" },
|
||||||
|
});
|
||||||
|
return true;
|
||||||
|
}
|
||||||
fireEvent(hassMainEl, "hass-toggle-menu");
|
fireEvent(hassMainEl, "hass-toggle-menu");
|
||||||
bus.fireMessage({
|
bus.fireMessage({
|
||||||
id: msg.id,
|
id: msg.id,
|
||||||
@ -53,6 +63,15 @@ const handleExternalMessage = (
|
|||||||
result: null,
|
result: null,
|
||||||
});
|
});
|
||||||
} else if (msg.command === "sidebar/show") {
|
} else if (msg.command === "sidebar/show") {
|
||||||
|
if (mainWindow.history.state?.open) {
|
||||||
|
bus.fireMessage({
|
||||||
|
id: msg.id,
|
||||||
|
type: "result",
|
||||||
|
success: false,
|
||||||
|
error: { code: "not_allowed", message: "dialog open" },
|
||||||
|
});
|
||||||
|
return true;
|
||||||
|
}
|
||||||
fireEvent(hassMainEl, "hass-toggle-menu", { open: true });
|
fireEvent(hassMainEl, "hass-toggle-menu", { open: true });
|
||||||
bus.fireMessage({
|
bus.fireMessage({
|
||||||
id: msg.id,
|
id: msg.id,
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/* eslint-disable no-console */
|
/* eslint-disable no-console */
|
||||||
import { ReactiveElement } from "lit";
|
import { PropertyValueMap, ReactiveElement } from "lit";
|
||||||
import { HASSDomEvent } from "../common/dom/fire_event";
|
import { HASSDomEvent } from "../common/dom/fire_event";
|
||||||
import { mainWindow } from "../common/dom/get_main_window";
|
import { mainWindow } from "../common/dom/get_main_window";
|
||||||
import {
|
import {
|
||||||
@ -31,8 +31,11 @@ export const urlSyncMixin = <
|
|||||||
|
|
||||||
public connectedCallback(): void {
|
public connectedCallback(): void {
|
||||||
super.connectedCallback();
|
super.connectedCallback();
|
||||||
if (history.length === 1) {
|
if (mainWindow.history.length === 1) {
|
||||||
history.replaceState({ ...history.state, root: true }, "");
|
mainWindow.history.replaceState(
|
||||||
|
{ ...mainWindow.history.state, root: true },
|
||||||
|
""
|
||||||
|
);
|
||||||
}
|
}
|
||||||
mainWindow.addEventListener("popstate", this._popstateChangeListener);
|
mainWindow.addEventListener("popstate", this._popstateChangeListener);
|
||||||
this.addEventListener("dialog-closed", this._dialogClosedListener);
|
this.addEventListener("dialog-closed", this._dialogClosedListener);
|
||||||
@ -47,6 +50,15 @@ export const urlSyncMixin = <
|
|||||||
this.removeEventListener("dialog-closed", this._dialogClosedListener);
|
this.removeEventListener("dialog-closed", this._dialogClosedListener);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected firstUpdated(
|
||||||
|
changedProperties: PropertyValueMap<any> | Map<PropertyKey, unknown>
|
||||||
|
): void {
|
||||||
|
super.firstUpdated(changedProperties);
|
||||||
|
if (mainWindow.history.state?.dialog) {
|
||||||
|
this._handleDialogStateChange(mainWindow.history.state);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private _dialogClosedListener = (
|
private _dialogClosedListener = (
|
||||||
ev: HASSDomEvent<DialogClosedParams>
|
ev: HASSDomEvent<DialogClosedParams>
|
||||||
) => {
|
) => {
|
||||||
@ -67,7 +79,7 @@ export const urlSyncMixin = <
|
|||||||
if (DEBUG) {
|
if (DEBUG) {
|
||||||
console.log("remove state", ev.detail.dialog);
|
console.log("remove state", ev.detail.dialog);
|
||||||
}
|
}
|
||||||
if (history.length) {
|
if (mainWindow.history.length) {
|
||||||
this._ignoreNextPopState = true;
|
this._ignoreNextPopState = true;
|
||||||
historyPromise = new Promise((resolve) => {
|
historyPromise = new Promise((resolve) => {
|
||||||
historyResolve = () => {
|
historyResolve = () => {
|
||||||
@ -145,13 +157,21 @@ export const urlSyncMixin = <
|
|||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (state.dialogParams !== null) {
|
let shown = false;
|
||||||
showDialog(
|
if (state.open && state.dialogParams !== null) {
|
||||||
|
shown = await showDialog(
|
||||||
this,
|
this,
|
||||||
this.shadowRoot!,
|
this.shadowRoot!,
|
||||||
state.dialog,
|
state.dialog,
|
||||||
state.dialogParams
|
state.dialogParams
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
if (!shown) {
|
||||||
|
// can't open dialog, update state
|
||||||
|
mainWindow.history.replaceState(
|
||||||
|
{ ...mainWindow.history.state, open: false },
|
||||||
|
""
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user