diff --git a/src/routes/admin/AdminHome.svelte b/src/routes/admin/AdminHome.svelte index 2e84d45..267ac89 100644 --- a/src/routes/admin/AdminHome.svelte +++ b/src/routes/admin/AdminHome.svelte @@ -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([]) let loading = $state(true) let error = $state('') + let unreviewedCounts = $state>({}) $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 @@