Skip to content

Commit

Permalink
minor patches to countdown and spinner components
Browse files Browse the repository at this point in the history
  • Loading branch information
roncodes committed Jan 16, 2024
1 parent 73fe4f2 commit 089f7b9
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 13 deletions.
46 changes: 35 additions & 11 deletions addon/components/countdown.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,17 +54,15 @@ export default class CountdownComponent extends Component {
constructor(owner, { expiry, hours, minutes, seconds, days, display }) {
super(...arguments);

this.duration = {
days,
hours,
minutes,
seconds,
};

if (expiry instanceof Date) {
// use the date provided to set the hours minutes seconds
this.duration = intervalToDuration({ start: new Date(), end: expiry });
}
this.setDuration(
{
days,
hours,
minutes,
seconds,
},
expiry
);

if (display) {
if (typeof display === 'string' && display.includes(',')) {
Expand All @@ -88,6 +86,24 @@ export default class CountdownComponent extends Component {
}
}

setDuration(duration = {}, expiry) {
if (expiry instanceof Date) {
// use the date provided to set the hours minutes seconds
duration = intervalToDuration({ start: new Date(), end: expiry });
}

// handle when only 2 minutes
if (duration && duration.minutes < 3) {
duration = {
...duration,
seconds: duration.seconds + duration.minutes * 60,
minutes: 0,
};
}

this.duration = duration;
}

/**
* Starts the countdown timer.
*
Expand Down Expand Up @@ -115,6 +131,14 @@ export default class CountdownComponent extends Component {
if (duration.seconds < 0) {
duration.seconds = 0; // Stop the countdown at 0
clearInterval(this.interval);

if (typeof this.args.onCountdownEnd === 'function') {
this.args.onCountdownEnd();
}

if (typeof this.args.onEnd === 'function') {
this.args.onEnd();
}
}
});
}, 1000);
Expand Down
4 changes: 2 additions & 2 deletions addon/components/spinner.hbs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<div class="fleetbase-loader-wrapper {{@wrapperClass}}" ...attributes>
<span class="fleetbase-loader {{@iconClass}}" {{set-width (or @width 16)}} {{set-height (or @height 16)}}></span>
{{#if (has-block)}}
<div class="loading-message">{{yield}}</div>
<div class="loading-message {{@loadingMessageClass}}">{{yield}}</div>
{{else}}
<div class="loading-message">{{or @text @loadingMessage @message}}</div>
<div class="loading-message {{@loadingMessageClass}}">{{or @text @loadingMessage @message}}</div>
{{/if}}
</div>

0 comments on commit 089f7b9

Please sign in to comment.