Skip to content

Commit

Permalink
[TASK] Add loading indicator (#9)
Browse files Browse the repository at this point in the history
Resolves: #4
  • Loading branch information
FamousWolf committed Mar 16, 2024
1 parent 785f97f commit abcc03e
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/card.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ export class WeekPlannerCard extends LitElement {
static get properties() {
return {
_days: { type: Array },
_config: { type: Object }
_config: { type: Object },
_isLoading: { type: Boolean }
}
}

Expand Down Expand Up @@ -81,6 +82,10 @@ export class WeekPlannerCard extends LitElement {
<div class="container">
${this._renderDays()}
</div>
${this._isLoading ?
html`<div class="loader"></div>` :
''
}
</div>
</ha-card>
`;
Expand Down Expand Up @@ -151,6 +156,7 @@ export class WeekPlannerCard extends LitElement {
}

this._loading++;
this._isLoading = true;
this._events = {};

let startDate = moment().startOf('day');
Expand Down Expand Up @@ -182,6 +188,7 @@ export class WeekPlannerCard extends LitElement {
if (this._loading === 0) {
clearInterval(checkLoading);
this._updateCard();
this._isLoading = false;

window.setTimeout(() => {
this._updateEvents();
Expand Down
27 changes: 27 additions & 0 deletions src/card.styles.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,33 @@ export default css`
color: var(--secondary-text-color, #aaaaaa);
margin: 0 0 3px 0;
}
.loader {
position: absolute;
top: 16px;
right: 16px;
width: 40px;
height: 40px;
}
.loader:after {
content: " ";
display: block;
width: 24px;
height: 24px;
margin: 4px;
border-radius: 50%;
border: 3px solid var(--primary-text-color);
border-color: var(--primary-text-color) transparent var(--primary-text-color) transparent;
animation: loader 1.2s linear infinite;
}
@keyframes loader {
0% {
transform: rotate(0deg);
}
100% {
transform: rotate(360deg);
}
}
@container weekplanner (width <= 1280px) {
div.container div.day {
Expand Down

0 comments on commit abcc03e

Please sign in to comment.