mirror of
https://github.com/home-assistant/frontend.git
synced 2025-12-20 02:38:53 +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:
@@ -336,9 +336,7 @@ class HaConfigIntegrationsDashboard extends KeyboardShortcutMixin(
|
|||||||
super.firstUpdated(changed);
|
super.firstUpdated(changed);
|
||||||
this._fetchManifests();
|
this._fetchManifests();
|
||||||
this._fetchEntitySources();
|
this._fetchEntitySources();
|
||||||
if (this.route.path === "/add") {
|
this._handleRouteChanged();
|
||||||
this._handleAdd();
|
|
||||||
}
|
|
||||||
this._scanUSBDevices();
|
this._scanUSBDevices();
|
||||||
this._scanImprovDevices();
|
this._scanImprovDevices();
|
||||||
|
|
||||||
@@ -355,6 +353,9 @@ class HaConfigIntegrationsDashboard extends KeyboardShortcutMixin(
|
|||||||
|
|
||||||
protected updated(changed: PropertyValues) {
|
protected updated(changed: PropertyValues) {
|
||||||
super.updated(changed);
|
super.updated(changed);
|
||||||
|
if (changed.has("route")) {
|
||||||
|
this._handleRouteChanged();
|
||||||
|
}
|
||||||
if (
|
if (
|
||||||
(this._searchParms.has("config_entry") ||
|
(this._searchParms.has("config_entry") ||
|
||||||
this._searchParms.has("domain")) &&
|
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 brand = extractSearchParam("brand");
|
||||||
const domain = extractSearchParam("domain");
|
const domain = extractSearchParam("domain");
|
||||||
navigate("/config/integrations", { replace: true });
|
navigate("/config/integrations/dashboard/", { replace: true });
|
||||||
|
|
||||||
if (brand) {
|
if (brand) {
|
||||||
showAddIntegrationDialog(this, {
|
showAddIntegrationDialog(this, {
|
||||||
|
|||||||
@@ -655,8 +655,13 @@ class HUIRoot extends LitElement {
|
|||||||
this.toggleAttribute("scrolled", window.scrollY !== 0);
|
this.toggleAttribute("scrolled", window.scrollY !== 0);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
private _locationChanged = () => {
|
||||||
|
this._handleUrlChanged();
|
||||||
|
};
|
||||||
|
|
||||||
private _handlePopState = () => {
|
private _handlePopState = () => {
|
||||||
this._restoreScroll = true;
|
this._restoreScroll = true;
|
||||||
|
this._handleUrlChanged();
|
||||||
};
|
};
|
||||||
|
|
||||||
private _isVisible = (view: LovelaceViewConfig) =>
|
private _isVisible = (view: LovelaceViewConfig) =>
|
||||||
@@ -678,6 +683,34 @@ class HUIRoot extends LitElement {
|
|||||||
|
|
||||||
protected firstUpdated(changedProps: PropertyValues) {
|
protected firstUpdated(changedProps: PropertyValues) {
|
||||||
super.firstUpdated(changedProps);
|
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
|
// Check for requested edit mode
|
||||||
const searchParams = extractSearchParamsObject();
|
const searchParams = extractSearchParamsObject();
|
||||||
if (searchParams.edit === "1") {
|
if (searchParams.edit === "1") {
|
||||||
@@ -697,29 +730,6 @@ class HUIRoot extends LitElement {
|
|||||||
this._showMoreInfoDialog(entityId);
|
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 {
|
protected willUpdate(changedProperties: PropertyValues): void {
|
||||||
|
|||||||
Reference in New Issue
Block a user