From cb8eb26d2277e3f0f3c5063fb7c2a302d165f164 Mon Sep 17 00:00:00 2001 From: Christoph Urlacher Date: Wed, 26 Feb 2025 21:04:21 +0100 Subject: [PATCH] Seasonpicks: Refactor current seasonpick acquisition + user new fetchers --- src/routes/seasonpicks/+page.svelte | 70 ++++++++++++++--------------- src/routes/seasonpicks/+page.ts | 12 ++++- 2 files changed, 46 insertions(+), 36 deletions(-) diff --git a/src/routes/seasonpicks/+page.svelte b/src/routes/seasonpicks/+page.svelte index 3d57d6d..89897d0 100644 --- a/src/routes/seasonpicks/+page.svelte +++ b/src/routes/seasonpicks/+page.svelte @@ -7,7 +7,7 @@ type ModalStore, } from "@skeletonlabs/skeleton"; import type { PageData } from "./$types"; - import type { SeasonPick, SeasonPickedUser } from "$lib/schema"; + import type { Hottake, SeasonPick } from "$lib/schema"; import { ChequeredFlagIcon, LazyImage } from "$lib/components"; import { get_by_value, @@ -25,13 +25,6 @@ let { data }: { data: PageData } = $props(); - const seasonpick: Promise = $derived.by( - async () => - (await data.seasonpicks).filter( - (seasonpick: SeasonPick) => seasonpick.expand.user.username === data.user?.username, - )[0] ?? undefined, - ); - const modalStore: ModalStore = getModalStore(); const seasonpick_handler = async (event: Event) => { const modalSettings: ModalSettings = { @@ -39,7 +32,7 @@ component: "seasonPickcard", meta: { data, - seasonpick: await seasonpick, + seasonpick: data.seasonpick, }, }; @@ -51,21 +44,20 @@ Formula 11 - Season Picks -{#await seasonpick then pick} - - - - - Your Season Pick - - - {pick?.hottake ?? "Invalid"} - - - -{/await} + + + + + Your Season Pick + + + {data.seasonpick?.hottake ?? "Invalid"} + + + +
@@ -126,16 +118,23 @@
+
- {#await Promise.all( [data.seasonpickedusers, data.seasonpicks, data.drivers, data.teams], ) then [seasonpicked, seasonpicks, drivers, teams]} - {#each seasonpicked.filter((user: SeasonPickedUser) => user.picked) as user} - {@const pick = seasonpicks.filter((pick: SeasonPick) => pick.user === user.id)[0]} - {@const wdcwinner = get_by_value(drivers, "id", pick.wdcwinner)} - {@const wccwinner = get_by_value(teams, "id", pick.wccwinner)} - {@const mostovertakes = get_by_value(drivers, "id", pick.mostovertakes)} - {@const mostdnfs = get_by_value(drivers, "id", pick.mostdnfs)} - {@const teamwinners = pick.teamwinners.map((id: string) => get_by_value(drivers, "id", id))} - {@const podiums = pick.podiums.map((id: string) => get_by_value(drivers, "id", id))} + {#await Promise.all( [data.seasonpickedusers, data.seasonpicks, data.hottakes, data.drivers, data.teams], ) then [seasonpicked, seasonpicks, hottakes, drivers, teams]} + {#each seasonpicked as user} + {@const hottake = hottakes.filter((take: Hottake) => take.user === user.id)[0] ?? undefined} + {@const pick = + seasonpicks.filter((pick: SeasonPick) => pick.user === user.id)[0] ?? undefined} + {@const wdcwinner = pick ? get_by_value(drivers, "id", pick.wdcwinner) : undefined} + {@const wccwinner = pick ? get_by_value(teams, "id", pick.wccwinner) : undefined} + {@const mostovertakes = pick ? get_by_value(drivers, "id", pick.mostovertakes) : undefined} + {@const mostdnfs = pick ? get_by_value(drivers, "id", pick.mostdnfs) : undefined} + {@const teamwinners = pick + ? pick.teamwinners.map((id: string) => get_by_value(drivers, "id", id)) + : [undefined]} + {@const podiums = pick + ? pick.podiums.map((id: string) => get_by_value(drivers, "id", id)) + : [undefined]}
-
{pick.hottake}
+
{hottake?.hottake ?? "?"}
@@ -224,12 +223,12 @@
- Jack Doohan startet {pick.doohanstarts} mal. + Jack Doohan startet {pick?.doohanstarts ?? "?"} mal.
- +
@@ -250,7 +249,8 @@
- + +
diff --git a/src/routes/seasonpicks/+page.ts b/src/routes/seasonpicks/+page.ts index 82ccd87..22c1097 100644 --- a/src/routes/seasonpicks/+page.ts +++ b/src/routes/seasonpicks/+page.ts @@ -1,4 +1,11 @@ -import { fetch_drivers, fetch_seasonpickedusers, fetch_seasonpicks, fetch_teams } from "$lib/fetch"; +import { + fetch_currentseasonpick, + fetch_drivers, + fetch_hottakes, + fetch_seasonpickedusers, + fetch_seasonpicks, + fetch_teams, +} from "$lib/fetch"; import type { PageLoad } from "../$types"; export const load: PageLoad = async ({ fetch, depends }) => { @@ -8,6 +15,9 @@ export const load: PageLoad = async ({ fetch, depends }) => { teams: fetch_teams(fetch), drivers: fetch_drivers(fetch), seasonpicks: fetch_seasonpicks(fetch), + hottakes: fetch_hottakes(fetch), seasonpickedusers: fetch_seasonpickedusers(fetch), + + seasonpick: await fetch_currentseasonpick(fetch), }; };