diff --git a/src/routes/admin/PhotoReview.svelte b/src/routes/admin/PhotoReview.svelte index 46cce09..c9430a7 100644 --- a/src/routes/admin/PhotoReview.svelte +++ b/src/routes/admin/PhotoReview.svelte @@ -14,12 +14,13 @@ if (!auth.isAdmin) push('/') }) + type PhotoWithTeam = PhotoResponse & { teamName: string } + let hunt = $state(null) let teams = $state([]) let items = $state([]) - let selectedTeam = $state(null) let selectedItem = $state(null) - let photos = $state([]) + let photos = $state([]) let loading = $state(true) let photosLoading = $state(false) let error = $state('') @@ -32,29 +33,28 @@ hunt = h teams = t items = i - // Pre-select team from query string if provided - const qs = new URLSearchParams(router.querystring ?? '') - const preTeam = qs.get('teamId') - if (preTeam) { - selectedTeam = t.find(x => x.id === preTeam) ?? null - } }) .catch(e => { error = e instanceof Error ? e.message : 'Failed to load' }) .finally(() => { loading = false }) }) $effect(() => { - if (selectedTeam && selectedItem) { + if (selectedItem) { photosLoading = true photos = [] - apiGetItemPhotos(params.huntId, selectedTeam.id, selectedItem.id) - .then(p => { photos = p }) + Promise.all( + teams.map(team => + apiGetItemPhotos(params.huntId, team.id, selectedItem!.id) + .then(ps => ps.map(p => ({ ...p, teamName: team.name }))) + ) + ) + .then(results => { photos = results.flat() }) .catch(e => { error = e instanceof Error ? e.message : 'Failed to load photos' }) .finally(() => { photosLoading = false }) } }) - async function review(photo: PhotoResponse, status: 'APPROVED' | 'REJECTED') { + async function review(photo: PhotoWithTeam, status: 'APPROVED' | 'REJECTED') { reviewing = photo.id try { await apiReviewPhoto(photo.id, status) @@ -82,43 +82,24 @@ {#if loading} {:else} - +
-

Select Team

+

Select Item

- {#each teams as team} + {#each items as item} {/each}
- {#if selectedTeam} - -
-

Select Item

-
- {#each items as item} - - {/each} -
-
- {/if} - - {#if selectedTeam && selectedItem} + {#if selectedItem} {#if photosLoading} {:else if activePhotos.length === 0} @@ -133,7 +114,7 @@
-

{photo.hunterName}

+

{photo.hunterName} ยท {photo.teamName}

{new Date(photo.photoUploadDateTime).toLocaleString()}