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

128 lines
5.0 KiB
Vue

<script setup lang="ts">
const { t } = useI18n()
const { user, logout } = useAuth()
const notices = useNotices()
const route = useRoute()
const { current } = useCurrentWorld()
const unreadReports = useUnreadReports()
/** Inside a world (village, map or reports) the header is that world's navigation. */
const inWorld = computed(() => !!current.value && /^\/(village|map|reports)\//.test(route.path))
const home = computed(() =>
inWorld.value && current.value?.villageId ? `/village/${current.value.villageId}` : '/worlds',
)
const connection = computed(() =>
isMockServer
? { text: t('app.mock'), tone: 'badge-gold' }
: ws.is_opened.value
? { text: t('app.connected'), tone: 'badge-moss' }
: { text: t('app.offline'), tone: 'badge-blood' },
)
const toastTone = {
success: 'border-moss-700 bg-parchment-50 text-moss-700',
error: 'border-blood-700 bg-[#f0d6c8] text-blood-800',
warning: 'border-gold-600 bg-parchment-50 text-wood-900',
info: 'border-wood-700 bg-parchment-50 text-ink-900',
}
useHead({ title: () => t('app.title') })
</script>
<template>
<div class="min-h-dvh">
<!-- A dark wooden bar, like a tavern sign board. -->
<header class="border-b-4 border-wood-950 bg-wood-900 text-parchment-100">
<div class="flex items-center gap-2 px-4 py-2 sm:gap-3 sm:px-6">
<NuxtLink :to="home" class="flex min-w-0 items-center gap-2">
<span class="grid size-8 shrink-0 place-items-center rounded-sm border border-gold-600 bg-blood-700 text-gold-400">
<IconBuilding type="headquarters" class="size-5" />
</span>
<span class="hidden font-display text-lg font-semibold text-gold-400 sm:inline" style="font-variant: small-caps">
{{ t('app.title') }}
</span>
</NuxtLink>
<nav v-if="user && inWorld && current" class="ml-1 flex items-center gap-1">
<NuxtLink
v-if="current.villageId"
:to="`/village/${current.villageId}`"
class="nav-link"
active-class="nav-link-active"
>
<IconBuilding type="headquarters" class="size-4" />
{{ t('app.village') }}
</NuxtLink>
<NuxtLink :to="`/map/${current.worldId}`" class="nav-link" active-class="nav-link-active">
<IconUi name="pin" class="size-4" />
{{ t('app.map') }}
</NuxtLink>
<NuxtLink :to="`/reports/${current.worldId}`" class="nav-link" active-class="nav-link-active">
<IconUi name="report" class="size-4" />
<span class="hidden sm:inline">{{ t('app.reports') }}</span>
<span v-if="unreadReports" class="badge badge-gold px-1.5 py-0" :title="t('app.unread_reports', { count: unreadReports })">
{{ unreadReports }}
</span>
</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-parchment-300 md:inline">{{ user.name }}</span>
<!-- Leaving the world is a quiet way out, not a tab. -->
<NuxtLink v-if="inWorld" to="/worlds" class="nav-link px-2" :title="t('app.change_world')">
<IconUi name="globe" class="size-4" />
<span class="hidden lg:inline">{{ t('app.change_world') }}</span>
</NuxtLink>
<button type="button" class="nav-link 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-sm border-2 px-3 py-2 text-left text-sm shadow-hard"
:class="toastTone[n.type]"
@click="notices.dismiss(n.id)"
>
{{ n.text }}
</button>
</TransitionGroup>
</div>
</div>
</template>
<style scoped>
@reference "~/assets/css/main.css";
.nav-link {
@apply inline-flex items-center gap-1.5 rounded-sm border border-transparent px-3 py-1.5 text-sm font-semibold text-parchment-100 transition-colors hover:border-wood-600 hover:bg-wood-800 focus-visible:outline-2 focus-visible:outline-gold-500;
}
.nav-link-active {
@apply border-gold-600 bg-wood-800 text-gold-400;
}
</style>