Skip to content

Commit a0360ee

Browse files
authored
Merge pull request #210 from FamousWolf/187-only-update-html-if-something-changes
[BUGFIX] Only rerender everything when something changes
2 parents eab4649 + 7af40e9 commit a0360ee

File tree

1 file changed

+24
-7
lines changed

1 file changed

+24
-7
lines changed

src/card.js

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ export class WeekPlannerCard extends LitElement {
8484
_legendToggle;
8585
_actions;
8686
_columns;
87+
_loader;
8788

8889
/**
8990
* Get config element
@@ -134,7 +135,6 @@ export class WeekPlannerCard extends LitElement {
134135
return {
135136
_days: { type: Array },
136137
_config: { type: Object },
137-
_isLoading: { type: Boolean },
138138
_error: { type: String },
139139
_currentEventDetails: { type: Object },
140140
_hideCalendars: { type: Array }
@@ -243,6 +243,10 @@ export class WeekPlannerCard extends LitElement {
243243
* @return {Object}
244244
*/
245245
render() {
246+
if (!this._loader) {
247+
this._loader = this._getLoader();
248+
}
249+
246250
if (!this._initialized) {
247251
this._initialized = true;
248252
this._waitForHassAndConfig();
@@ -291,10 +295,7 @@ export class WeekPlannerCard extends LitElement {
291295
${this._renderDays()}
292296
</div>
293297
${this._renderEventDetailsDialog()}
294-
${this._isLoading ?
295-
html`<div class="loader"></div>` :
296-
''
297-
}
298+
${this._loader}
298299
</div>
299300
</ha-card>
300301
`;
@@ -623,6 +624,21 @@ export class WeekPlannerCard extends LitElement {
623624
`;
624625
}
625626

627+
_getLoader() {
628+
const loader = document.createElement('div');
629+
loader.className = 'loader';
630+
loader.style.display = 'none';
631+
return loader;
632+
}
633+
634+
_updateLoader() {
635+
if (this._loading > 0) {
636+
this._loader.style.display = 'inherit';
637+
} else {
638+
this._loader.style.display = 'none';
639+
}
640+
}
641+
626642
_getWeatherIcon(weatherState) {
627643
const condition = weatherState?.condition;
628644
if (!condition) {
@@ -646,6 +662,7 @@ export class WeekPlannerCard extends LitElement {
646662

647663
_subscribeToWeatherForecast() {
648664
this._loading++;
665+
this._updateLoader();
649666
let loadingWeather = true;
650667
this.hass.connection.subscribeMessage((event) => {
651668
this._weatherForecast = event.forecast ?? [];
@@ -666,7 +683,7 @@ export class WeekPlannerCard extends LitElement {
666683
}
667684

668685
this._loading++;
669-
this._isLoading = true;
686+
this._updateLoader();
670687
this._error = '';
671688
this._events = {};
672689
this._calendarEvents = {};
@@ -735,7 +752,7 @@ export class WeekPlannerCard extends LitElement {
735752
if (!this._error) {
736753
this._updateCard();
737754
}
738-
this._isLoading = false;
755+
this._updateLoader();
739756

740757
window.setTimeout(() => {
741758
this._updateEvents();

0 commit comments

Comments
 (0)