Don't add toast to history (#8915)
This commit is contained in:
parent
a43120320e
commit
aaa50b4d1d
|
@ -45,7 +45,8 @@ export const showDialog = async (
|
||||||
root: ShadowRoot | HTMLElement,
|
root: ShadowRoot | HTMLElement,
|
||||||
dialogTag: string,
|
dialogTag: string,
|
||||||
dialogParams: unknown,
|
dialogParams: unknown,
|
||||||
dialogImport?: () => Promise<unknown>
|
dialogImport?: () => Promise<unknown>,
|
||||||
|
addHistory = true
|
||||||
) => {
|
) => {
|
||||||
if (!(dialogTag in LOADED)) {
|
if (!(dialogTag in LOADED)) {
|
||||||
if (!dialogImport) {
|
if (!dialogImport) {
|
||||||
|
@ -59,30 +60,31 @@ export const showDialog = async (
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
history.replaceState(
|
if (addHistory) {
|
||||||
{
|
history.replaceState(
|
||||||
dialog: dialogTag,
|
{
|
||||||
open: false,
|
dialog: dialogTag,
|
||||||
oldState:
|
open: false,
|
||||||
history.state?.open && history.state?.dialog !== dialogTag
|
oldState:
|
||||||
? history.state
|
history.state?.open && history.state?.dialog !== dialogTag
|
||||||
: null,
|
? history.state
|
||||||
},
|
: null,
|
||||||
""
|
},
|
||||||
);
|
|
||||||
try {
|
|
||||||
history.pushState(
|
|
||||||
{ dialog: dialogTag, dialogParams: dialogParams, open: true },
|
|
||||||
""
|
|
||||||
);
|
|
||||||
} catch (err) {
|
|
||||||
// dialogParams could not be cloned, probably contains callback
|
|
||||||
history.pushState(
|
|
||||||
{ dialog: dialogTag, dialogParams: null, open: true },
|
|
||||||
""
|
""
|
||||||
);
|
);
|
||||||
|
try {
|
||||||
|
history.pushState(
|
||||||
|
{ dialog: dialogTag, dialogParams: dialogParams, open: true },
|
||||||
|
""
|
||||||
|
);
|
||||||
|
} catch (err) {
|
||||||
|
// dialogParams could not be cloned, probably contains callback
|
||||||
|
history.pushState(
|
||||||
|
{ dialog: dialogTag, dialogParams: null, open: true },
|
||||||
|
""
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const dialogElement = await LOADED[dialogTag];
|
const dialogElement = await LOADED[dialogTag];
|
||||||
dialogElement.showDialog(dialogParams);
|
dialogElement.showDialog(dialogParams);
|
||||||
};
|
};
|
||||||
|
|
|
@ -8,6 +8,7 @@ interface RegisterDialogParams {
|
||||||
dialogShowEvent: keyof HASSDomEvents;
|
dialogShowEvent: keyof HASSDomEvents;
|
||||||
dialogTag: keyof HTMLElementTagNameMap;
|
dialogTag: keyof HTMLElementTagNameMap;
|
||||||
dialogImport: () => Promise<unknown>;
|
dialogImport: () => Promise<unknown>;
|
||||||
|
addHistory?: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
declare global {
|
declare global {
|
||||||
|
@ -38,6 +39,7 @@ export const dialogManagerMixin = <T extends Constructor<HassBaseEl>>(
|
||||||
dialogShowEvent,
|
dialogShowEvent,
|
||||||
dialogTag,
|
dialogTag,
|
||||||
dialogImport,
|
dialogImport,
|
||||||
|
addHistory = true,
|
||||||
}: RegisterDialogParams) {
|
}: RegisterDialogParams) {
|
||||||
this.addEventListener(dialogShowEvent, (showEv) => {
|
this.addEventListener(dialogShowEvent, (showEv) => {
|
||||||
showDialog(
|
showDialog(
|
||||||
|
@ -45,7 +47,8 @@ export const dialogManagerMixin = <T extends Constructor<HassBaseEl>>(
|
||||||
this.shadowRoot!,
|
this.shadowRoot!,
|
||||||
dialogTag,
|
dialogTag,
|
||||||
(showEv as HASSDomEvent<unknown>).detail,
|
(showEv as HASSDomEvent<unknown>).detail,
|
||||||
dialogImport
|
dialogImport,
|
||||||
|
addHistory
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,6 +10,7 @@ export default <T extends Constructor<HassBaseEl>>(superClass: T) =>
|
||||||
dialogShowEvent: "hass-notification",
|
dialogShowEvent: "hass-notification",
|
||||||
dialogTag: "notification-manager",
|
dialogTag: "notification-manager",
|
||||||
dialogImport: () => import("../managers/notification-manager"),
|
dialogImport: () => import("../managers/notification-manager"),
|
||||||
|
addHistory: false,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue