yunohost-portal/layouts/default.vue

123 lines
3.2 KiB
Vue
Raw Normal View History

<script setup lang="ts">
import type { User } from '@/composables/states'
const { t } = useI18n()
const isLoggedIn = useIsLoggedIn()
const settings = await useSettings()
const user = await useUser<User | null>()
2023-07-26 04:30:24 +02:00
const footerLinks = [
{ text: t('footerlink_edit'), to: '/edit' },
{
text: t('footerlink_documentation'),
2023-08-23 11:44:18 +02:00
to: '//yunohost.org/user_guide',
newWindow: true,
},
{ text: t('footerlink_support'), to: '//yunohost.org/help', newWindow: true },
{
text: t('footerlink_administration'),
to: '/yunohost/admin/',
newWindow: true,
},
]
async function logout() {
const { error } = await useApi('/logout')
if (!error.value) {
// Delete user infos
user.value = null
isLoggedIn.value = false
await navigateTo(settings.value.public ? '/' : '/login')
} else {
// FIXME : display an error or something
}
}
</script>
2023-07-12 04:52:58 +02:00
<template>
2023-07-26 01:25:42 +02:00
<div class="container mx-auto p-10 min-h-screen flex flex-col">
<header class="py-2">
<div id="focus-reset" class="h-10 -mt-10 focus-target" tabindex="-1">
<a class="link sr-only focus:not-sr-only" href="#main-target">
{{ $t('skip_link.main_content') }}
</a>
2023-08-06 16:27:24 +02:00
<a
v-if="isLoggedIn"
2023-08-06 16:27:24 +02:00
class="link sr-only focus:not-sr-only"
href="#main-footer"
2023-08-06 16:27:24 +02:00
>
{{ $t('skip_link.footer') }}
</a>
2023-08-06 16:27:24 +02:00
</div>
<slot name="header">
<div class="flex flex-row items-center">
<NuxtLink to="/" class="me-5">
2023-07-26 01:25:42 +02:00
<span class="sr-only">{{ t('back_to_apps') }}</span>
<CustomLogo class="logo" />
2023-07-26 01:25:42 +02:00
</NuxtLink>
<div
class="flex min-[500px]:w-full max-[500px]:flex-col max-[500px]:ms-auto"
>
<div>
<h2 class="text-2xl font-extrabold leading-none tracking-tight">
{{ user?.username || t('visitor') }}
</h2>
<h3 v-if="user">{{ user.fullname }}</h3>
<h4 v-if="user" class="opacity-50">{{ user.mail }}</h4>
</div>
<div class="min-[500px]:ms-auto max-[500px]:mt-2">
<YButton
v-if="isLoggedIn"
icon="logout"
:text="t('logout')"
@click.prevent="logout"
/>
<YButton v-else icon="login" :text="t('login')" to="/login" />
</div>
2023-07-26 04:30:24 +02:00
</div>
</div>
</slot>
</header>
<main>
2023-07-19 18:42:05 +02:00
<slot />
</main>
2023-07-19 18:42:05 +02:00
<footer id="main-footer" class="mt-auto focus-target" tabindex="-1">
2023-07-19 18:42:05 +02:00
<slot name="footer">
<nav
class="flex pt-2 flex-col border-t border-gray-500 flex-wrap text-center sm:space-x-5 sm:flex-row sm:inline-flex"
>
<NuxtLink
v-for="link in footerLinks"
:key="link.to"
:to="link.to"
:target="link.newWindow ? '_blank' : undefined"
class="link link-hover text-base-content inline-block"
>
{{ link.text }}
</NuxtLink>
</nav>
2023-07-19 18:42:05 +02:00
</slot>
</footer>
</div>
2023-07-12 04:52:58 +02:00
</template>
<style scoped>
header .logo {
width: 100px;
}
.focus-target:not(:focus-visible) {
outline: none;
}
#focus-reset {
outline: none;
}
</style>