-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.vue
174 lines (147 loc) · 4.17 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
<template>
<div>
<NuxtLayout>
<NuxtLoadingIndicator :throttle="300" />
<NuxtPage />
</NuxtLayout>
</div>
</template>
<script setup lang="ts">
import { storeToRefs } from 'pinia'
import { useFavicon } from '@vueuse/core'
import {
useSessionStore,
useProductStore,
useDeliveryStore,
useUiStore,
useCartStore,
useContactStore,
} from '~/store'
import { createSeoTags, APP_VERSION } from '#imports'
const nuxtApp = useNuxtApp()
const { $env, $log } = nuxtApp
const ui = useUiStore()
console.log(`APP Version: ${APP_VERSION}`)
$log.log({ $env })
const loaded = ref(false)
nuxtApp.hook('page:finish', () => {
if (loaded.value) {
// scrollPageToTop()
ui.closeAllModals()
ui.setMobileMenu(false)
}
loaded.value = true
})
onMounted(() => {
setAppVH()
window.addEventListener('resize', setAppVH)
})
const setAppVH = () => {
const vw = document.documentElement.clientWidth * 0.01
const vh = window.innerHeight * 0.01
document.documentElement.style.setProperty('--vw', `${vw}px`)
document.documentElement.style.setProperty('--vh', `${vh}px`)
}
const productStore = useProductStore()
const deliveryStore = useDeliveryStore()
const cartStore = useCartStore()
const sessionStore = useSessionStore()
const contactStore = useContactStore()
const { region } = storeToRefs(deliveryStore)
const initData = await useInit()
// установка куки в клиент от init (баг useCookieState)
// не работает когда useCookieState работает в SSR контексте
const apiCookieClient = useCookie('x-thapl-apitoken', { maxAge: 60 * 60 * 24 * 30 * 6 })
apiCookieClient.value = initData?.api_token || null
useHead({
htmlAttrs: {
class: `theme-${$env.theme}`,
},
...createSeoTags({
title: initData?.site_settings?.page?.seo_title || $env.projectName,
description: initData?.site_settings?.page?.seo_description,
meta_tags: initData?.site_settings?.meta_tags,
}),
})
useFavicon(initData?.site_settings.fav_icon)
await useAsyncData('zone-init', () => deliveryStore.hydrateZone())
await useAsyncData('startup', async () => {
const promisesToBeFetched = [
{
id: 'catalog',
resolver: productStore.getCatalog(),
},
// {
// id: 'zone',
// resolver: deliveryStore.hydrateZone(),
// },
{
id: 'contacts',
resolver: contactStore.getContacts(),
},
{
id: 'restaurantsForContacts',
resolver: contactStore.getContactRestaurants(),
},
] as { id: string; resolver: Promise<any> }[]
if ($env.useRegions) {
promisesToBeFetched.push({
id: 'regions',
resolver: deliveryStore.getRegions(),
})
}
if (initData?.app_settings.takeaway_enabled) {
promisesToBeFetched.push({
id: 'restaurants',
resolver: deliveryStore.getRestaurants(),
})
}
const allSettled = (await Promise.allSettled(
promisesToBeFetched.map((x) => x.resolver)
)) as PromiseSettledResult<any>[]
const regionCookie = useCookieState('x-thapl-region-id')
allSettled.forEach((result, idx) => {
const { id } = promisesToBeFetched[idx]
// console.log(name, { result })
// if (result.status === 'rejected') errHandler()
if (result.status === 'fulfilled' && result.value) {
const { data, error } = result.value
switch (id) {
case 'catalog':
$log.log('🧙♂️ ASYNC CATALOG', { catalog: result.value })
break
case 'regions':
// const regionCookieClient = useCookie('x-thapl-region-id')
region.value = regionCookie.value || null
// regionCookieClient.value = regionCookie.value
$log.log('🧙♂️ ASYNC REGIONS', { regions: result.value })
break
case 'restaurants':
$log.log('🧙♂️ ASYNC ORGANIZATIONS', { restaurants: result.value })
break
default:
break
}
}
})
return true
})
onMounted(() => {
deliveryStore.getStoredAddresses()
cartStore.fetchCartProducts()
})
</script>
<style lang="scss">
:root {
--app-vh: 100vh;
}
.page-enter-active,
.page-leave-active {
transition: all 0.3s;
}
.page-enter-from,
.page-leave-to {
opacity: 0;
filter: blur(10px);
}
</style>