-
Notifications
You must be signed in to change notification settings - Fork 5
/
App.vue
119 lines (100 loc) · 3.48 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
<template>
<Head>
<title>{{ isLevante ? '' : 'ROAR:' }} {{ pageTitle }}</title>
<meta name="description" content="The Rapid Online Assessment of Reading" />
<!-- Social -->
<meta property="og:title" content="ROAR Web Query" />
<meta property="og:description" content="A web-based tool to query ROAR assessment data!" />
<!-- Twitter -->
<meta name="twitter:title" content="ROAR Web Query" />
<meta name="twitter:description" content="A web-based tool to query ROAR assessment data!" />
</Head>
<div>
<PvToast />
<NavBar v-if="!navbarBlacklist.includes($route.name) && isAuthStoreReady" />
<router-view :key="$route.fullPath" />
<SessionTimer v-if="loadSessionTimeoutHandler" />
</div>
<VueQueryDevtools v-if="showDevtools" />
</template>
<script setup>
import { computed, onBeforeMount, onMounted, ref, defineAsyncComponent } from 'vue';
import { useRoute } from 'vue-router';
import { useRecaptchaProvider } from 'vue-recaptcha';
import { Head } from '@unhead/vue/components';
import NavBar from '@/components/NavBar.vue';
const SessionTimer = defineAsyncComponent(() => import('@/containers/SessionTimer/SessionTimer.vue'));
const VueQueryDevtools = defineAsyncComponent(() =>
import('@tanstack/vue-query-devtools').then((module) => module.VueQueryDevtools),
);
import { useAuthStore } from '@/store/auth';
import { fetchDocById } from '@/helpers/query/utils';
import { i18n } from '@/translations/i18n';
const isLevante = import.meta.env.MODE === 'LEVANTE';
const isAuthStoreReady = ref(false);
const showDevtools = ref(false);
const authStore = useAuthStore();
const route = useRoute();
const pageTitle = computed(() => {
const locale = i18n.global.locale.value;
const fallbackLocale = i18n.global.fallbackLocale.value;
return route.meta?.pageTitle?.[locale] || route.meta?.pageTitle?.[fallbackLocale] || route.meta?.pageTitle;
});
const loadSessionTimeoutHandler = computed(() => isAuthStoreReady.value && authStore.isAuthenticated);
useRecaptchaProvider();
const navbarBlacklist = ref([
'SignIn',
'Register',
'Maintenance',
'PlayApp',
'SWR',
'SWR-ES',
'SRE',
'SRE-ES',
'PA',
'PA-ES',
'Letter',
'Letter-ES',
'Vocab',
'Multichoice',
'Morphology',
'Cva',
'Fluency-ARF',
'Fluency-ARF-ES',
'Fluency-CALF',
'Fluency-CALF-ES',
'Fluency-Alpaca',
'Fluency-Alpaca-ES',
'RAN',
'Crowding',
'MEP',
]);
onBeforeMount(async () => {
await authStore.initFirekit();
await authStore.initStateFromRedirect().then(async () => {
// @TODO: Refactor this callback as we should ideally use the useUserClaimsQuery and useUserDataQuery composables.
// @NOTE: Whilst the rest of the application relies on the user's ROAR UID, this callback requires the user's ID
// in order for SSO to work and cannot currently be changed without significant refactoring.
if (authStore.uid) {
const userClaims = await fetchDocById('userClaims', authStore.uid);
authStore.userClaims = userClaims;
}
if (authStore.roarUid) {
const userData = await fetchDocById('users', authStore.roarUid);
authStore.userData = userData;
}
});
isAuthStoreReady.value = true;
});
onMounted(() => {
const isLocal = import.meta.env.MODE === 'development';
const isDevToolsEnabled = import.meta.env.VITE_QUERY_DEVTOOLS_ENABLED === 'true';
if (isLocal) {
showDevtools.value = true;
} else if (isDevToolsEnabled) {
window.toggleDevtools = () => {
showDevtools.value = !showDevtools.value;
};
}
});
</script>