Adds unreviewed notification bubble in Admin hunts list
This commit is contained in:
@@ -2,7 +2,7 @@
|
|||||||
import {push} from 'svelte-spa-router'
|
import {push} from 'svelte-spa-router'
|
||||||
import {auth} from '../../lib/stores/auth.svelte'
|
import {auth} from '../../lib/stores/auth.svelte'
|
||||||
import {huntStatus, formatDate} from '../../lib/utils'
|
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 type {HuntResponse} from '../../lib/api/types'
|
||||||
import StatusBadge from '../../lib/components/StatusBadge.svelte'
|
import StatusBadge from '../../lib/components/StatusBadge.svelte'
|
||||||
import LoadingSpinner from '../../lib/components/LoadingSpinner.svelte'
|
import LoadingSpinner from '../../lib/components/LoadingSpinner.svelte'
|
||||||
@@ -15,10 +15,21 @@
|
|||||||
let hunts = $state<HuntResponse[]>([])
|
let hunts = $state<HuntResponse[]>([])
|
||||||
let loading = $state(true)
|
let loading = $state(true)
|
||||||
let error = $state('')
|
let error = $state('')
|
||||||
|
let unreviewedCounts = $state<Record<string, number>>({})
|
||||||
|
|
||||||
$effect(() => {
|
$effect(() => {
|
||||||
apiGetAllHunts()
|
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' })
|
.catch(e => { error = e instanceof Error ? e.message : 'Failed to load' })
|
||||||
.finally(() => { loading = false })
|
.finally(() => { loading = false })
|
||||||
})
|
})
|
||||||
@@ -58,6 +69,9 @@
|
|||||||
<div class="card-actions justify-end gap-2 mt-1">
|
<div class="card-actions justify-end gap-2 mt-1">
|
||||||
<button class="btn btn-outline btn-xs" onclick={() => push(`/admin/hunt/${hunt.id}/review`)}>
|
<button class="btn btn-outline btn-xs" onclick={() => push(`/admin/hunt/${hunt.id}/review`)}>
|
||||||
Review Photos
|
Review Photos
|
||||||
|
{#if (unreviewedCounts[hunt.id] ?? 0) > 0}
|
||||||
|
<span class="badge badge-error badge-sm">{unreviewedCounts[hunt.id]}</span>
|
||||||
|
{/if}
|
||||||
</button>
|
</button>
|
||||||
<button class="btn btn-primary btn-xs" onclick={() => push(`/admin/hunt/${hunt.id}`)}>
|
<button class="btn btn-primary btn-xs" onclick={() => push(`/admin/hunt/${hunt.id}`)}>
|
||||||
Manage
|
Manage
|
||||||
|
|||||||
Reference in New Issue
Block a user