-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathApp.vue
81 lines (70 loc) · 2.33 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
<template>
<router-view/>
</template>
<script setup lang="ts">
import {computed, onMounted, watch} from 'vue';
import {LanguageUtils} from 'src/utils/LanguageUtils';
import {useSettingsStore} from 'stores/SettingsStore';
import {useQuasar} from 'quasar';
import {useI18n} from 'vue-i18n';
import {ThemeUtils} from 'src/utils/ThemeUtils';
import {TestDataUtils} from 'src/utils/TestDataUtils';
// Initialize helpers
const q = useQuasar();
const i18n = useI18n();
const settingsStore = useSettingsStore();
const testDataUtils = new TestDataUtils();
const languageUtils = new LanguageUtils();
const themeUtils = new ThemeUtils();
// Initialize variable that computes if i18n locale and settings locale are different or note.
const isI18nInconsistent = computed(() =>
settingsStore.locale !== i18n.locale.value
);
// Initialize variable that computes if quasar lang and settings locale are different or note.
const isQuasarLangInconsistent = computed(() =>
settingsStore.locale !== q.lang.isoName
);
// Initialize variable that computes if the theme is inconsistent or not.
const isThemeInconsistent = computed(() =>
(settingsStore.darkMode && !q.dark.isActive) || (!settingsStore.darkMode && q.dark.isActive)
);
// region INITIALIZATION
/**
* If the app gets mounted, the language of the app will be initialized with user's settings.
*/
onMounted(async () => {
// TODO: Load app settings.
if (isI18nInconsistent.value)
i18n.locale.value = settingsStore.locale;
if (isQuasarLangInconsistent.value)
await languageUtils.loadQuasarLanguagePack(settingsStore.locale);
if(isThemeInconsistent.value)
themeUtils.changeTheme();
// Load test data
testDataUtils.initializeStoreWithTestData();
});
// endregion
// region INCONSISTENCY HANDLING
/**
* If the app's theme is inconsistent, the theme will be updated.
*/
watch(isI18nInconsistent, (newValue: boolean) => {
if (newValue)
i18n.locale.value = settingsStore.locale;
});
/**
* If the app's theme is inconsistent, the theme will be updated.
*/
watch(isQuasarLangInconsistent, async (newValue: boolean) => {
if (newValue)
await languageUtils.loadQuasarLanguagePack(settingsStore.locale);
});
/**
* If the app's theme is inconsistent, the theme will be updated.
*/
watch(isThemeInconsistent, (newValue: boolean) => {
if (newValue)
themeUtils.changeTheme();
});
// endregion
</script>