suggestions

This commit is contained in:
Bram Kragten 2024-12-11 16:08:03 +01:00
parent 84322a21fe
commit 3436a023f6
5 changed files with 9 additions and 31 deletions

View File

@ -24,16 +24,9 @@ import "@polymer/paper-listbox/paper-listbox";
import type { UnsubscribeFunc } from "home-assistant-js-websocket"; import type { UnsubscribeFunc } from "home-assistant-js-websocket";
import type { CSSResult, CSSResultGroup, PropertyValues } from "lit"; import type { CSSResult, CSSResultGroup, PropertyValues } from "lit";
import { LitElement, css, html, nothing } from "lit"; import { LitElement, css, html, nothing } from "lit";
import { import { customElement, eventOptions, property, state } from "lit/decorators";
customElement,
eventOptions,
property,
query,
state,
} from "lit/decorators";
import { classMap } from "lit/directives/class-map"; import { classMap } from "lit/directives/class-map";
import memoizeOne from "memoize-one"; import memoizeOne from "memoize-one";
import type { PaperListboxElement } from "@polymer/paper-listbox";
import { storage } from "../common/decorators/storage"; import { storage } from "../common/decorators/storage";
import { fireEvent } from "../common/dom/fire_event"; import { fireEvent } from "../common/dom/fire_event";
import { toggleAttribute } from "../common/dom/toggle_attribute"; import { toggleAttribute } from "../common/dom/toggle_attribute";
@ -55,6 +48,7 @@ import "./ha-menu-button";
import "./ha-sortable"; import "./ha-sortable";
import "./ha-svg-icon"; import "./ha-svg-icon";
import "./user/ha-user-badge"; import "./user/ha-user-badge";
import { preventDefault } from "../common/dom/prevent_default";
const SHOW_AFTER_SPACER = ["config", "developer-tools"]; const SHOW_AFTER_SPACER = ["config", "developer-tools"];
@ -203,8 +197,6 @@ class HaSidebar extends SubscribeMixin(LitElement) {
@state() private _issuesCount = 0; @state() private _issuesCount = 0;
@query("paper-listbox", true) private _sidebar!: PaperListboxElement;
private _mouseLeaveTimeout?: number; private _mouseLeaveTimeout?: number;
private _tooltipHideTimeout?: number; private _tooltipHideTimeout?: number;
@ -296,10 +288,6 @@ class HaSidebar extends SubscribeMixin(LitElement) {
protected firstUpdated(changedProps: PropertyValues) { protected firstUpdated(changedProps: PropertyValues) {
super.firstUpdated(changedProps); super.firstUpdated(changedProps);
this._subscribePersistentNotifications(); this._subscribePersistentNotifications();
window.addEventListener("hass-reset-sidebar", (ev) => {
this._sidebar.selected = ev.detail;
});
} }
private _subscribePersistentNotifications(): void { private _subscribePersistentNotifications(): void {
@ -417,6 +405,7 @@ class HaSidebar extends SubscribeMixin(LitElement) {
@focusout=${this._listboxFocusOut} @focusout=${this._listboxFocusOut}
@scroll=${this._listboxScroll} @scroll=${this._listboxScroll}
@keydown=${this._listboxKeydown} @keydown=${this._listboxKeydown}
@iron-activate=${preventDefault}
> >
${this.editMode ${this.editMode
? this._renderPanelsEdit(beforeSpacer) ? this._renderPanelsEdit(beforeSpacer)
@ -1137,8 +1126,4 @@ declare global {
interface HTMLElementTagNameMap { interface HTMLElementTagNameMap {
"ha-sidebar": HaSidebar; "ha-sidebar": HaSidebar;
} }
interface HASSDomEvents {
"hass-reset-sidebar": string;
}
} }

View File

@ -1,7 +1,6 @@
import type { LitElement, PropertyValues } from "lit"; import type { LitElement, PropertyValues } from "lit";
import type { Constructor } from "../types";
import { isNavigationClick } from "../common/dom/is-navigation-click"; import { isNavigationClick } from "../common/dom/is-navigation-click";
import { fireEvent } from "../common/dom/fire_event"; import type { Constructor } from "../types";
export const PreventUnsavedMixin = <T extends Constructor<LitElement>>( export const PreventUnsavedMixin = <T extends Constructor<LitElement>>(
superClass: T superClass: T
@ -21,8 +20,6 @@ export const PreventUnsavedMixin = <T extends Constructor<LitElement>>(
const newEvent = new MouseEvent(e.type, e); const newEvent = new MouseEvent(e.type, e);
target.dispatchEvent(newEvent); target.dispatchEvent(newEvent);
} }
} else {
fireEvent(this, "hass-reset-sidebar", this.getPanel());
} }
}; };
@ -36,7 +33,7 @@ export const PreventUnsavedMixin = <T extends Constructor<LitElement>>(
public willUpdate(changedProperties: PropertyValues): void { public willUpdate(changedProperties: PropertyValues): void {
super.willUpdate(changedProperties); super.willUpdate(changedProperties);
if (this.isDirty()) { if (this.isDirty) {
window.addEventListener("click", this._handleClick, true); window.addEventListener("click", this._handleClick, true);
window.addEventListener("beforeunload", this._handleUnload); window.addEventListener("beforeunload", this._handleUnload);
} else { } else {
@ -50,15 +47,11 @@ export const PreventUnsavedMixin = <T extends Constructor<LitElement>>(
this._removeListeners(); this._removeListeners();
} }
protected isDirty(): boolean { protected get isDirty(): boolean {
return false; return false;
} }
protected async promptDiscardChanges(): Promise<boolean> { protected async promptDiscardChanges(): Promise<boolean> {
return true; return true;
} }
protected getPanel(): string {
return "config";
}
}; };

View File

@ -850,7 +850,7 @@ export class HaAutomationEditor extends PreventUnsavedMixin(
}; };
} }
protected isDirty() { protected get isDirty() {
return this._dirty; return this._dirty;
} }

View File

@ -1226,7 +1226,7 @@ export class HaSceneEditor extends PreventUnsavedMixin(
}); });
} }
protected isDirty() { protected get isDirty() {
return this._dirty; return this._dirty;
} }

View File

@ -816,7 +816,7 @@ export class HaScriptEditor extends PreventUnsavedMixin(
}; };
} }
protected isDirty() { protected get isDirty() {
return this._dirty; return this._dirty;
} }