diff --git a/src/lib/components/cards/DriverCard.svelte b/src/lib/components/cards/DriverCard.svelte index e73b6d5..d24f5ef 100644 --- a/src/lib/components/cards/DriverCard.svelte +++ b/src/lib/components/cards/DriverCard.svelte @@ -7,185 +7,138 @@ type ModalStore, } from "@skeletonlabs/skeleton"; import { Button, Input, Card, Dropdown } from "$lib/components"; - import type { Driver, Team } from "$lib/schema"; + import type { Driver } from "$lib/schema"; import { DRIVER_HEADSHOT_HEIGHT, DRIVER_HEADSHOT_WIDTH } from "$lib/config"; import { team_dropdown_options } from "$lib/dropdown"; import { enhance } from "$app/forms"; + import { get_driver_headshot_template } from "$lib/database"; interface DriverCardProps { + /** Data passed from the page context */ + data: any; + /** The [Driver] object used to prefill values. */ - driver?: Driver | undefined; - - /** The teams (for the dropdown options) */ - teams: Team[]; - - /** Disable all inputs if [true] */ - disable_inputs?: boolean; - - /** Require all inputs if [true] */ - require_inputs?: boolean; - - /** The [src] of the driver headshot template preview */ - headshot_template?: string; - - /** The value this component's team select dropdown will bind to */ - // TODO: Move this into this component? Why am I passing it from the outside? - // This also applies to the other card components... - team_select_value: string; - - /** The value this component's active switch will bind to */ - active_value: boolean; + driver?: Driver; } - let { - driver = undefined, - teams, - disable_inputs = false, - require_inputs = false, - headshot_template = undefined, - team_select_value, - active_value, - }: DriverCardProps = $props(); + let { data, driver = undefined }: DriverCardProps = $props(); const modalStore: ModalStore = getModalStore(); if ($modalStore[0].meta) { const meta = $modalStore[0].meta; - // Stuff thats required for the "update" card + data = meta.data; driver = meta.driver; - teams = meta.teams; - team_select_value = meta.team_select_value; - active_value = meta.active_value; - disable_inputs = meta.disable_inputs; - - // Stuff thats additionally required for the "create" card - require_inputs = meta.require_inputs; - headshot_template = meta.headshot_template; } + + const required: boolean = $derived(!driver); + const disabled: boolean = $derived(!data.admin); + const labelwidth: string = "120px"; + + let team_select_value: string = $state(driver?.team ?? ""); + let active_value: boolean = $state(driver?.active ?? true); - modalStore.close()} -> -
- - - {#if driver && !disable_inputs} - - {/if} +{#await data.graphics then graphics} + modalStore.close()} + > + modalStore.close()} + > + + + {#if driver && !disabled} + + {/if} -
- - First Name - - Last Name - - Driver Code - - - - - Team - - - - - Upload Headshot + + + First Name + + - + Last Name + + + Driver Code + - -
-
- + + {#await data.teams then teams} + + Team + + {/await} + + + + + Upload Headshot + + + + +
+
+ +
+ {#if driver} + + + {:else} + + {/if}
- {#if driver} - - - {:else} - - {/if}
-
- - + + +{/await} diff --git a/src/routes/data/season/drivers/+page.svelte b/src/routes/data/season/drivers/+page.svelte index 6fbd6a5..79f0bff 100644 --- a/src/routes/data/season/drivers/+page.svelte +++ b/src/routes/data/season/drivers/+page.svelte @@ -1,24 +1,31 @@
-
{#await data.drivers then drivers} - +
{/await}