-
-
Notifications
You must be signed in to change notification settings - Fork 37
/
app.vue
198 lines (171 loc) · 5.22 KB
/
app.vue
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
<script setup lang="ts">
import { defineAsyncComponent } from 'vue'
import { useI18n } from 'vue-i18n'
import { useHead } from '#imports'
import { useSchedule } from '~~/stores/schedule'
import { useSettings } from '~~/stores/settings'
import { useTicker } from '~~/components/ticker'
import { useWeb } from '~~/platforms/web'
import { useMobile } from '~~/platforms/mobile'
import TimerSwitch from '@/components/timer/display/_timerSwitch.vue'
import TimerProgress from '@/components/timer/timerProgress.vue'
import TimerControls from '@/components/timer/controls/controlsNew.vue'
import { AppPlatform } from '~~/platforms/platforms'
import { useMobileSettings } from '~~/stores/platforms/mobileSettings'
import Layout from '~/layouts/timer.vue'
// components
const AppBar = defineAsyncComponent(() => import('@/components/appBar.vue'))
const TutorialView = defineAsyncComponent(() => import('@/components/tutorial/_tutorialView.vue'))
const settingsStore = useSettings()
const mobileSettingsStore = useMobileSettings()
const scheduleStore = useSchedule()
const runtimeConfig = useRuntimeConfig()
const { t } = useI18n()
const iconSvg = computed(() => `data:image/svg+xml,
<svg
width="32"
height="32"
viewBox="0 0 32 32"
fill="none"
style="color: ${scheduleStore.currentScheduleColour};"
xmlns="http://www.w3.org/2000/svg"
>
<circle cx="16" cy="16" r="14" fill="currentColor" /></svg>`)
useHead({
link: [
{
rel: 'manifest',
href: '/app_manifest.json'
},
{
rel: 'apple-touch-icon',
href: '/icons/icon-apple-192.png'
}
],
meta: [
{ name: 'theme-color', content: '#F87171' }
]
})
if (!import.meta.server) {
useHead({
link: [
{
rel: 'icon',
type: 'image/svg+xml',
href: iconSvg
}
]
})
}
onMounted(() => {
if (typeof window !== 'undefined') {
if ('serviceWorker' in navigator) {
const registerSw = () => {
console.debug('Registering service worker at /serviceworker.js')
navigator.serviceWorker.register('/serviceworker.js')
}
if (document.readyState === 'complete') {
registerSw()
} else {
window.addEventListener('load', registerSw)
}
}
}
})
useTicker()
// Load appropriate platform module based on runtime config
if (runtimeConfig.public.PLATFORM === AppPlatform.web) {
useWeb()
} else if (runtimeConfig.public.PLATFORM === AppPlatform.mobile) {
useMobile()
}
const state = reactive({
timeString: ''
})
const remainingTimeString = computed(() => {
if (scheduleStore.getCurrentTimerState === 3) {
return settingsStore.pageTitle.useTickEmoji ? '✔' : t('ready').toLowerCase()
}
return state.timeString
})
const pageTitle = computed(() => {
return scheduleStore.getCurrentItem
? t('section.' + scheduleStore.getCurrentItem.type).toLowerCase()
: 'Pomodoro'
})
const progressBarSchedules = computed(() => {
const numSchedules = settingsStore.performance.showProgressBar ? 2 : 1
return scheduleStore.getSchedule.slice(0, numSchedules)
})
</script>
<template>
<Layout>
<section class="h-full overflow-hidden duration-300 ease-in dark:text-gray-50">
<Title>{{ (remainingTimeString ? `(${remainingTimeString}) ` : '') + pageTitle }}</Title>
<!-- Dark mode background override -->
<div class="absolute w-full h-full dark:bg-gray-900" />
<!-- Progress bar -->
<TransitionGroup name="progress-transition" :duration="1000">
<TimerProgress
v-for="(scheduleItem, index) in progressBarSchedules"
:key="scheduleItem.id"
:colour="scheduleStore.getScheduleColour[index]"
:schedule-entry-id="scheduleItem.id"
:background="index === 0"
:time-elapsed="scheduleStore.getCurrentItem.timeElapsed"
:time-original="scheduleStore.getCurrentItem.length"
/>
</TransitionGroup>
<div
class="relative flex flex-col items-center justify-center w-full h-full isolate"
:style="{
'padding-top': `${mobileSettingsStore.padding.top}px`,
'padding-bottom': `${mobileSettingsStore.padding.bottom}px`
}"
>
<AppBar />
<TimerSwitch
key="timerswitch"
:time-elapsed="scheduleStore.getCurrentItem.timeElapsed"
:time-original="scheduleStore.getCurrentItem.length"
:timer-state="scheduleStore.timerState"
:timer-widget="settingsStore.currentTimer"
class="flex-grow"
@tick="state.timeString = $event"
/>
<TimerControls class="mb-8" />
</div>
<client-only>
<TutorialView />
</client-only>
</section>
</Layout>
</template>
<style lang="scss" scoped>
.timer-background {
transition: 300ms ease-in;
transition-property: background-color;
position: relative;
height: 100%;
}
.schedule-transition-enter-active,
.schedule-transition-leave-active {
transition: transform 300ms ease-out, opacity 200ms ease-out;
}
.schedule-transition-enter,
.schedule-transition-leave-to {
transform: translateY(-20px);
opacity: 0;
}
.progress-transition-leave-to {
@apply transform-gpu translate-x-0;
}
.progress-transition-enter {
@apply transform-gpu -translate-x-full;
}
</style>
<style>
body {
overscroll-behavior-y: contain;
}
</style>