From 178adef32704175c1392b3eec27766ad410aa3b7 Mon Sep 17 00:00:00 2001 From: Christoph Urlacher Date: Wed, 5 Feb 2025 21:56:41 +0100 Subject: [PATCH] Lib: Simplify RaceResultCard --- .../components/cards/RaceResultCard.svelte | 267 +++++++++--------- src/routes/data/raceresults/+page.svelte | 60 ++-- 2 files changed, 156 insertions(+), 171 deletions(-) diff --git a/src/lib/components/cards/RaceResultCard.svelte b/src/lib/components/cards/RaceResultCard.svelte index 3b27e04..2339592 100644 --- a/src/lib/components/cards/RaceResultCard.svelte +++ b/src/lib/components/cards/RaceResultCard.svelte @@ -7,96 +7,69 @@ type ModalStore, } from "@skeletonlabs/skeleton"; import { Button, Card, Dropdown } from "$lib/components"; - import type { Driver, Race, RaceResult } from "$lib/schema"; + import type { Driver, Race, RaceResult, SkeletonData } from "$lib/schema"; import { get_by_value } from "$lib/database"; import { race_dropdown_options } from "$lib/dropdown"; import { enhance } from "$app/forms"; interface RaceResultCardProps { + /** Data passed from the page context */ + data: SkeletonData & { results: RaceResult[] }; + /** The [RaceResult] object used to prefill values. */ result?: RaceResult; - - /** The list of [Drivers] for the driver selection */ - drivers: Driver[]; - - /** The list of [Races] for the race selection + PXX display */ - races: Race[]; - - /** Disable all inputs if [true] */ - disable_inputs?: boolean; - - /** Require all inputs if [true] */ - require_inputs?: boolean; } - let { - result = undefined, - drivers, - races, - disable_inputs = false, - require_inputs = false, - }: RaceResultCardProps = $props(); + let { data, result = undefined }: RaceResultCardProps = $props(); - // TODO: This does not work at all. Why does it work for other cards??? - // Everything exists here, but in the markup it is undefined??? const modalStore: ModalStore = getModalStore(); if ($modalStore[0].meta) { const meta = $modalStore[0].meta; - // Stuff thats required for the "update" card - disable_inputs = meta.disable_inputs; - drivers = meta.drivers; - races = meta.races; + data = meta.data; result = meta.result; - - // Stuff thats additionally required for the "create" card - require_inputs = meta.require_inputs; } - const currentrace: Race | undefined = get_by_value(races, "id", result?.race ?? "Invalid"); + const required: boolean = $derived(!result); + const disabled: boolean = $derived(!data.admin); + const labelwidth: string = "70px"; + const currentrace: Promise = $derived.by(async () => + get_by_value(await data.races, "id", result?.race ?? "Invalid"), + ); - // TODO: I have no fucking idea why this solves things... - // Without this, the original values passed through the modalStore - // are undefined within the markup, but not within the -
+ modalStore.close()}> - {#if result2 && !disable_inputs2} - + {#if result && !disabled} + {/if} {#each pxxs_ids as pxxs_id} - + {/each} {#each dnfs_ids as dnfs_id} - + {/each} - - Race - + {#await data.races then races} + + Race + + {/await}
- + {#await currentrace then current} + {#await pxxs_whitelist then whitelist} + + {/await} + {/await}
- + {#await pxxs_options then options} + + {/await}
- -
- + {/await} +
+ {#await pxxs_options then options} + + {/await}
- {#if result2} + {#if result} - {:else} diff --git a/src/routes/data/raceresults/+page.svelte b/src/routes/data/raceresults/+page.svelte index 9af05f5..4a35b52 100644 --- a/src/routes/data/raceresults/+page.svelte +++ b/src/routes/data/raceresults/+page.svelte @@ -4,10 +4,30 @@ import { Button, Table, type TableColumn } from "$lib/components"; import { get_by_value } from "$lib/database"; import { PXX_COLORS } from "$lib/config"; + import type { RaceResult } from "$lib/schema"; let { data }: { data: PageData } = $props(); - const results_columns: TableColumn[] = [ + const modalStore: ModalStore = getModalStore(); + + const result_handler = async (event: Event, id?: string) => { + const result: RaceResult | undefined = get_by_value(data.results, "id", id ?? "Invalid"); + + if (id && !result) return; + + const modalSettings: ModalSettings = { + type: "component", + component: "raceResultCard", + meta: { + data, + result, + }, + }; + + modalStore.trigger(modalSettings); + }; + + const results_columns: TableColumn[] = $derived([ { data_value_name: "race", label: "Step", @@ -58,44 +78,12 @@ return dnfs_codes.join(""); }, }, - ]; - - const modalStore: ModalStore = getModalStore(); - - const results_handler = async (event: Event, id: string) => { - const modalSettings: ModalSettings = { - type: "component", - component: "raceResultCard", - meta: { - disable_inputs: !data.admin, - drivers: await data.drivers, - races: await data.races, - result: get_by_value(data.results, "id", id), - }, - }; - - modalStore.trigger(modalSettings); - }; - - const create_result_handler = async (event: Event) => { - const modalSettings: ModalSettings = { - type: "component", - component: "raceResultCard", - meta: { - disable_inputs: !data.admin, - drivers: await data.drivers, - races: await data.races, - require_inputs: true, - }, - }; - - modalStore.trigger(modalSettings); - }; + ]);
-
- +