48 lines
1.8 KiB
Vue
48 lines
1.8 KiB
Vue
<script setup lang="ts">
|
||
import type { Report } from '~/types/game'
|
||
|
||
definePageMeta({ layout: 'game' })
|
||
|
||
const route = useRoute()
|
||
const worldId = Number(route.params.worldId)
|
||
const { error, show } = useReports(worldId)
|
||
useCurrentWorld().enter(worldId)
|
||
const { t } = useI18n()
|
||
const clock = useNow()
|
||
|
||
const report = ref<Report | null>(null)
|
||
watch(
|
||
() => route.params.id,
|
||
async (id) => (report.value = await show(Number(id))),
|
||
{ immediate: true },
|
||
)
|
||
|
||
const subject = computed(() => {
|
||
const r = report.value
|
||
if (!r) return ''
|
||
if (r.type === 'support') return t('reports.title_support', { from: villageLabel(r.payload.from), to: villageLabel(r.payload.to) })
|
||
return t('reports.title_attack', { from: villageLabel(r.payload.attacker.village), to: villageLabel(r.payload.defender.village) })
|
||
})
|
||
</script>
|
||
|
||
<template>
|
||
<div class="p-2.5">
|
||
<NuxtLink :to="`/reports/${worldId}`" class="btn btn-outline mb-3">‹ {{ $t('reports.back') }}</NuxtLink>
|
||
<p v-if="error" class="alert mb-3" role="alert">{{ error }}</p>
|
||
<section v-if="report" class="panel">
|
||
<div class="panel-head">
|
||
<h1 class="panel-title">{{ subject }}</h1>
|
||
<span class="text-sm whitespace-nowrap text-ink-700 tabular-nums">{{ formatArrival(Date.parse(report.happened_at), clock, t) }}</span>
|
||
</div>
|
||
<div class="panel-body">
|
||
<ReportBattle v-if="report.type !== 'support'" :report="report.payload" :world-id="worldId" />
|
||
<div v-else class="space-y-3 text-sm">
|
||
<p>{{ $t('reports.support.arrived', { to: villageLabel(report.payload.to) }) }}</p>
|
||
<ReportUnits :units="report.payload.units" :lost="null" />
|
||
</div>
|
||
</div>
|
||
</section>
|
||
<p v-else-if="!error" class="py-6 text-center text-sm text-ink-500">{{ $t('common.loading') }}</p>
|
||
</div>
|
||
</template>
|