diff --git a/src/components/ha-sidebar.ts b/src/components/ha-sidebar.ts index 2f1f473ca4..717d376544 100644 --- a/src/components/ha-sidebar.ts +++ b/src/components/ha-sidebar.ts @@ -202,195 +202,17 @@ class HaSidebar extends LitElement { private _sortable?; protected render() { - const hass = this.hass; - - if (!hass) { + if (!this.hass) { return html``; } - const [beforeSpacer, afterSpacer] = computePanels( - hass.panels, - hass.defaultPanel, - this._panelOrder, - this._hiddenPanels - ); - - let notificationCount = this._notifications - ? this._notifications.length - : 0; - for (const entityId in hass.states) { - if (computeDomain(entityId) === "configurator") { - notificationCount++; - } - } - + // prettier-ignore return html` - - - ${this.editMode - ? html`
- ${guard([this._hiddenPanels, this._renderEmptySortable], () => - this._renderEmptySortable - ? "" - : this._renderPanels(beforeSpacer) - )} -
` - : this._renderPanels(beforeSpacer)} -
- ${this.editMode && this._hiddenPanels.length - ? html` - ${this._hiddenPanels.map((url) => { - const panel = this.hass.panels[url]; - if (!panel) { - return ""; - } - return html` - - ${panel.url_path === this.hass.defaultPanel - ? hass.localize("panel.states") - : hass.localize(`panel.${panel.title}`) || - panel.title} - - - - `; - })} -
- ` - : ""} - ${this._renderPanels(afterSpacer)} - ${this._externalConfig && this._externalConfig.hasSettingsScreen - ? html` - - - - - ${hass.localize("ui.sidebar.external_app_configuration")} - - - - ` - : ""} -
- -
- -
- - - ${!this.expanded && notificationCount > 0 - ? html` - - ${notificationCount} - - ` - : ""} - - ${hass.localize("ui.notification_drawer.title")} - - ${this.expanded && notificationCount > 0 - ? html` - ${notificationCount} - ` - : ""} - -
- - - - - - - ${hass.user ? hass.user.name : ""} - - - + ${this._renderHeader()} + ${this._renderAllPanels()} + ${this._renderDivider()} + ${this._renderNotifications()} + ${this._renderUserItem()}
`; @@ -475,6 +297,215 @@ class HaSidebar extends LitElement { } } + private _renderHeader() { + return html``; + } + + private _renderAllPanels() { + const [beforeSpacer, afterSpacer] = computePanels( + this.hass.panels, + this.hass.defaultPanel, + this._panelOrder, + this._hiddenPanels + ); + + // prettier-ignore + return html` + + ${this.editMode + ? this._renderPanelsEdit(beforeSpacer) + : this._renderPanels(beforeSpacer)} + ${this._renderSpacer()} + ${this._renderPanels(afterSpacer)} + ${this._renderExternalConfiguration()} + + `; + } + + private _renderPanelsEdit(beforeSpacer: PanelInfo[]) { + // prettier-ignore + return html`
+ ${guard([this._hiddenPanels, this._renderEmptySortable], () => + this._renderEmptySortable ? "" : this._renderPanels(beforeSpacer) + )} +
+ ${this._renderSpacer()} + ${this._renderHiddenPanels()} `; + } + + private _renderHiddenPanels() { + return html` ${this._hiddenPanels.length + ? html`${this._hiddenPanels.map((url) => { + const panel = this.hass.panels[url]; + if (!panel) { + return ""; + } + return html` + + ${panel.url_path === this.hass.defaultPanel + ? this.hass.localize("panel.states") + : this.hass.localize(`panel.${panel.title}`) || + panel.title} + + + + `; + })} + ${this._renderSpacer()}` + : ""}`; + } + + private _renderDivider() { + return html`
`; + } + + private _renderSpacer() { + return html`
`; + } + + private _renderNotifications() { + let notificationCount = this._notifications + ? this._notifications.length + : 0; + for (const entityId in this.hass.states) { + if (computeDomain(entityId) === "configurator") { + notificationCount++; + } + } + + return html`
+ + + ${!this.expanded && notificationCount > 0 + ? html` + + ${notificationCount} + + ` + : ""} + + ${this.hass.localize("ui.notification_drawer.title")} + + ${this.expanded && notificationCount > 0 + ? html` ${notificationCount} ` + : ""} + +
`; + } + + private _renderUserItem() { + return html` + + + + + ${this.hass.user ? this.hass.user.name : ""} + + + `; + } + + private _renderExternalConfiguration() { + return html`${this._externalConfig && this._externalConfig.hasSettingsScreen + ? html` + + + + + ${this.hass.localize("ui.sidebar.external_app_configuration")} + + + + ` + : ""}`; + } + private get _tooltip() { return this.shadowRoot!.querySelector(".tooltip")! as HTMLDivElement; }