diff --git a/src/lib/components/cards/TeamCard.svelte b/src/lib/components/cards/TeamCard.svelte index 3adcadf..5ceaefa 100644 --- a/src/lib/components/cards/TeamCard.svelte +++ b/src/lib/components/cards/TeamCard.svelte @@ -5,176 +5,136 @@ import type { Team } from "$lib/schema"; import { TEAM_BANNER_HEIGHT, TEAM_BANNER_WIDTH } from "$lib/config"; import { enhance } from "$app/forms"; + import { get_team_banner_template, get_team_logo_template } from "$lib/database"; interface TeamCardProps { + /** Data from the page context */ + data: any; + /** The [Team] object used to prefill values. */ - team?: Team | undefined; - - /** Disable all inputs if [true] */ - disable_inputs?: boolean; - - /** Require all inputs if [true] */ - require_inputs?: boolean; - - /** The [src] of the team banner template preview */ - banner_template?: string; - - /** The [src] of the team logo template preview */ - logo_template?: string; + team?: Team; } - let { - team = undefined, - disable_inputs = false, - require_inputs = false, - banner_template = "", - logo_template = "", - }: TeamCardProps = $props(); + let { data, team = undefined }: TeamCardProps = $props(); const modalStore: ModalStore = getModalStore(); if ($modalStore[0].meta) { const meta = $modalStore[0].meta; - // Stuff thats required for the "update" card + data = meta.data; team = meta.team; - disable_inputs = meta.disable_inputs; - - // Stuff thats additionally required for the "create" card - require_inputs = meta.require_inputs; - banner_template = meta.banner_template; - logo_template = meta.logo_template; } + const required: boolean = $derived(!team); + const disabled: boolean = $derived(!data.admin); const labelwidth: string = "110px"; - let colorpreview: string = $state(team?.color ?? "white"); + let colorpreview: string = $state(team?.color ?? "Invalid"); - modalStore.close()} -> -
- - - {#if team && !disable_inputs} - - {/if} +{#await data.graphics then graphics} + modalStore.close()} + > + modalStore.close()} + > + + + {#if team && !disabled} + + {/if} -
- - - Name - - - - { - colorpreview = (event.target as HTMLInputElement).value; - }} - > - Color - - C - - - - - - Upload Banner + + - + Name + - - - -
- Upload Logo - -
-
-
+ + { + colorpreview = (event.target as HTMLInputElement).value; + }} + {labelwidth} + {disabled} + {required} + > + Color + + C + + - -
- {#if team} - - - {:else} - - {/if} + + + + Upload Banner + + + + + + +
+ Upload Logo + +
+
+
+ + +
+ {#if team} + + + {:else} + + {/if} +
-
- -
+ +
+{/await} diff --git a/src/routes/data/season/teams/+page.svelte b/src/routes/data/season/teams/+page.svelte index 1229a2e..4d5d5b3 100644 --- a/src/routes/data/season/teams/+page.svelte +++ b/src/routes/data/season/teams/+page.svelte @@ -3,11 +3,30 @@ import type { Team } from "$lib/schema"; import { getModalStore, type ModalSettings, type ModalStore } from "@skeletonlabs/skeleton"; import type { PageData } from "./$types"; - import { get_by_value, get_team_banner_template, get_team_logo_template } from "$lib/database"; + import { get_by_value } from "$lib/database"; let { data }: { data: PageData } = $props(); - const teams_columns: TableColumn[] = [ + const modalStore: ModalStore = getModalStore(); + const team_handler = async (event: Event, id?: string) => { + const team: Team | undefined = get_by_value(await data.teams, "id", id ?? "Invalid"); + + // If we expect to find a team but don't, abort + if (id && !team) return; + + const modalSettings: ModalSettings = { + type: "component", + component: "teamCard", + meta: { + data, + team, + }, + }; + + modalStore.trigger(modalSettings); + }; + + const teams_columns: TableColumn[] = $derived([ { data_value_name: "name", label: "Name", @@ -20,47 +39,14 @@ valuefun: async (value: string): Promise => `C`, }, - ]; - - const modalStore: ModalStore = getModalStore(); - - const teams_handler = async (event: Event, id: string) => { - const team: Team | undefined = get_by_value(await data.teams, "id", id); - if (!team) return; - - const modalSettings: ModalSettings = { - type: "component", - component: "teamCard", - meta: { - team: team, - disable_inputs: !data.admin, - }, - }; - - modalStore.trigger(modalSettings); - }; - - const create_team_handler = async (event: Event) => { - const modalSettings: ModalSettings = { - type: "component", - component: "teamCard", - meta: { - banner_template: get_team_banner_template(await data.graphics), - logo_template: get_team_logo_template(await data.graphics), - require_inputs: true, - disable_inputs: !data.admin, - }, - }; - - modalStore.trigger(modalSettings); - }; + ]);
-
{#await data.teams then teams} - +
{/await}