Skip to content

Commit

Permalink
suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
bramkragten committed Dec 11, 2024
1 parent 84322a2 commit 3436a02
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 31 deletions.
21 changes: 3 additions & 18 deletions src/components/ha-sidebar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,9 @@ import "@polymer/paper-listbox/paper-listbox";
import type { UnsubscribeFunc } from "home-assistant-js-websocket";
import type { CSSResult, CSSResultGroup, PropertyValues } from "lit";
import { LitElement, css, html, nothing } from "lit";
import {
customElement,
eventOptions,
property,
query,
state,
} from "lit/decorators";
import { customElement, eventOptions, property, state } from "lit/decorators";
import { classMap } from "lit/directives/class-map";
import memoizeOne from "memoize-one";
import type { PaperListboxElement } from "@polymer/paper-listbox";
import { storage } from "../common/decorators/storage";
import { fireEvent } from "../common/dom/fire_event";
import { toggleAttribute } from "../common/dom/toggle_attribute";
Expand All @@ -55,6 +48,7 @@ import "./ha-menu-button";
import "./ha-sortable";
import "./ha-svg-icon";
import "./user/ha-user-badge";
import { preventDefault } from "../common/dom/prevent_default";

const SHOW_AFTER_SPACER = ["config", "developer-tools"];

Expand Down Expand Up @@ -203,8 +197,6 @@ class HaSidebar extends SubscribeMixin(LitElement) {

@state() private _issuesCount = 0;

@query("paper-listbox", true) private _sidebar!: PaperListboxElement;

private _mouseLeaveTimeout?: number;

private _tooltipHideTimeout?: number;
Expand Down Expand Up @@ -296,10 +288,6 @@ class HaSidebar extends SubscribeMixin(LitElement) {
protected firstUpdated(changedProps: PropertyValues) {
super.firstUpdated(changedProps);
this._subscribePersistentNotifications();

window.addEventListener("hass-reset-sidebar", (ev) => {
this._sidebar.selected = ev.detail;
});
}

private _subscribePersistentNotifications(): void {
Expand Down Expand Up @@ -417,6 +405,7 @@ class HaSidebar extends SubscribeMixin(LitElement) {
@focusout=${this._listboxFocusOut}
@scroll=${this._listboxScroll}
@keydown=${this._listboxKeydown}
@iron-activate=${preventDefault}
>
${this.editMode
? this._renderPanelsEdit(beforeSpacer)
Expand Down Expand Up @@ -1137,8 +1126,4 @@ declare global {
interface HTMLElementTagNameMap {
"ha-sidebar": HaSidebar;
}

interface HASSDomEvents {
"hass-reset-sidebar": string;
}
}
13 changes: 3 additions & 10 deletions src/mixins/prevent-unsaved-mixin.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import type { LitElement, PropertyValues } from "lit";
import type { Constructor } from "../types";
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>>(
superClass: T
Expand All @@ -21,8 +20,6 @@ export const PreventUnsavedMixin = <T extends Constructor<LitElement>>(
const newEvent = new MouseEvent(e.type, e);
target.dispatchEvent(newEvent);
}
} else {
fireEvent(this, "hass-reset-sidebar", this.getPanel());
}
};

Expand All @@ -36,7 +33,7 @@ export const PreventUnsavedMixin = <T extends Constructor<LitElement>>(
public willUpdate(changedProperties: PropertyValues): void {
super.willUpdate(changedProperties);

if (this.isDirty()) {
if (this.isDirty) {
window.addEventListener("click", this._handleClick, true);
window.addEventListener("beforeunload", this._handleUnload);
} else {
Expand All @@ -50,15 +47,11 @@ export const PreventUnsavedMixin = <T extends Constructor<LitElement>>(
this._removeListeners();
}

protected isDirty(): boolean {
protected get isDirty(): boolean {
return false;
}

protected async promptDiscardChanges(): Promise<boolean> {
return true;
}

protected getPanel(): string {
return "config";
}
};
2 changes: 1 addition & 1 deletion src/panels/config/automation/ha-automation-editor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -850,7 +850,7 @@ export class HaAutomationEditor extends PreventUnsavedMixin(
};
}

protected isDirty() {
protected get isDirty() {
return this._dirty;
}

Expand Down
2 changes: 1 addition & 1 deletion src/panels/config/scene/ha-scene-editor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1226,7 +1226,7 @@ export class HaSceneEditor extends PreventUnsavedMixin(
});
}

protected isDirty() {
protected get isDirty() {
return this._dirty;
}

Expand Down
2 changes: 1 addition & 1 deletion src/panels/config/script/ha-script-editor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -816,7 +816,7 @@ export class HaScriptEditor extends PreventUnsavedMixin(
};
}

protected isDirty() {
protected get isDirty() {
return this._dirty;
}

Expand Down

0 comments on commit 3436a02

Please sign in to comment.