feat: styled app shell, toasts, auth and world pages
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
08b48e6415
commit
e5cdf43e37
76
app/app.vue
76
app/app.vue
|
|
@ -4,33 +4,79 @@ const { user, logout } = useAuth()
|
|||
const notices = useNotices()
|
||||
|
||||
const connection = computed(() =>
|
||||
isMockServer ? t('app.mock') : ws.is_opened.value ? t('app.connected') : t('app.offline'),
|
||||
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>
|
||||
<header>
|
||||
<strong>{{ t('app.title') }}</strong>
|
||||
<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">
|
||||
<span class="badge" :class="connection.tone">
|
||||
<span class="size-1.5 rounded-full bg-current" />
|
||||
{{ connection.text }}
|
||||
</span>
|
||||
<template v-if="user">
|
||||
· <NuxtLink to="/worlds">{{ t('app.worlds') }}</NuxtLink>
|
||||
· {{ user.name }}
|
||||
· <button type="button" @click="logout()">{{ t('app.logout') }}</button>
|
||||
<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>
|
||||
· <small>{{ connection }}</small>
|
||||
</div>
|
||||
</div>
|
||||
</header>
|
||||
|
||||
<ul v-if="notices.list.value.length">
|
||||
<li v-for="n in notices.list.value" :key="n.id" @click="notices.dismiss(n.id)">
|
||||
[{{ n.type }}] {{ n.text }}
|
||||
</li>
|
||||
</ul>
|
||||
|
||||
<hr />
|
||||
<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>
|
||||
|
|
|
|||
|
|
@ -0,0 +1,26 @@
|
|||
<script setup lang="ts">
|
||||
defineProps<{ title: string }>()
|
||||
</script>
|
||||
|
||||
<!-- Centred card for the login and register forms. -->
|
||||
<template>
|
||||
<div class="flex min-h-[calc(100dvh-3.5rem)] items-center justify-center px-4 py-10">
|
||||
<div class="w-full max-w-sm">
|
||||
<div class="mb-6 flex flex-col items-center gap-3 text-center">
|
||||
<span class="grid size-14 place-items-center rounded-2xl bg-amber-700 text-amber-50 shadow-md">
|
||||
<IconBuilding type="headquarters" class="size-8" />
|
||||
</span>
|
||||
<div>
|
||||
<h1 class="font-display text-2xl font-semibold">{{ title }}</h1>
|
||||
<p class="mt-1 text-sm text-ink-500">{{ $t('auth.tagline') }}</p>
|
||||
</div>
|
||||
</div>
|
||||
<div class="panel p-6">
|
||||
<slot />
|
||||
</div>
|
||||
<p class="mt-4 text-center text-sm">
|
||||
<slot name="footer" />
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
|
@ -23,19 +23,22 @@ async function submit() {
|
|||
</script>
|
||||
|
||||
<template>
|
||||
<section>
|
||||
<h1>{{ $t('auth.login.title') }}</h1>
|
||||
<p v-if="mock"><small>{{ $t('auth.mock_hint') }}</small></p>
|
||||
<form @submit.prevent="submit">
|
||||
<p>
|
||||
<label>{{ $t('auth.email') }}<br /><input v-model="email" type="email" autocomplete="email" required /></label>
|
||||
</p>
|
||||
<p>
|
||||
<label>{{ $t('auth.password') }}<br /><input v-model="password" type="password" autocomplete="current-password" required /></label>
|
||||
</p>
|
||||
<p v-if="error" role="alert">{{ error }}</p>
|
||||
<button type="submit" :disabled="busy">{{ $t('auth.login.submit') }}</button>
|
||||
<UiAuthCard :title="$t('auth.login.title')">
|
||||
<p v-if="mock" class="mb-4 rounded-lg bg-amber-50 px-3 py-2 text-xs text-amber-800">{{ $t('auth.mock_hint') }}</p>
|
||||
<form class="space-y-4" @submit.prevent="submit">
|
||||
<label class="block">
|
||||
<span class="label">{{ $t('auth.email') }}</span>
|
||||
<input v-model="email" class="input" type="email" autocomplete="email" required />
|
||||
</label>
|
||||
<label class="block">
|
||||
<span class="label">{{ $t('auth.password') }}</span>
|
||||
<input v-model="password" class="input" type="password" autocomplete="current-password" required />
|
||||
</label>
|
||||
<p v-if="error" class="alert" role="alert">{{ error }}</p>
|
||||
<button type="submit" class="btn btn-primary w-full py-2" :disabled="busy">{{ $t('auth.login.submit') }}</button>
|
||||
</form>
|
||||
<p><NuxtLink to="/register">{{ $t('auth.login.to_register') }}</NuxtLink></p>
|
||||
</section>
|
||||
<template #footer>
|
||||
<NuxtLink to="/register" class="font-medium text-amber-800 hover:underline">{{ $t('auth.login.to_register') }}</NuxtLink>
|
||||
</template>
|
||||
</UiAuthCard>
|
||||
</template>
|
||||
|
|
|
|||
|
|
@ -24,22 +24,26 @@ async function submit() {
|
|||
</script>
|
||||
|
||||
<template>
|
||||
<section>
|
||||
<h1>{{ $t('auth.register.title') }}</h1>
|
||||
<p v-if="mock"><small>{{ $t('auth.mock_hint') }}</small></p>
|
||||
<form @submit.prevent="submit">
|
||||
<p>
|
||||
<label>{{ $t('auth.name') }}<br /><input v-model="name" type="text" autocomplete="nickname" required /></label>
|
||||
</p>
|
||||
<p>
|
||||
<label>{{ $t('auth.email') }}<br /><input v-model="email" type="email" autocomplete="email" required /></label>
|
||||
</p>
|
||||
<p>
|
||||
<label>{{ $t('auth.password') }}<br /><input v-model="password" type="password" autocomplete="new-password" required /></label>
|
||||
</p>
|
||||
<p v-if="error" role="alert">{{ error }}</p>
|
||||
<button type="submit" :disabled="busy">{{ $t('auth.register.submit') }}</button>
|
||||
<UiAuthCard :title="$t('auth.register.title')">
|
||||
<p v-if="mock" class="mb-4 rounded-lg bg-amber-50 px-3 py-2 text-xs text-amber-800">{{ $t('auth.mock_hint') }}</p>
|
||||
<form class="space-y-4" @submit.prevent="submit">
|
||||
<label class="block">
|
||||
<span class="label">{{ $t('auth.name') }}</span>
|
||||
<input v-model="name" class="input" type="text" autocomplete="nickname" required />
|
||||
</label>
|
||||
<label class="block">
|
||||
<span class="label">{{ $t('auth.email') }}</span>
|
||||
<input v-model="email" class="input" type="email" autocomplete="email" required />
|
||||
</label>
|
||||
<label class="block">
|
||||
<span class="label">{{ $t('auth.password') }}</span>
|
||||
<input v-model="password" class="input" type="password" autocomplete="new-password" required />
|
||||
</label>
|
||||
<p v-if="error" class="alert" role="alert">{{ error }}</p>
|
||||
<button type="submit" class="btn btn-primary w-full py-2" :disabled="busy">{{ $t('auth.register.submit') }}</button>
|
||||
</form>
|
||||
<p><NuxtLink to="/login">{{ $t('auth.register.to_login') }}</NuxtLink></p>
|
||||
</section>
|
||||
<template #footer>
|
||||
<NuxtLink to="/login" class="font-medium text-amber-800 hover:underline">{{ $t('auth.register.to_login') }}</NuxtLink>
|
||||
</template>
|
||||
</UiAuthCard>
|
||||
</template>
|
||||
|
|
|
|||
|
|
@ -16,33 +16,46 @@ async function resetMock() {
|
|||
</script>
|
||||
|
||||
<template>
|
||||
<section>
|
||||
<h1>{{ $t('worlds.title') }}</h1>
|
||||
<p v-if="error" role="alert">{{ error }}</p>
|
||||
<p v-if="!worlds">{{ $t('common.loading') }}</p>
|
||||
<p v-else-if="!worlds.length">{{ $t('worlds.none') }}</p>
|
||||
<table v-else>
|
||||
<thead>
|
||||
<tr>
|
||||
<th>{{ $t('worlds.name') }}</th>
|
||||
<th>{{ $t('worlds.speed') }}</th>
|
||||
<th>{{ $t('worlds.village') }}</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr v-for="w in worlds" :key="w.id">
|
||||
<td>{{ w.name }}</td>
|
||||
<td>{{ w.speed }}×</td>
|
||||
<td>
|
||||
<button type="button" :disabled="busy" @click="enter(w.id)">
|
||||
<div class="mx-auto max-w-2xl px-4 py-10">
|
||||
<header class="mb-6">
|
||||
<h1 class="font-display text-3xl font-semibold">{{ $t('worlds.title') }}</h1>
|
||||
<p class="mt-1 text-ink-500">{{ $t('worlds.subtitle') }}</p>
|
||||
</header>
|
||||
|
||||
<p v-if="error" class="alert mb-4" role="alert">{{ error }}</p>
|
||||
|
||||
<div class="panel overflow-hidden">
|
||||
<p v-if="!worlds" class="px-4 py-8 text-center text-sm text-ink-500">{{ $t('common.loading') }}</p>
|
||||
<p v-else-if="!worlds.length" class="px-4 py-8 text-center text-sm text-ink-500">{{ $t('worlds.none') }}</p>
|
||||
<ul v-else class="divide-y divide-parchment-200">
|
||||
<li v-for="w in worlds" :key="w.id" class="flex items-center gap-4 px-4 py-4">
|
||||
<span class="grid size-11 shrink-0 place-items-center rounded-xl bg-sky-50 text-sky-700 ring-1 ring-sky-200">
|
||||
<IconUi name="globe" class="size-6" />
|
||||
</span>
|
||||
<div class="min-w-0 flex-1">
|
||||
<p class="truncate font-medium">{{ w.name }}</p>
|
||||
<p class="mt-0.5 flex flex-wrap gap-1.5">
|
||||
<span class="badge bg-parchment-200 text-ink-700">{{ $t('worlds.speed_value', { speed: w.speed }) }}</span>
|
||||
<span v-if="w.village_id" class="badge bg-emerald-100 text-emerald-800">{{ $t('worlds.joined') }}</span>
|
||||
</p>
|
||||
</div>
|
||||
<button
|
||||
type="button"
|
||||
class="btn"
|
||||
:class="w.village_id ? 'btn-primary' : 'btn-outline'"
|
||||
:disabled="busy"
|
||||
@click="enter(w.id)"
|
||||
>
|
||||
{{ w.village_id ? $t('worlds.open') : $t('worlds.join') }}
|
||||
</button>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
<p v-if="mock">
|
||||
<button type="button" :disabled="busy" @click="resetMock">{{ $t('worlds.reset') }}</button>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
<p v-if="mock" class="mt-6 text-center">
|
||||
<button type="button" class="btn btn-ghost text-xs text-ink-500" :disabled="busy" @click="resetMock">
|
||||
{{ $t('worlds.reset') }}
|
||||
</button>
|
||||
</p>
|
||||
</section>
|
||||
</div>
|
||||
</template>
|
||||
|
|
|
|||
|
|
@ -9,6 +9,7 @@ export default {
|
|||
},
|
||||
common: {
|
||||
loading: 'Loading…',
|
||||
clear: 'Clear',
|
||||
},
|
||||
resources: {
|
||||
wood: 'Wood',
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@ export default {
|
|||
email: 'Email',
|
||||
password: 'Password',
|
||||
mock_hint: 'Mock server: any email and password work.',
|
||||
tagline: 'Plan your village, one building at a time.',
|
||||
login: {
|
||||
title: 'Log in',
|
||||
submit: 'Log in',
|
||||
|
|
|
|||
|
|
@ -4,8 +4,11 @@ export default {
|
|||
en: {
|
||||
worlds: {
|
||||
title: 'Worlds',
|
||||
subtitle: 'Each world has its own map, speed and players.',
|
||||
name: 'World',
|
||||
speed: 'Speed',
|
||||
speed_value: 'Speed {speed}×',
|
||||
joined: 'Your village is here',
|
||||
village: 'Your village',
|
||||
join: 'Join',
|
||||
open: 'Open village',
|
||||
|
|
|
|||
Loading…
Reference in New Issue