Clear view cache edit mode (#2291)

* Clear view cache when canceling edit mode

* Fix enabling edit mode on not first view
This commit is contained in:
Paulus Schoutsen 2018-12-13 21:46:50 +01:00 committed by GitHub
parent 0dfca2f33b
commit 47635055d0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -93,6 +93,8 @@ class HUIRoot extends hassLocalizeLitMixin(LitElement) {
constructor() { constructor() {
super(); super();
// The view can trigger a re-render when it knows that certain
// web components have been loaded.
this._debouncedConfigChanged = debounce( this._debouncedConfigChanged = debounce(
() => this._selectView(this._curView, true), () => this._selectView(this._curView, true),
100 100
@ -380,7 +382,7 @@ class HUIRoot extends hassLocalizeLitMixin(LitElement) {
protected updated(changedProperties: PropertyValues): void { protected updated(changedProperties: PropertyValues): void {
super.updated(changedProperties); super.updated(changedProperties);
const view = this._view; const view = this._viewRoot;
const huiView = view.lastChild as HUIView; const huiView = view.lastChild as HUIView;
if (changedProperties.has("columns") && huiView) { if (changedProperties.has("columns") && huiView) {
@ -424,18 +426,21 @@ class HUIRoot extends hassLocalizeLitMixin(LitElement) {
| undefined; | undefined;
if (!oldLovelace || oldLovelace.config !== this.lovelace!.config) { if (!oldLovelace || oldLovelace.config !== this.lovelace!.config) {
this._viewCache = {};
this._loadResources(this.lovelace!.config.resources || []); this._loadResources(this.lovelace!.config.resources || []);
// On config change, recreate the view from scratch. // On config change, recreate the current view from scratch.
force = true; force = true;
} }
if (!oldLovelace || oldLovelace.editMode !== this.lovelace!.editMode) { if (!oldLovelace || oldLovelace.editMode !== this.lovelace!.editMode) {
// On edit mode change, recreate the current view from scratch
force = true; force = true;
} }
} }
if (newSelectView !== undefined || force) { if (newSelectView !== undefined || force) {
if (force && newSelectView === undefined) {
newSelectView = this._curView;
}
this._selectView(newSelectView, force); this._selectView(newSelectView, force);
} }
} }
@ -463,7 +468,7 @@ class HUIRoot extends hassLocalizeLitMixin(LitElement) {
return this.shadowRoot!.getElementById("layout"); return this.shadowRoot!.getElementById("layout");
} }
private get _view(): HTMLDivElement { private get _viewRoot(): HTMLDivElement {
return this.shadowRoot!.getElementById("view") as HTMLDivElement; return this.shadowRoot!.getElementById("view") as HTMLDivElement;
} }
@ -535,11 +540,8 @@ class HUIRoot extends hassLocalizeLitMixin(LitElement) {
} }
private _handleViewSelected(ev) { private _handleViewSelected(ev) {
const index = ev.detail.selected; const viewIndex = ev.detail.selected as number;
this._navigateView(index);
}
private _navigateView(viewIndex: number): void {
if (viewIndex !== this._curView) { if (viewIndex !== this._curView) {
const path = this.config.views[viewIndex].path || viewIndex; const path = this.config.views[viewIndex].path || viewIndex;
navigate(this, `/lovelace/${path}`); navigate(this, `/lovelace/${path}`);
@ -559,8 +561,12 @@ class HUIRoot extends hassLocalizeLitMixin(LitElement) {
this._curView = viewIndex; this._curView = viewIndex;
if (force) {
this._viewCache = {};
}
// Recreate a new element to clear the applied themes. // Recreate a new element to clear the applied themes.
const root = this._view; const root = this._viewRoot;
if (root.lastChild) { if (root.lastChild) {
root.removeChild(root.lastChild); root.removeChild(root.lastChild);