diff --git a/src/lib/components/cards/RaceCard.svelte b/src/lib/components/cards/RaceCard.svelte index c50790b..0369794 100644 --- a/src/lib/components/cards/RaceCard.svelte +++ b/src/lib/components/cards/RaceCard.svelte @@ -6,214 +6,193 @@ import { format } from "date-fns"; import { RACE_PICTOGRAM_HEIGHT, RACE_PICTOGRAM_WIDTH } from "$lib/config"; import { enhance } from "$app/forms"; + import { get_race_pictogram_template } from "$lib/database"; interface RaceCardProps { + /** Data passed from the page context */ + data: any; + /** The [Race] object used to prefill values. */ - race?: Race | undefined; - - /** Disable all inputs if [true] */ - disable_inputs?: boolean; - - /** Require all inputs if [true] */ - require_inputs?: boolean; - - /** The [src] of the race pictogram template preview */ - pictogram_template?: string; + race?: Race; } - let { - race = undefined, - disable_inputs = false, - require_inputs = false, - pictogram_template = "", - }: RaceCardProps = $props(); + let { data, race = undefined }: RaceCardProps = $props(); const modalStore: ModalStore = getModalStore(); if ($modalStore[0].meta) { const meta = $modalStore[0].meta; - // Stuff thats required for the "update" card + data = meta.data; race = meta.race; - disable_inputs = meta.disable_inputs; - - // Stuff thats additionally required for the "create" card - require_inputs = meta.require_inputs; - pictogram_template = meta.pictogram_template; } + const clear_sprint = () => { + (document.getElementById("sqdate") as HTMLInputElement).value = ""; + (document.getElementById("sdate") as HTMLInputElement).value = ""; + }; + + const required: boolean = $derived(!race); + const disabled: boolean = $derived(!data.admin); + const labelwidth = "80px"; + // Dates have to be formatted to datetime-local format const dateformat: string = "yyyy-MM-dd'T'HH:mm"; - const sprintqualidate: string | undefined = - race && race.sprintqualidate ? format(new Date(race.sprintqualidate), dateformat) : undefined; - const sprintdate: string | undefined = - race && race.sprintdate ? format(new Date(race.sprintdate), dateformat) : undefined; - const qualidate: string | undefined = race - ? format(new Date(race.qualidate), dateformat) - : undefined; - const racedate: string | undefined = race - ? format(new Date(race.racedate), dateformat) - : undefined; - - const clear_sprint = () => { - const sprintquali: HTMLInputElement = document.getElementById( - `race_sprintqualidate_${race?.id ?? "create"}`, - ) as HTMLInputElement; - const sprint: HTMLInputElement = document.getElementById( - `race_sprintdate_${race?.id ?? "create"}`, - ) as HTMLInputElement; - - sprintquali.value = ""; - sprint.value = ""; - }; - - const labelwidth = "80px"; + const sprintqualidate: string | undefined = $derived( + race?.sprintqualidate ? format(new Date(race.sprintqualidate), dateformat) : undefined, + ); + const sprintdate: string | undefined = $derived( + race?.sprintdate ? format(new Date(race.sprintdate), dateformat) : undefined, + ); + const qualidate: string | undefined = $derived( + race ? format(new Date(race.qualidate), dateformat) : undefined, + ); + const racedate: string | undefined = $derived( + race ? format(new Date(race.racedate), dateformat) : undefined, + ); - modalStore.close()} -> -
- - - {#if race && !disable_inputs} - - {/if} +{#await data.graphics then graphics} + modalStore.close()} + > + modalStore.close()} + > + + + {#if race && !disabled} + + {/if} -
- - Name - Step - PXX - - - SQuali - SRace - Quali - Race - - - - Upload Pictogram + + - + Name + + + Step + + + PXX + - -
- - {#if race} + + + SQuali + + + SRace + + + Quali + + + Race + + + + + + Upload Pictogram + + + + +
- - {:else} - - {/if} + {#if race} + + + {:else} + + {/if} +
-
- -
+ +
+{/await} diff --git a/src/routes/data/season/races/+page.svelte b/src/routes/data/season/races/+page.svelte index 761b8d2..e21f92f 100644 --- a/src/routes/data/season/races/+page.svelte +++ b/src/routes/data/season/races/+page.svelte @@ -2,12 +2,31 @@ import { Button, Table, type TableColumn } from "$lib/components"; import { getModalStore, type ModalSettings, type ModalStore } from "@skeletonlabs/skeleton"; import type { PageData } from "./$types"; - import { get_by_value, get_race_pictogram_template } from "$lib/database"; + import { get_by_value } from "$lib/database"; import type { Race } from "$lib/schema"; let { data }: { data: PageData } = $props(); - const races_columns: TableColumn[] = [ + const modalStore: ModalStore = getModalStore(); + + const race_handler = async (event: Event, id?: string) => { + const race: Race | undefined = get_by_value(await data.races, "id", id ?? "Invalid"); + + if (id && !race) return; + + const modalSettings: ModalSettings = { + type: "component", + component: "raceCard", + meta: { + data, + race, + }, + }; + + modalStore.trigger(modalSettings); + }; + + const races_columns: TableColumn[] = $derived([ { data_value_name: "name", label: "Name", @@ -35,46 +54,14 @@ label: "Race", valuefun: async (value: string): Promise => value.slice(0, -5), }, - ]; - - const modalStore: ModalStore = getModalStore(); - - const races_handler = async (event: Event, id: string) => { - const race: Race | undefined = get_by_value(await data.races, "id", id); - if (!race) return; - - const modalSettings: ModalSettings = { - type: "component", - component: "raceCard", - meta: { - race: race, - disable_inputs: !data.admin, - }, - }; - - modalStore.trigger(modalSettings); - }; - - const create_race_handler = async (event: Event) => { - const modalSettings: ModalSettings = { - type: "component", - component: "raceCard", - meta: { - disable_inputs: !data.admin, - require_inputs: true, - pictogram_template: get_race_pictogram_template(await data.graphics), - }, - }; - - modalStore.trigger(modalSettings); - }; + ]);
-
{#await data.races then races} - +
{/await}