1
0
mirror of https://github.com/home-assistant/frontend.git synced 2025-12-19 18:28:42 +00:00

Handle search params changed after first updated for dashboards and … (#28375)

handle search params changed after first updated for dashboards and integrations
This commit is contained in:
Bram Kragten
2025-12-06 12:45:44 +01:00
committed by GitHub
parent 7dda8c36bc
commit d1011d691f
2 changed files with 42 additions and 28 deletions

View File

@@ -336,9 +336,7 @@ class HaConfigIntegrationsDashboard extends KeyboardShortcutMixin(
super.firstUpdated(changed);
this._fetchManifests();
this._fetchEntitySources();
if (this.route.path === "/add") {
this._handleAdd();
}
this._handleRouteChanged();
this._scanUSBDevices();
this._scanImprovDevices();
@@ -355,6 +353,9 @@ class HaConfigIntegrationsDashboard extends KeyboardShortcutMixin(
protected updated(changed: PropertyValues) {
super.updated(changed);
if (changed.has("route")) {
this._handleRouteChanged();
}
if (
(this._searchParms.has("config_entry") ||
this._searchParms.has("domain")) &&
@@ -813,10 +814,13 @@ class HaConfigIntegrationsDashboard extends KeyboardShortcutMixin(
}
}
private async _handleAdd() {
private async _handleRouteChanged() {
if (this.route?.path !== "/add") {
return;
}
const brand = extractSearchParam("brand");
const domain = extractSearchParam("domain");
navigate("/config/integrations", { replace: true });
navigate("/config/integrations/dashboard/", { replace: true });
if (brand) {
showAddIntegrationDialog(this, {

View File

@@ -655,8 +655,13 @@ class HUIRoot extends LitElement {
this.toggleAttribute("scrolled", window.scrollY !== 0);
};
private _locationChanged = () => {
this._handleUrlChanged();
};
private _handlePopState = () => {
this._restoreScroll = true;
this._handleUrlChanged();
};
private _isVisible = (view: LovelaceViewConfig) =>
@@ -678,6 +683,34 @@ class HUIRoot extends LitElement {
protected firstUpdated(changedProps: PropertyValues) {
super.firstUpdated(changedProps);
window.addEventListener("scroll", this._handleWindowScroll, {
passive: true,
});
this._handleUrlChanged();
}
public connectedCallback(): void {
super.connectedCallback();
window.addEventListener("scroll", this._handleWindowScroll, {
passive: true,
});
window.addEventListener("popstate", this._handlePopState);
window.addEventListener("location-changed", this._locationChanged);
// Disable history scroll restoration because it is managed manually here
window.history.scrollRestoration = "manual";
}
public disconnectedCallback(): void {
super.disconnectedCallback();
window.removeEventListener("scroll", this._handleWindowScroll);
window.removeEventListener("popstate", this._handlePopState);
window.removeEventListener("location-changed", this._locationChanged);
this.toggleAttribute("scrolled", window.scrollY !== 0);
// Re-enable history scroll restoration when leaving the page
window.history.scrollRestoration = "auto";
}
private _handleUrlChanged() {
// Check for requested edit mode
const searchParams = extractSearchParamsObject();
if (searchParams.edit === "1") {
@@ -697,29 +730,6 @@ class HUIRoot extends LitElement {
this._showMoreInfoDialog(entityId);
});
}
window.addEventListener("scroll", this._handleWindowScroll, {
passive: true,
});
}
public connectedCallback(): void {
super.connectedCallback();
window.addEventListener("scroll", this._handleWindowScroll, {
passive: true,
});
window.addEventListener("popstate", this._handlePopState);
// Disable history scroll restoration because it is managed manually here
window.history.scrollRestoration = "manual";
}
public disconnectedCallback(): void {
super.disconnectedCallback();
window.removeEventListener("scroll", this._handleWindowScroll);
window.removeEventListener("popstate", this._handlePopState);
this.toggleAttribute("scrolled", window.scrollY !== 0);
// Re-enable history scroll restoration when leaving the page
window.history.scrollRestoration = "auto";
}
protected willUpdate(changedProperties: PropertyValues): void {