62 lines
2.2 KiB
Vue
62 lines
2.2 KiB
Vue
<script setup lang="ts">
|
|
const { worlds, error, busy, refresh, join } = useWorld()
|
|
const mock = isMockServer
|
|
|
|
refresh()
|
|
|
|
async function enter(worldId: number) {
|
|
const villageId = await join(worldId)
|
|
if (villageId) await navigateTo(`/village/${villageId}`)
|
|
}
|
|
|
|
async function resetMock() {
|
|
await ws.send('mock.reset')
|
|
await refresh()
|
|
}
|
|
</script>
|
|
|
|
<template>
|
|
<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>
|
|
</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>
|
|
</div>
|
|
</template>
|