forked from quasarframework/quasar
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSurveyCountdown.vue
More file actions
83 lines (68 loc) · 1.94 KB
/
SurveyCountdown.vue
File metadata and controls
83 lines (68 loc) · 1.94 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
<template lang="pug">
q-banner(v-if="!hasEnded").survey-countdown
.q-gutter-sm.row(:class="[paddingClass, alignClass]")
| Quasar Scaffolding Survey closes in...
q-badge.text-bold(v-if="days > 0" :color="color" :text-color="textColor") {{ days }} Days
q-badge.text-bold(v-if="hours > 0" :color="color" :text-color="textColor") {{ hours }} Hours
q-badge.text-bold(:color="color" :text-color="textColor") {{ minutes }} Minutes
q-btn(
href="https://bit.ly/2VtIGK9"
target="_blank"
:color="color"
:text-color="textColor"
:icon="mdiFileDocumentEditOutline"
label="Open survey"
no-caps
)
</template>
<script>
import { ref, onMounted, onBeforeUnmount } from 'vue'
import { mdiFileDocumentEditOutline } from '@quasar/extras/mdi-v6'
const confDate = new Date('2021-08-08').getTime()
const oneDay = 1000 * 60 * 60 * 24
const oneHour = 1000 * 60 * 60
const oneMin = 1000 * 60
export default {
name: 'ConfCountdown',
props: {
color: String,
textColor: String,
alignClass: String,
paddingClass: String
},
setup () {
const days = ref('*')
const hours = ref('*')
const minutes = ref('*')
const hasEnded = ref(false)
let interval
function calcTimeRemaining () {
const now = new Date().getTime()
const remaining = confDate - now
hasEnded.value = remaining <= 0
if (hasEnded.value === false) {
days.value = Math.floor(remaining / oneDay)
hours.value = Math.floor((remaining % oneDay) / oneHour)
minutes.value = Math.floor((remaining % oneHour) / oneMin)
}
else {
clearInterval(interval)
}
}
onMounted(() => {
interval = setInterval(() => calcTimeRemaining, oneMin)
calcTimeRemaining()
})
onBeforeUnmount(() => {
clearInterval(interval)
})
return {
days,
hours,
minutes,
hasEnded,
mdiFileDocumentEditOutline
}
}
}
</script>