Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -35,17 +35,10 @@ export const load: PageServerLoad = async (event) => {
throw e
})

// TODO(backend: list-owners): `List` leaves `owners` empty — only `Get` fills
// it — so each row costs a `Get` of its own, the whole hackathon tree fetched
// to read one edge of it. Until then the page makes one call per hackathon,
// in parallel. Once `List` carries owners for a caller who may read them,
// delete `ownersOf` and read `h.owners` straight off the list entry.
const owners = await Promise.all(hackathons.map((h) => ownersOf(event, h.id)))

// Only what the page draws. A `Get` carries every project, member and page
// of the hackathon; none of it belongs in the page payload.
// `List` fills `owners` for every hackathon the caller may read, which for an
// admin is all of them — so the owners arrive with the list, in one call.
return {
hackathons: hackathons.map((h, i) => ({
hackathons: hackathons.map((h) => ({
id: h.id,
name: h.name,
logo: h.logo,
Expand All @@ -54,41 +47,12 @@ export const load: PageServerLoad = async (event) => {
endsAt: h.endsAt,
visibility: h.visibility,
participantCount: h.participantCount,
owners: owners[i],
// Only what a badge shows, not the whole user record.
owners: h.owners.map((o) => ({
id: o.id,
displayName: o.displayName,
username: o.username,
})),
})),
}
}

type Owner = { id: string; displayName: string; username: string }

/**
* The hackathon's owners, or null when they could not be read.
*
* Null rather than a failed page: one hackathon deleted between `List` and its
* `Get`, or one refusal, should cost that row its owners and nothing else. The
* page says so on the row rather than showing an empty list, which would read
* as a hackathon nobody runs.
*/
async function ownersOf(
event: Parameters<PageServerLoad>[0],
hackathonId: string,
): Promise<Owner[] | null> {
const { hackathon } = requireGrpc(event.locals.grpc)
try {
const { hackathon: h } = await hackathon.get({ hackathonId })
if (!h) return null

return h.owners.map((o) => ({
id: o.id,
displayName: o.displayName,
username: o.username,
}))
} catch (e) {
event.locals.logger.warn(
{ err: e, hackathonId },
"manage/hackathons: could not read owners",
)

return null
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
let { data }: { data: PageData } = $props();

type Row = PageData['hackathons'][number];
type Owner = NonNullable<Row['owners']>[number];
type Owner = Row['owners'][number];

let search = $state('');

Expand Down Expand Up @@ -57,7 +57,7 @@
const filtered = $derived(
sorted.filter((h) => {
const group = whenGroup(h.status);
const owners = (h.owners ?? []).flatMap((o) => [o.displayName, o.username]);
const owners = h.owners.flatMap((o) => [o.displayName, o.username]);
return matchesAny(
[
h.name,
Expand Down Expand Up @@ -131,18 +131,11 @@
{/snippet}

{#snippet owners(h: Row)}
{#if h.owners === null}
<!-- Not an empty list: that would read as a hackathon nobody runs. -->
<span class="text-ink-3" title="The owners of this hackathon could not be read">
Couldn't load owners
</span>
{:else}
<div class="flex flex-wrap gap-1">
{#each h.owners as o (o.id)}
<span class="badge badge-neutral" title="@{o.username}">{ownerName(o)}</span>
{/each}
</div>
{/if}
<div class="flex flex-wrap gap-1">
{#each h.owners as o (o.id)}
<span class="badge badge-neutral" title="@{o.username}">{ownerName(o)}</span>
{/each}
</div>
{/snippet}

<div class="flex flex-col gap-6 px-4 py-8 sm:px-10 md:px-20">
Expand Down
Loading