86 lines
4.5 KiB
Vue
86 lines
4.5 KiB
Vue
<script setup lang="ts">
|
||
import type { Report } from '~/types/game'
|
||
|
||
const route = useRoute()
|
||
const worldId = Number(route.params.worldId)
|
||
const { page, error, busy, load, remove, readAll } = useReports(worldId)
|
||
useCurrentWorld().enter(worldId)
|
||
const { t } = useI18n()
|
||
const clock = useNow()
|
||
|
||
load(Number(route.query.page) || 1)
|
||
|
||
const selected = ref<number[]>([])
|
||
watch(page, () => (selected.value = []))
|
||
const allSelected = computed(() => !!page.value?.reports.length && selected.value.length === page.value.reports.length)
|
||
function toggleAll() {
|
||
selected.value = allSelected.value ? [] : (page.value?.reports.map((r) => r.id) ?? [])
|
||
}
|
||
|
||
function subject(r: Report) {
|
||
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) })
|
||
}
|
||
|
||
const DOT = { won: 'bg-moss-600', losses: 'bg-gold-500', lost: 'bg-blood-700', info: 'bg-iron-400' }
|
||
</script>
|
||
|
||
<!-- The report list, like Die Stämme's: a coloured dot for the outcome, unread in bold, newest first. -->
|
||
<template>
|
||
<div class="mx-auto max-w-4xl px-4 py-6 sm:px-6">
|
||
<section class="panel">
|
||
<div class="panel-head">
|
||
<h1 class="panel-title">{{ $t('reports.title') }}</h1>
|
||
<button v-if="page?.unread" type="button" class="text-sm font-semibold text-blood-700 hover:underline" :disabled="busy" @click="readAll()">
|
||
{{ $t('reports.read_all') }}
|
||
</button>
|
||
</div>
|
||
<div class="panel-body">
|
||
<p v-if="error" class="alert mb-3" role="alert">{{ error }}</p>
|
||
<p v-if="!page" class="py-6 text-center text-sm text-ink-500">{{ $t('common.loading') }}</p>
|
||
<p v-else-if="!page.reports.length" class="py-6 text-center text-sm text-ink-500">{{ $t('reports.none') }}</p>
|
||
<template v-else>
|
||
<table class="w-full text-sm">
|
||
<thead>
|
||
<tr class="border-b-2 border-parchment-300 text-left text-xs text-ink-500">
|
||
<th class="w-8 py-1.5">
|
||
<input type="checkbox" :checked="allSelected" :aria-label="$t('reports.select_all')" @change="toggleAll" />
|
||
</th>
|
||
<th class="py-1.5 font-semibold">{{ $t('reports.subject') }}</th>
|
||
<th class="py-1.5 text-right font-semibold">{{ $t('reports.received') }}</th>
|
||
</tr>
|
||
</thead>
|
||
<tbody class="divide-y divide-parchment-300">
|
||
<tr v-for="r in page.reports" :key="r.id">
|
||
<td class="py-1.5">
|
||
<input v-model="selected" type="checkbox" :value="r.id" :aria-label="$t('reports.select', { subject: subject(r) })" />
|
||
</td>
|
||
<td class="py-1.5 pr-2">
|
||
<NuxtLink :to="`/reports/${worldId}/${r.id}`" class="flex items-center gap-2 hover:underline" :class="r.read ? '' : 'font-semibold'">
|
||
<span class="size-2.5 shrink-0 rounded-full" :class="DOT[reportTone(r)]" :title="$t(`reports.tone.${reportTone(r)}`)" />
|
||
<IconUi :name="r.type === 'support' ? 'support' : 'attack'" class="size-4 shrink-0 text-ink-500" />
|
||
<span class="min-w-0">{{ subject(r) }}</span>
|
||
<span v-if="!r.read" class="sr-only">({{ $t('reports.unread') }})</span>
|
||
</NuxtLink>
|
||
</td>
|
||
<td class="py-1.5 text-right whitespace-nowrap text-ink-700 tabular-nums">{{ formatArrival(Date.parse(r.happened_at), clock, t) }}</td>
|
||
</tr>
|
||
</tbody>
|
||
</table>
|
||
|
||
<div class="mt-3 flex flex-wrap items-center gap-2 border-t-2 border-parchment-300 pt-3">
|
||
<button type="button" class="btn btn-outline px-2.5 py-1" :disabled="busy || !selected.length" @click="remove(selected)">
|
||
{{ $t('reports.delete') }}
|
||
</button>
|
||
<div v-if="page.pages > 1" class="ml-auto flex items-center gap-2 text-sm">
|
||
<button type="button" class="btn btn-ghost px-2 py-1" :disabled="busy || page.page <= 1" @click="load(page.page - 1)">‹ {{ $t('reports.prev') }}</button>
|
||
<span class="tabular-nums text-ink-700">{{ $t('reports.page', { page: page.page, pages: page.pages }) }}</span>
|
||
<button type="button" class="btn btn-ghost px-2 py-1" :disabled="busy || page.page >= page.pages" @click="load(page.page + 1)">{{ $t('reports.next') }} ›</button>
|
||
</div>
|
||
</div>
|
||
</template>
|
||
</div>
|
||
</section>
|
||
</div>
|
||
</template>
|