mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-23 09:16:38 +00:00
Extract navigate mixin (#1865)
* Extract navigate to function * Remove eventsmixin properly and side effects
This commit is contained in:
parent
13c5724d7c
commit
35194cf345
14
src/common/navigate.ts
Normal file
14
src/common/navigate.ts
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
import { fireEvent } from "./dom/fire_event.js";
|
||||||
|
|
||||||
|
export const navigate = (
|
||||||
|
node: HTMLElement,
|
||||||
|
path: string,
|
||||||
|
replace: boolean = false
|
||||||
|
) => {
|
||||||
|
if (replace) {
|
||||||
|
history.replaceState(null, "", path);
|
||||||
|
} else {
|
||||||
|
history.pushState(null, "", path);
|
||||||
|
}
|
||||||
|
fireEvent(node, "location-changed");
|
||||||
|
};
|
@ -1,5 +1,5 @@
|
|||||||
import { dedupingMixin } from "@polymer/polymer/lib/utils/mixin.js";
|
import { dedupingMixin } from "@polymer/polymer/lib/utils/mixin.js";
|
||||||
import EventsMixin from "./events-mixin";
|
import { navigate } from "../common/navigate";
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* @polymerMixin
|
* @polymerMixin
|
||||||
@ -7,14 +7,9 @@ import EventsMixin from "./events-mixin";
|
|||||||
*/
|
*/
|
||||||
export default dedupingMixin(
|
export default dedupingMixin(
|
||||||
(superClass) =>
|
(superClass) =>
|
||||||
class extends EventsMixin(superClass) {
|
class extends superClass {
|
||||||
navigate(path, replace = false) {
|
navigate(...args) {
|
||||||
if (replace) {
|
navigate(this, ...args);
|
||||||
history.replaceState(null, null, path);
|
|
||||||
} else {
|
|
||||||
history.pushState(null, null, path);
|
|
||||||
}
|
|
||||||
this.fire("location-changed");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
@ -52,7 +52,7 @@ class HaConfigDashboard extends NavigateMixin(LocalizeMixin(PolymerElement)) {
|
|||||||
<template is="dom-if" if="[[computeIsLoaded(hass, 'cloud')]]">
|
<template is="dom-if" if="[[computeIsLoaded(hass, 'cloud')]]">
|
||||||
<paper-card>
|
<paper-card>
|
||||||
<a href='/config/cloud' tabindex="-1">
|
<a href='/config/cloud' tabindex="-1">
|
||||||
<paper-item on-click="_navigate">
|
<paper-item>
|
||||||
<paper-item-body two-line="">
|
<paper-item-body two-line="">
|
||||||
[[localize('ui.panel.config.cloud.caption')]]
|
[[localize('ui.panel.config.cloud.caption')]]
|
||||||
<template is="dom-if" if="[[cloudStatus.logged_in]]">
|
<template is="dom-if" if="[[cloudStatus.logged_in]]">
|
||||||
|
@ -8,6 +8,7 @@ import NavigateMixin from "../../../mixins/navigate-mixin.js";
|
|||||||
|
|
||||||
import "./ha-user-picker.js";
|
import "./ha-user-picker.js";
|
||||||
import "./ha-user-editor.js";
|
import "./ha-user-editor.js";
|
||||||
|
import { fireEvent } from "../../../common/dom/fire_event.js";
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* @appliesMixin NavigateMixin
|
* @appliesMixin NavigateMixin
|
||||||
@ -68,8 +69,8 @@ class HaConfigUsers extends NavigateMixin(PolymerElement) {
|
|||||||
_checkRoute(route) {
|
_checkRoute(route) {
|
||||||
if (!route || route.path.substr(0, 6) !== "/users") return;
|
if (!route || route.path.substr(0, 6) !== "/users") return;
|
||||||
|
|
||||||
// prevent list gettung under toolbar
|
// prevent list getting under toolbar
|
||||||
this.fire("iron-resize");
|
fireEvent(this, "iron-resize");
|
||||||
|
|
||||||
this._debouncer = Debouncer.debounce(
|
this._debouncer = Debouncer.debounce(
|
||||||
this._debouncer,
|
this._debouncer,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user