-
Notifications
You must be signed in to change notification settings - Fork 2
/
app.vue
80 lines (66 loc) · 1.92 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
<template>
<VitePwaManifest />
<PopupsLayer />
<NuxtLayout :name="viewMode">
<NuxtPage />
</NuxtLayout>
</template>
<script setup lang="ts">
// load dayjs + plugins
import dayjs from 'dayjs'
import 'dayjs/locale/de'
import relativeTime from 'dayjs/plugin/relativeTime'
dayjs.extend(relativeTime)
// apply color mode
useSettingColorMode()
// viewport info
const viewMode = useViewMode()
// maximum screen width (px) for mobile view
const VIEW_MAX_WIDTH_MOBILE = 800
function trackViewMode() {
// making sure we're showing the right view (mobile <-> desktop)
const { width } = useWindowSize()
if (width.value > VIEW_MAX_WIDTH_MOBILE)
viewMode.value = 'desktop'
watch(width, (val) => {
if (val > VIEW_MAX_WIDTH_MOBILE)
viewMode.value = 'desktop'
else
viewMode.value = 'mobile'
})
}
async function backgroundTasks() {
// backgroundTasks() gets executed once the main thread is idle or after 2 seconds
// this way low priority tasks can be done once all the important rendering and loading work is done
const api = useApi()
// update local mensa list
const locations = await api.getLocations()
if (locations)
useLocationList().value = locations
}
onMounted(() => {
trackViewMode()
if ('requestIdleCallback' in window)
requestIdleCallback(backgroundTasks, { timeout: 2000 })
else
backgroundTasks()
})
const popups = usePopups()
useEventListener('popstate', (e) => {
const allowedPopups = e.state.$popups ?? []
for (const popup of popups.state) {
if (allowedPopups.includes(popup.uuid)) continue
if (!popup.dismissed)
popup.callback(null)
popup.dismissed = true
setTimeout(() => {
const index = popups.state.findIndex(search => search.uuid === popup.uuid)
popups.state.splice(index, 1)
}, 1000)
}
})
</script>
<!-- THIS IS GLOBAL CSS, NOT SCOPED. DO NOT ADD STYLES HERE! -->
<style lang="scss">
@import '~/assets/style/global.scss';
</style>