Files
dancefinder-app/app/layouts/default.vue
T

112 lines
3.6 KiB
Vue
Raw Normal View History

2019-01-15 13:21:24 +01:00
<template>
<v-app :key='locale + isAuthenticated'>
<v-navigation-drawer v-model='nav' temporary>
<v-list density="compact">
<v-list-item v-if='isAuthenticated && user' :title='user.name' :prepend-avatar='user.picture' />
2024-02-05 16:48:02 +01:00
<v-list-item>
<v-switch v-model='darkMode' color='primary' :label="t('app.darkMode')" hide-details class='ms-1' />
2024-02-05 16:48:02 +01:00
</v-list-item>
<!-- eslint-disable-next-line vue/no-bare-strings-in-template -->
<v-list-item title='In English' :to="switchLocalePath('en')">
2024-02-05 16:48:02 +01:00
<template #prepend>
<!-- eslint-disable-next-line vue/no-bare-strings-in-template -->
<div class='d-flex d-inline-flex text-h5 me-8'>
2024-02-05 16:48:02 +01:00
🇬🇧
</div>
</template>
</v-list-item>
<!-- eslint-disable-next-line vue/no-bare-strings-in-template -->
<v-list-item title='På Svenska' :to="switchLocalePath('sv')">
2024-02-05 16:48:02 +01:00
<template #prepend>
<!-- eslint-disable-next-line vue/no-bare-strings-in-template -->
<div class='d-flex d-inline-flex text-h5 me-8'>
2024-02-05 16:48:02 +01:00
🇸🇪
</div>
</template>
</v-list-item>
<v-list-item to='/' :title="t('app.links.events')" prepend-icon='mdi-calendar-outline' />
<v-list-item v-if='isAuthenticated' to='/origins/' :title="t('app.links.origins')" prepend-icon='mdi-home' />
<v-list-item
v-if='isAuthenticated' to='/filters/' :title="t('app.links.filters')"
prepend-icon='mdi-magnify' />
<v-list-item v-if='!user' link :title="t('app.login')" prepend-icon='mdi-login' @click='doLogin' />
<v-list-item
v-if='isAuthenticated' link :title="t('app.logout')" prepend-icon='mdi-logout'
@click='doLogout' />
2024-02-05 16:48:02 +01:00
</v-list>
</v-navigation-drawer>
<v-app-bar scroll-behavior="hide">
<v-app-bar-nav-icon @click='nav = !nav' />
<v-toolbar-title :title='title' />
2024-02-05 16:48:02 +01:00
<v-spacer />
<v-toolbar-items>
<v-list-item v-if='isAuthenticated && user' :prepend-avatar='user.picture' :title='user.name' />
2024-02-05 16:48:02 +01:00
</v-toolbar-items>
</v-app-bar>
<v-main>
<v-container v-if='!isLoading' fluid>
2024-02-05 16:48:02 +01:00
<slot />
</v-container>
</v-main>
2019-01-21 20:58:25 +01:00
</v-app>
2019-01-15 13:21:24 +01:00
</template>
2024-02-02 18:55:45 +01:00
<script setup lang='ts'>
import { useAuth0 } from '@auth0/auth0-vue'
2024-02-05 16:48:02 +01:00
import { computed, onMounted, ref } from 'vue'
import { useTheme } from 'vuetify'
2024-02-05 16:48:02 +01:00
import { useSwitchLocalePath } from '#i18n'
2023-08-01 20:21:31 +02:00
import { useState } from '~/store'
2019-01-15 13:21:24 +01:00
const { t, locale } = useI18n()
const { $faro } = useNuxtApp()
2024-02-05 16:48:02 +01:00
const switchLocalePath = useSwitchLocalePath()
2024-02-02 18:55:45 +01:00
const state = useState()
2024-02-05 16:48:02 +01:00
const { isLoading, isAuthenticated, user, loginWithRedirect, logout } =
useAuth0()
2024-02-02 18:55:45 +01:00
const doLogin = () => {
loginWithRedirect({
2024-02-05 16:48:02 +01:00
appState: { targetUrl: window.location.pathname },
2024-02-02 18:55:45 +01:00
})
}
const doLogout = () => {
logout({
logoutParams: {
2024-02-05 16:48:02 +01:00
returnTo: window.location.origin,
},
2024-02-02 18:55:45 +01:00
})
}
2024-02-05 16:48:02 +01:00
const theme = useTheme()
onMounted(() => {
if (state.darkMode) {
theme.global.name.value = 'dark'
} else {
theme.global.name.value = 'light'
2024-02-02 18:55:45 +01:00
}
})
2024-02-05 16:48:02 +01:00
const darkMode = computed<boolean>({
get: () => theme.global.current.value.dark,
set: (value: boolean) => {
state.setDarkMode(value)
if (value) {
theme.global.name.value = 'dark'
} else {
theme.global.name.value = 'light'
}
2024-02-05 16:48:02 +01:00
},
2024-02-02 18:55:45 +01:00
})
const nav = ref(false)
const title = computed(() => state.title)
watchEffect(() => {
if ($faro && !isLoading.value && user.value) {
$faro.api.setUser({
id: user.value.sub,
email: user.value.email,
username: user.value.preferred_username,
})
}
})
2019-01-15 13:21:24 +01:00
</script>