@@ -84,6 +84,7 @@ export class WeekPlannerCard extends LitElement {
84
84
_legendToggle ;
85
85
_actions ;
86
86
_columns ;
87
+ _loader ;
87
88
88
89
/**
89
90
* Get config element
@@ -134,7 +135,6 @@ export class WeekPlannerCard extends LitElement {
134
135
return {
135
136
_days : { type : Array } ,
136
137
_config : { type : Object } ,
137
- _isLoading : { type : Boolean } ,
138
138
_error : { type : String } ,
139
139
_currentEventDetails : { type : Object } ,
140
140
_hideCalendars : { type : Array }
@@ -243,6 +243,10 @@ export class WeekPlannerCard extends LitElement {
243
243
* @return {Object }
244
244
*/
245
245
render ( ) {
246
+ if ( ! this . _loader ) {
247
+ this . _loader = this . _getLoader ( ) ;
248
+ }
249
+
246
250
if ( ! this . _initialized ) {
247
251
this . _initialized = true ;
248
252
this . _waitForHassAndConfig ( ) ;
@@ -291,10 +295,7 @@ export class WeekPlannerCard extends LitElement {
291
295
${ this . _renderDays ( ) }
292
296
</ div >
293
297
${ this . _renderEventDetailsDialog ( ) }
294
- ${ this . _isLoading ?
295
- html `< div class ="loader "> </ div > ` :
296
- ''
297
- }
298
+ ${ this . _loader }
298
299
</ div >
299
300
</ ha-card >
300
301
` ;
@@ -623,6 +624,21 @@ export class WeekPlannerCard extends LitElement {
623
624
` ;
624
625
}
625
626
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
+
626
642
_getWeatherIcon ( weatherState ) {
627
643
const condition = weatherState ?. condition ;
628
644
if ( ! condition ) {
@@ -646,6 +662,7 @@ export class WeekPlannerCard extends LitElement {
646
662
647
663
_subscribeToWeatherForecast ( ) {
648
664
this . _loading ++ ;
665
+ this . _updateLoader ( ) ;
649
666
let loadingWeather = true ;
650
667
this . hass . connection . subscribeMessage ( ( event ) => {
651
668
this . _weatherForecast = event . forecast ?? [ ] ;
@@ -666,7 +683,7 @@ export class WeekPlannerCard extends LitElement {
666
683
}
667
684
668
685
this . _loading ++ ;
669
- this . _isLoading = true ;
686
+ this . _updateLoader ( ) ;
670
687
this . _error = '' ;
671
688
this . _events = { } ;
672
689
this . _calendarEvents = { } ;
@@ -735,7 +752,7 @@ export class WeekPlannerCard extends LitElement {
735
752
if ( ! this . _error ) {
736
753
this . _updateCard ( ) ;
737
754
}
738
- this . _isLoading = false ;
755
+ this . _updateLoader ( ) ;
739
756
740
757
window . setTimeout ( ( ) => {
741
758
this . _updateEvents ( ) ;
0 commit comments