-
Notifications
You must be signed in to change notification settings - Fork 387
/
AuthBar.vue
137 lines (127 loc) · 4.9 KB
/
AuthBar.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
// Copyright (C) 2023 Storj Labs, Inc.
// See LICENSE for copying information.
<template>
<v-app-bar :elevation="0" border="0">
<template #prepend>
<div class="d-flex flex-row align-center mr-1">
<img
v-if="theme.global.current.value.dark"
src="@/assets/logo-dark.svg"
height="36"
width="auto"
alt="Storj Logo"
>
<img
v-else
src="@/assets/logo.svg"
height="36"
width="auto"
alt="Storj Logo"
>
<template v-if="partnerConfig && partnerConfig.partnerLogoTopUrl && route.name === ROUTES.Signup.name">
<p class="mx-1">+</p>
<a :href="partnerConfig.partnerUrl">
<img
:src="partnerConfig.partnerLogoTopUrl"
height="36"
width="auto"
:alt="partnerConfig.name + ' logo'"
class="rounded mt-2"
style="background-color: white;"
>
</a>
</template>
</div>
</template>
<template #append>
<!-- Theme Toggle Light/Dark Mode -->
<v-btn-toggle
v-model="activeTheme"
mandatory
border
inset
density="comfortable"
class="pa-1"
>
<v-tooltip text="Light Theme" location="bottom">
<template #activator="{ props }">
<v-btn
v-bind="props"
rounded="xl"
density="comfortable"
size="small"
class="px-4"
icon
aria-label="Toggle Light Theme"
@click="toggleTheme('light')"
>
<v-icon :icon="mdiWeatherSunny" height="24" width="24" />
</v-btn>
</template>
</v-tooltip>
<v-tooltip text="Dark Theme" location="bottom">
<template #activator="{ props }">
<v-btn
v-bind="props"
rounded="xl"
density="comfortable"
size="small"
class="px-4"
icon
aria-label="Toggle Dark Theme"
@click="toggleTheme('dark')"
>
<v-icon :icon="mdiWeatherNight" height="24" width="24" />
</v-btn>
</template>
</v-tooltip>
</v-btn-toggle>
</template>
</v-app-bar>
</template>
<script setup lang="ts">
import { useTheme } from 'vuetify';
import { onBeforeMount, ref, watch } from 'vue';
import { useRoute } from 'vue-router';
import { VAppBar, VAppBarTitle, VBtn, VBtnToggle, VIcon, VImg, VMenu, VTooltip } from 'vuetify/components';
import { mdiWeatherNight, mdiWeatherSunny } from '@mdi/js';
import { PartnerConfig } from '@/types/partners';
import { ROUTES } from '@/router';
const route = useRoute();
const theme = useTheme();
const activeTheme = ref(0);
const menu = ref(false);
const partnerConfig = ref<PartnerConfig | null>(null);
function toggleTheme(newTheme: string): void {
if ((newTheme === 'dark' && theme.global.current.value.dark) || (newTheme === 'light' && !theme.global.current.value.dark)) {
return;
}
theme.global.name.value = newTheme;
localStorage.setItem('theme', newTheme); // Store the selected theme in localStorage
}
onBeforeMount(() => {
// Check for stored theme in localStorage. If none, default to 'light'
toggleTheme(localStorage.getItem('theme') || 'light');
});
onBeforeMount(async () => {
// if on signup page, and has partner in route, see if there is a partner config to display logo
if (route.name !== ROUTES.Signup.name) {
return;
}
let partner = '';
if (route.query.partner) {
partner = route.query.partner.toString();
}
// If partner.value is true, attempt to load the partner-specific configuration
if (partner !== '') {
try {
const config = (await import('@/configs/registrationViewConfig.json')).default;
partnerConfig.value = config[partner];
// eslint-disable-next-line no-empty
} catch (_) {}
}
});
watch(() => theme.global.current.value.dark, (newVal: boolean) => {
activeTheme.value = newVal ? 1 : 0;
});
</script>