Adds unreviewed notification bubble in Admin hunts list

This commit is contained in:
2026-05-19 10:26:49 -05:00
parent 2c7cb00745
commit c6f1475b84

View File

@@ -2,7 +2,7 @@
import {push} from 'svelte-spa-router'
import {auth} from '../../lib/stores/auth.svelte'
import {huntStatus, formatDate} from '../../lib/utils'
import {apiGetAllHunts} from '../../lib/api/index'
import {apiGetAllHunts, apiGetUnreviewedPhotos} from '../../lib/api/index'
import type {HuntResponse} from '../../lib/api/types'
import StatusBadge from '../../lib/components/StatusBadge.svelte'
import LoadingSpinner from '../../lib/components/LoadingSpinner.svelte'
@@ -15,10 +15,21 @@
let hunts = $state<HuntResponse[]>([])
let loading = $state(true)
let error = $state('')
let unreviewedCounts = $state<Record<string, number>>({})
$effect(() => {
apiGetAllHunts()
.then(h => { hunts = h })
.then(async h => {
hunts = h
const counts = await Promise.all(
h.map(hunt =>
apiGetUnreviewedPhotos(hunt.id)
.then(photos => [hunt.id, photos.length] as const)
.catch(() => [hunt.id, 0] as const)
)
)
unreviewedCounts = Object.fromEntries(counts)
})
.catch(e => { error = e instanceof Error ? e.message : 'Failed to load' })
.finally(() => { loading = false })
})
@@ -58,6 +69,9 @@
<div class="card-actions justify-end gap-2 mt-1">
<button class="btn btn-outline btn-xs" onclick={() => push(`/admin/hunt/${hunt.id}/review`)}>
Review Photos
{#if (unreviewedCounts[hunt.id] ?? 0) > 0}
<span class="badge badge-error badge-sm">{unreviewedCounts[hunt.id]}</span>
{/if}
</button>
<button class="btn btn-primary btn-xs" onclick={() => push(`/admin/hunt/${hunt.id}`)}>
Manage