diff --git a/addon/components/countdown.js b/addon/components/countdown.js index e9dede9..e1efbc6 100644 --- a/addon/components/countdown.js +++ b/addon/components/countdown.js @@ -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(',')) { @@ -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. * @@ -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); diff --git a/addon/components/spinner.hbs b/addon/components/spinner.hbs index 015111e..ccc3f14 100644 --- a/addon/components/spinner.hbs +++ b/addon/components/spinner.hbs @@ -1,8 +1,8 @@
{{#if (has-block)}} -
{{yield}}
+
{{yield}}
{{else}} -
{{or @text @loadingMessage @message}}
+
{{or @text @loadingMessage @message}}
{{/if}}
\ No newline at end of file