-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.vue
More file actions
151 lines (144 loc) · 3.87 KB
/
app.vue
File metadata and controls
151 lines (144 loc) · 3.87 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
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
<template>
<transition name="page" mode="out-in" appear>
<div
class="max-w-screeen flex flex-col"
>
<TheNavigation
:key="keyTrigger"
:on-global-page="convertToBoolean(useRuntimeConfig().public.IS_GLOBAL_SITE)"
:tag-line="globalData?.tagLine"
:contact-button-label="globalData?.contactButtonLabel"
/>
<main class="">
<NuxtPage />
</main>
<TheFooter
v-if="!onGlobalPage"
:key="`Footer-${String(keyTrigger)}`"
:class="{ 'pt-120': onGlobalPage }"
:on-global-page="convertToBoolean(useRuntimeConfig().public.IS_GLOBAL_SITE)"
:background-color="onGlobalPage ? 'white' : 'gray'"
/>
<!-- <PreviewModeControls /> -->
</div>
</transition>
</template>
<script lang="ts" setup>
import { computed } from 'vue'
import { useWebsiteStore } from './store/store'
import type { Page } from './types/dato-models/Page'
import type { DatoRegionResponse } from './types/dato-api-responses/Region'
const store = useWebsiteStore()
const onGlobalPage = useRuntimeConfig().public.IS_GLOBAL_SITE
const route = useRoute()
await useAsyncData('setNavigation', () => store.setNavigation(convertToBoolean(onGlobalPage)).then(() => true))
const keyTrigger = ref(0)
const { locale } = useI18n()
watch(locale, () => {
updateNavigation()
})
const pageFields = (showNavLabel = true) => `
id
_modelApiKey
${showNavLabel ? 'navigationLabel' : ''}
`
interface RegionResponse {
data: DatoRegionResponse
}
async function updateNavigation () {
const QUERY = `
query {
region(filter: {id: {eq: "${useRuntimeConfig().public.DATO_REGION_ID}"}}, locale: ${locale.value}) {
_allReferencingHomePages {
${pageFields(false)}
}
_allReferencingMerchantPages {
${pageFields()}
}
_allReferencingBeginnerPages {
${pageFields()}
}
_allReferencingNetworkPages {
${pageFields()}
}
_allReferencingNewsPages {
${pageFields()}
}
_allReferencingAboutPages {
${pageFields()}
}
_allReferencingContactPages {
${pageFields()}
}
}
}`
const body = await $fetch('https://graphql.datocms.com', {
method: 'POST',
headers: {
Authorization: `Bearer ${useRuntimeConfig().public.DATO_TOKEN}`,
'X-environment': 'main'
},
body: {
query: QUERY
}
}) as RegionResponse
store.pages = []
for (const property in body.data.region) {
if (property.includes('Pages')) {
const value = body.data.region[property as keyof typeof body.data.region] as Page[]
if (typeof value === 'object' && value[0]) {
store.pages?.push((value as Page[])[0])
}
}
}
keyTrigger.value++
}
function convertToBoolean (input: string | boolean): boolean | undefined {
if (typeof input === 'boolean') {
return input
}
return input === 'true'
}
const globalData = computed(() => {
if (onGlobalPage) {
return store.getGlobalData
}
return null
})
const pageTitle = computed(() => {
const pageTitle = route.path.split('/').pop()?.replace(/%20/g, ' ').replace(/-/g, ' ')
if (pageTitle && pageTitle.length > 2) {
return pageTitle
.toLowerCase()
.split(' ')
.map(word => word.charAt(0).toUpperCase() + word.slice(1))
.join(' ')
} else {
return null
}
})
const regionName = computed(() => {
if (onGlobalPage) { return 'CryptoCity' }
if (store.region) {
return store.region?.brandName
} else {
return ''
}
})
const makeName = computed(() => {
return `${pageTitle.value ? pageTitle.value + ' - ' : ''}${regionName.value}\u00AE`
})
useHead({
title: makeName
})
</script>
<style>
.page-enter-active,
.page-leave-active {
transition: all 0.3s;
}
.page-enter-from,
.page-leave-to {
opacity: 0;
}
</style>