game-village-politics-frontend/app/app.vue

84 lines
3.0 KiB
Vue

<script setup lang="ts">
const { t } = useI18n()
const { user, logout } = useAuth()
const notices = useNotices()
const connection = computed(() =>
isMockServer
? { text: t('app.mock'), tone: 'bg-amber-100 text-amber-800' }
: ws.is_opened.value
? { text: t('app.connected'), tone: 'bg-emerald-100 text-emerald-800' }
: { text: t('app.offline'), tone: 'bg-rose-100 text-rose-800' },
)
const toastTone = {
success: 'border-emerald-200 bg-emerald-50 text-emerald-900',
error: 'border-rose-200 bg-rose-50 text-rose-900',
warning: 'border-amber-200 bg-amber-50 text-amber-900',
info: 'border-parchment-300 bg-white text-ink-900',
}
useHead({ title: () => t('app.title') })
</script>
<template>
<div class="min-h-dvh">
<header class="border-b border-parchment-300/70 bg-parchment-50/90">
<div class="mx-auto flex max-w-6xl items-center gap-2 px-4 py-2.5 sm:gap-3">
<NuxtLink to="/" class="flex min-w-0 items-center gap-2">
<span class="grid size-8 shrink-0 place-items-center rounded-lg bg-amber-700 text-amber-50 shadow-sm">
<IconBuilding type="headquarters" class="size-5" />
</span>
<span class="hidden font-display text-lg font-semibold sm:inline">{{ t('app.title') }}</span>
</NuxtLink>
<nav v-if="user" class="ml-1">
<NuxtLink to="/worlds" class="btn btn-ghost" active-class="bg-parchment-200/70">
<IconUi name="globe" class="size-4" />
{{ t('app.worlds') }}
</NuxtLink>
</nav>
<div class="ml-auto flex min-w-0 items-center gap-2">
<!-- The socket opens with the first request after login, so before that there is nothing to show. -->
<span v-if="user" class="badge" :class="connection.tone">
<span class="size-1.5 rounded-full bg-current" />
{{ connection.text }}
</span>
<template v-if="user">
<span class="hidden truncate text-sm text-ink-500 md:inline">{{ user.name }}</span>
<button type="button" class="btn btn-ghost px-2" :title="t('app.logout')" @click="logout()">
<IconUi name="logout" class="size-4" />
<span class="hidden sm:inline">{{ t('app.logout') }}</span>
</button>
</template>
</div>
</div>
</header>
<main>
<NuxtPage />
</main>
<div class="pointer-events-none fixed inset-x-4 bottom-4 z-50 flex flex-col items-end gap-2">
<TransitionGroup
enter-from-class="translate-y-2 opacity-0"
leave-to-class="opacity-0"
enter-active-class="transition duration-200"
leave-active-class="transition duration-200"
>
<button
v-for="n in notices.list.value"
:key="n.id"
type="button"
class="pointer-events-auto w-full max-w-sm rounded-lg border px-3 py-2 text-left text-sm shadow-md"
:class="toastTone[n.type]"
@click="notices.dismiss(n.id)"
>
{{ n.text }}
</button>
</TransitionGroup>
</div>
</div>
</template>