feat(event): more datetime countdown improvements

This commit is contained in:
Sabe Jones
2021-04-08 15:43:47 -05:00
parent 5ffdf09be4
commit 23f6e9b911
9 changed files with 65 additions and 62 deletions

View File

@@ -318,27 +318,6 @@
opacity: 0.55; opacity: 0.55;
} }
.limitedTime {
height: 32px;
background-color: $purple-300;
width: calc(100% + 30px);
margin: 0 -15px; // the modal content has its own padding
font-size: 12px;
line-height: 1.33;
text-align: center;
color: $white;
display: flex;
align-items: center;
justify-content: center;
.limitedString {
height: 16px;
margin-left: 8px;
}
}
.attributesGrid { .attributesGrid {
margin-top: 8px; margin-top: 8px;
border-radius: 2px; border-radius: 2px;

View File

@@ -1,8 +1,11 @@
<template> <template>
<div class="limitedTime"> <div
class="limitedTime"
:class="availabilityClass"
>
<span <span
class="svg-icon inline icon-16" class="svg-icon inline icon-16"
v-html="icons.clock" v-html="availabilityClass === 'expired' ? icons.clockWhite : icons.clock"
></span> ></span>
<span class="limitedString"> {{ limitedString }} </span> <span class="limitedString"> {{ limitedString }} </span>
</div> </div>
@@ -13,7 +16,6 @@
.limitedTime { .limitedTime {
height: 32px; height: 32px;
background-color: $purple-300;
width: calc(100% + 30px); width: calc(100% + 30px);
margin: 0 -15px; // the modal content has its own padding margin: 0 -15px; // the modal content has its own padding
@@ -31,46 +33,65 @@
margin-left: 8px; margin-left: 8px;
} }
} }
.available {
background-color: $purple-300;
}
.expired {
background-color: $gray-200;
}
</style> </style>
<script> <script>
import moment from 'moment'; import moment from 'moment';
import svgClock from '@/assets/svg/clock.svg'; import svgClock from '@/assets/svg/clock.svg';
import clockWhite from '@/assets/svg/clock-white.svg';
export default { export default {
props: { props: {
endDate: { endDate: {
type: String, type: Object, // moment
}, },
}, },
data () { data () {
return { return {
icons: Object.freeze({ icons: Object.freeze({
clock: svgClock, clock: svgClock,
clockWhite,
}), }),
timer: '', timer: '',
limitedString: '', limitedString: '',
availabilityClass: 'available',
}; };
}, },
mounted () { mounted () {
this.countdownString(); this.countdownString();
this.timer = setInterval(this.countdownString, 30000); this.timer = setInterval(this.countdownString, 1000);
}, },
methods: { methods: {
countdownString () { countdownString () {
const diffDuration = moment.duration(moment(this.endDate).diff(moment())); const diffDuration = moment.duration(moment(this.endDate).diff(moment()));
if (diffDuration.days() > 0) { if (moment(this.endDate).isBefore()) {
this.limitedString = this.$t('noLongerAvailable');
this.availabilityClass = 'expired';
this.cancelAutoUpdate();
} else if (diffDuration.days() > 0) {
this.limitedString = this.$t('limitedAvailabilityDays', { this.limitedString = this.$t('limitedAvailabilityDays', {
days: diffDuration.days(), days: diffDuration.days(),
hours: diffDuration.hours(), hours: diffDuration.hours(),
minutes: diffDuration.minutes(), minutes: diffDuration.minutes(),
}); });
} else { } else if (diffDuration.asMinutes() > 2) {
this.limitedString = this.$t('limitedAvailabilityHours', { this.limitedString = this.$t('limitedAvailabilityHours', {
hours: diffDuration.hours(), hours: diffDuration.hours(),
minutes: diffDuration.minutes(), minutes: diffDuration.minutes(),
}); });
} else {
this.limitedString = this.$t('limitedAvailabilityMinutes', {
minutes: diffDuration.minutes(),
seconds: diffDuration.seconds(),
});
} }
}, },
cancelAutoUpdate () { cancelAutoUpdate () {

View File

@@ -108,7 +108,7 @@ export default {
}, },
mounted () { mounted () {
this.countdownString(); this.countdownString();
this.timer = setInterval(this.countdownString, 30000); this.timer = setInterval(this.countdownString, 1000);
}, },
methods: { methods: {
itemSelected (item) { itemSelected (item) {
@@ -117,17 +117,24 @@ export default {
countdownString () { countdownString () {
const diffDuration = moment.duration(moment(seasonalShopConfig.dateRange.end).diff(moment())); const diffDuration = moment.duration(moment(seasonalShopConfig.dateRange.end).diff(moment()));
if (diffDuration.days() > 0) { if (diffDuration.asSeconds() <= 0) {
this.limitedString = this.$t('noLongerAvailable');
} else if (diffDuration.days() > 0) {
this.limitedString = this.$t('limitedAvailabilityDays', { this.limitedString = this.$t('limitedAvailabilityDays', {
days: diffDuration.days(), days: diffDuration.days(),
hours: diffDuration.hours(), hours: diffDuration.hours(),
minutes: diffDuration.minutes(), minutes: diffDuration.minutes(),
}); });
} else { } else if (diffDuration.asMinutes() > 2) {
this.limitedString = this.$t('limitedAvailabilityHours', { this.limitedString = this.$t('limitedAvailabilityHours', {
hours: diffDuration.hours(), hours: diffDuration.hours(),
minutes: diffDuration.minutes(), minutes: diffDuration.minutes(),
}); });
} else {
this.limitedString = this.$t('limitedAvailabilityMinutes', {
minutes: diffDuration.minutes(),
seconds: diffDuration.seconds(),
});
} }
}, },
cancelAutoUpdate () { cancelAutoUpdate () {

View File

@@ -202,27 +202,6 @@
display: block; display: block;
} }
.limitedTime {
height: 32px;
background-color: $purple-300;
width: calc(100% + 30px);
margin: 0 -15px; // the modal content has its own padding
font-size: 12px;
line-height: 1.33;
text-align: center;
color: $white;
display: flex;
align-items: center;
justify-content: center;
.limitedString {
height: 16px;
margin-left: 8px;
}
}
.notEnough { .notEnough {
pointer-events: none; pointer-events: none;
opacity: 0.55; opacity: 0.55;

View File

@@ -158,7 +158,7 @@ export default {
}, },
mounted () { mounted () {
this.countdownString(); this.countdownString();
this.timer = setInterval(this.countdownString, 30000); this.timer = setInterval(this.countdownString, 1000);
}, },
methods: { methods: {
stars () { stars () {
@@ -188,17 +188,24 @@ export default {
countdownString () { countdownString () {
const diffDuration = moment.duration(moment(seasonalShopConfig.dateRange.end).diff(moment())); const diffDuration = moment.duration(moment(seasonalShopConfig.dateRange.end).diff(moment()));
if (diffDuration.days() > 0) { if (diffDuration.asSeconds() <= 0) {
this.limitedString = this.$t('noLongerAvailable');
} else if (diffDuration.days() > 0) {
this.limitedString = this.$t('limitedAvailabilityDays', { this.limitedString = this.$t('limitedAvailabilityDays', {
days: diffDuration.days(), days: diffDuration.days(),
hours: diffDuration.hours(), hours: diffDuration.hours(),
minutes: diffDuration.minutes(), minutes: diffDuration.minutes(),
}); });
} else { } else if (diffDuration.asMinutes() > 2) {
this.limitedString = this.$t('limitedAvailabilityHours', { this.limitedString = this.$t('limitedAvailabilityHours', {
hours: diffDuration.hours(), hours: diffDuration.hours(),
minutes: diffDuration.minutes(), minutes: diffDuration.minutes(),
}); });
} else {
this.limitedString = this.$t('limitedAvailabilityMinutes', {
minutes: diffDuration.minutes(),
seconds: diffDuration.seconds(),
});
} }
}, },
cancelAutoUpdate () { cancelAutoUpdate () {

View File

@@ -319,7 +319,7 @@ export default {
}, },
mounted () { mounted () {
this.countdownString(); this.countdownString();
this.timer = setInterval(this.countdownString, 30000); this.timer = setInterval(this.countdownString, 1000);
}, },
methods: { methods: {
click () { click () {
@@ -343,17 +343,24 @@ export default {
countdownString () { countdownString () {
const diffDuration = moment.duration(moment(seasonalShopConfig.dateRange.end).diff(moment())); const diffDuration = moment.duration(moment(seasonalShopConfig.dateRange.end).diff(moment()));
if (diffDuration.days() > 0) { if (diffDuration.asSeconds() <= 0) {
this.limitedString = this.$t('noLongerAvailable');
} else if (diffDuration.days() > 0) {
this.limitedString = this.$t('limitedAvailabilityDays', { this.limitedString = this.$t('limitedAvailabilityDays', {
days: diffDuration.days(), days: diffDuration.days(),
hours: diffDuration.hours(), hours: diffDuration.hours(),
minutes: diffDuration.minutes(), minutes: diffDuration.minutes(),
}); });
} else { } else if (diffDuration.asMinutes() > 2) {
this.limitedString = this.$t('limitedAvailabilityHours', { this.limitedString = this.$t('limitedAvailabilityHours', {
hours: diffDuration.hours(), hours: diffDuration.hours(),
minutes: diffDuration.minutes(), minutes: diffDuration.minutes(),
}); });
} else {
this.limitedString = this.$t('limitedAvailabilityMinutes', {
minutes: diffDuration.minutes(),
seconds: diffDuration.seconds(),
});
} }
}, },
cancelAutoUpdate () { cancelAutoUpdate () {

View File

@@ -199,5 +199,6 @@
"howItWorks": "How it Works", "howItWorks": "How it Works",
"g1g1HowItWorks": "Type in the username of the account youd like to gift to. From there, pick the sub length youd like to gift and check out. Your account will automatically be rewarded with the same level of subscription you just gifted.", "g1g1HowItWorks": "Type in the username of the account youd like to gift to. From there, pick the sub length youd like to gift and check out. Your account will automatically be rewarded with the same level of subscription you just gifted.",
"limitations": "Limitations", "limitations": "Limitations",
"g1g1Limitations": "This is a limited time event that starts on December 17th at 8:00 AM ET (13:00 UTC) and will end January 7th at 8:00 PM ET (1:00 UTC). This promotion only applies when you gift to another Habitican. If you or your gift recipient already have a subscription, the gifted subscription will add months of credit that will only be used after the current subscription is canceled or expires." "g1g1Limitations": "This is a limited time event that starts on December 17th at 8:00 AM ET (13:00 UTC) and will end January 7th at 8:00 PM ET (1:00 UTC). This promotion only applies when you gift to another Habitican. If you or your gift recipient already have a subscription, the gifted subscription will add months of credit that will only be used after the current subscription is canceled or expires.",
"noLongerAvailable": "This item is no longer available."
} }

View File

@@ -127,5 +127,6 @@
"imReady": "Enter Habitica", "imReady": "Enter Habitica",
"limitedOffer": "Available until <%= date %>", "limitedOffer": "Available until <%= date %>",
"limitedAvailabilityDays": "Available for <%= days %>d <%= hours %>h <%= minutes %>m", "limitedAvailabilityDays": "Available for <%= days %>d <%= hours %>h <%= minutes %>m",
"limitedAvailabilityHours": "Available for <%= hours %>h <%= minutes %>m" "limitedAvailabilityHours": "Available for <%= hours %>h <%= minutes %>m",
"limitedAvailabilityMinutes": "Available for <%= minutes %>m <%= seconds %>s"
} }

View File

@@ -518,8 +518,9 @@ const quests = {
completion: t('questEggHuntCompletion'), completion: t('questEggHuntCompletion'),
value: 1, value: 1,
category: 'pet', category: 'pet',
event: EVENTS.spring2021,
canBuy () { canBuy () {
return moment().isBefore('2021-04-30T20:00-05:00'); return moment().isBefore(EVENTS.spring2021.end);
}, },
collect: { collect: {
plainEgg: { plainEgg: {
@@ -3587,7 +3588,7 @@ const quests = {
category: 'hatchingPotion', category: 'hatchingPotion',
event: EVENTS.spring2021, event: EVENTS.spring2021,
canBuy () { canBuy () {
return moment().isBetween('2021-04-01T08:00-05:00', '2021-04-30T20:00-05:00'); return moment().isBefore(EVENTS.spring2021.end);
}, },
boss: { boss: {
name: t('questWaffleBoss'), name: t('questWaffleBoss'),