Keep root state when replacing, fix subpages for menu button on mobile (#8837)

This commit is contained in:
Bram Kragten 2021-04-07 12:25:17 +02:00 committed by GitHub
parent 2aac8c55e7
commit 26c4591baa
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 36 additions and 13 deletions

View File

@ -12,12 +12,16 @@ declare global {
export const navigate = (_node: any, path: string, replace = false) => { export const navigate = (_node: any, path: string, replace = false) => {
if (__DEMO__) { if (__DEMO__) {
if (replace) { if (replace) {
history.replaceState(null, "", `${location.pathname}#${path}`); history.replaceState(
history.state?.root ? { root: true } : null,
"",
`${location.pathname}#${path}`
);
} else { } else {
window.location.hash = path; window.location.hash = path;
} }
} else if (replace) { } else if (replace) {
history.replaceState(null, "", path); history.replaceState(history.state?.root ? { root: true } : null, "", path);
} else { } else {
history.pushState(null, "", path); history.pushState(null, "", path);
} }

View File

@ -89,15 +89,12 @@ class HassSubpage extends LitElement {
box-sizing: border-box; box-sizing: border-box;
} }
ha-menu-button,
ha-icon-button-arrow-prev, ha-icon-button-arrow-prev,
::slotted([slot="toolbar-icon"]) { ::slotted([slot="toolbar-icon"]) {
pointer-events: auto; pointer-events: auto;
} }
ha-icon-button-arrow-prev.hidden {
visibility: hidden;
}
.main-title { .main-title {
margin: 0 0 0 24px; margin: 0 0 0 24px;
line-height: 20px; line-height: 20px;

View File

@ -140,7 +140,7 @@ class HassTabsSubpage extends LitElement {
const showTabs = tabs.length > 1 || !this.narrow; const showTabs = tabs.length > 1 || !this.narrow;
return html` return html`
<div class="toolbar"> <div class="toolbar">
${this.mainPage || history.state?.root ${this.mainPage || (!this.backPath && history.state?.root)
? html` ? html`
<ha-menu-button <ha-menu-button
.hassio=${this.supervisor} .hassio=${this.supervisor}
@ -289,8 +289,10 @@ class HassTabsSubpage extends LitElement {
} }
:host([narrow]) .content.tabs { :host([narrow]) .content.tabs {
height: calc(100% - 128px); height: calc(100% - 2 * var(--header-height));
height: calc(100% - 128px - env(safe-area-inset-bottom)); height: calc(
100% - 2 * var(--header-height) - env(safe-area-inset-bottom)
);
} }
#fab { #fab {

View File

@ -62,7 +62,11 @@ class CloudAccount extends EventsMixin(LocalizeMixin(PolymerElement)) {
color: var(--primary-color); color: var(--primary-color);
} }
</style> </style>
<hass-subpage hass="[[hass]]" header="Home Assistant Cloud"> <hass-subpage
hass="[[hass]]"
narrow="[[narrow]]"
header="Home Assistant Cloud"
>
<div class="content"> <div class="content">
<ha-config-section is-wide="[[isWide]]"> <ha-config-section is-wide="[[isWide]]">
<span slot="header">Home Assistant Cloud</span> <span slot="header">Home Assistant Cloud</span>
@ -167,6 +171,7 @@ class CloudAccount extends EventsMixin(LocalizeMixin(PolymerElement)) {
return { return {
hass: Object, hass: Object,
isWide: Boolean, isWide: Boolean,
narrow: Boolean,
cloudStatus: Object, cloudStatus: Object,
_subscription: { _subscription: {
type: Object, type: Object,

View File

@ -47,6 +47,7 @@ class CloudForgotPassword extends LocalizeMixin(EventsMixin(PolymerElement)) {
</style> </style>
<hass-subpage <hass-subpage
hass="[[hass]]" hass="[[hass]]"
narrow="[[narrow]]"
header="[[localize('ui.panel.config.cloud.forgot_password.title')]]" header="[[localize('ui.panel.config.cloud.forgot_password.title')]]"
> >
<div class="content"> <div class="content">
@ -84,6 +85,7 @@ class CloudForgotPassword extends LocalizeMixin(EventsMixin(PolymerElement)) {
static get properties() { static get properties() {
return { return {
hass: Object, hass: Object,
narrow: Boolean,
email: { email: {
type: String, type: String,
notify: true, notify: true,

View File

@ -128,6 +128,7 @@ class HaConfigCloud extends HassRouterPage {
hass: this.hass, hass: this.hass,
email: this._loginEmail, email: this._loginEmail,
isWide: this.isWide, isWide: this.isWide,
narrow: this.narrow,
cloudStatus: this.cloudStatus, cloudStatus: this.cloudStatus,
flashMessage: this._flashMessage, flashMessage: this._flashMessage,
}); });

View File

@ -85,7 +85,11 @@ class CloudLogin extends LocalizeMixin(
align-self: flex-end; align-self: flex-end;
} }
</style> </style>
<hass-subpage hass="[[hass]]" header="Home Assistant Cloud"> <hass-subpage
hass="[[hass]]"
narrow="[[narrow]]"
header="Home Assistant Cloud"
>
<div class="content"> <div class="content">
<ha-config-section is-wide="[[isWide]]"> <ha-config-section is-wide="[[isWide]]">
<span slot="header">Home Assistant Cloud</span> <span slot="header">Home Assistant Cloud</span>
@ -186,6 +190,7 @@ class CloudLogin extends LocalizeMixin(
return { return {
hass: Object, hass: Object,
isWide: Boolean, isWide: Boolean,
narrow: Boolean,
email: { email: {
type: String, type: String,
notify: true, notify: true,

View File

@ -47,7 +47,7 @@ class CloudRegister extends LocalizeMixin(EventsMixin(PolymerElement)) {
display: none; display: none;
} }
</style> </style>
<hass-subpage hass="[[hass]]" header="[[localize('ui.panel.config.cloud.register.title')]]"> <hass-subpage hass="[[hass]]" narrow="[[narrow]]" header="[[localize('ui.panel.config.cloud.register.title')]]">
<div class="content"> <div class="content">
<ha-config-section is-wide="[[isWide]]"> <ha-config-section is-wide="[[isWide]]">
<span slot="header">[[localize('ui.panel.config.cloud.register.headline')]]</span> <span slot="header">[[localize('ui.panel.config.cloud.register.headline')]]</span>
@ -100,6 +100,7 @@ class CloudRegister extends LocalizeMixin(EventsMixin(PolymerElement)) {
return { return {
hass: Object, hass: Object,
isWide: Boolean, isWide: Boolean,
narrow: Boolean,
email: { email: {
type: String, type: String,
notify: true, notify: true,

View File

@ -68,6 +68,7 @@ export class ZHAAddGroupPage extends LitElement {
return html` return html`
<hass-subpage <hass-subpage
.hass=${this.hass} .hass=${this.hass}
.narrow=${this.narrow}
.header=${this.hass.localize("ui.panel.config.zha.groups.create_group")} .header=${this.hass.localize("ui.panel.config.zha.groups.create_group")}
> >
<ha-config-section .isWide=${!this.narrow}> <ha-config-section .isWide=${!this.narrow}>

View File

@ -103,7 +103,11 @@ export class ZHAGroupPage extends LitElement {
} }
return html` return html`
<hass-subpage .hass=${this.hass} .header=${this.group.name}> <hass-subpage
.hass=${this.hass}
.narrow=${this.narrow}
.header=${this.group.name}
>
<ha-icon-button <ha-icon-button
slot="toolbar-icon" slot="toolbar-icon"
icon="hass:delete" icon="hass:delete"

View File

@ -135,6 +135,7 @@ export class ZHANetworkVisualizationPage extends LitElement {
return html` return html`
<hass-subpage <hass-subpage
.hass=${this.hass} .hass=${this.hass}
.narrow=${this.narrow}
.header=${this.hass.localize( .header=${this.hass.localize(
"ui.panel.config.zha.visualization.header" "ui.panel.config.zha.visualization.header"
)} )}