Lib: Use progressive form enhancement for all cards

This commit is contained in:
2025-02-04 23:01:35 +01:00
parent 09519c18fa
commit 887a9ea2ae
6 changed files with 36 additions and 7 deletions

View File

@ -10,6 +10,7 @@
import type { Driver, Team } from "$lib/schema"; import type { Driver, Team } from "$lib/schema";
import { DRIVER_HEADSHOT_HEIGHT, DRIVER_HEADSHOT_WIDTH } from "$lib/config"; import { DRIVER_HEADSHOT_HEIGHT, DRIVER_HEADSHOT_WIDTH } from "$lib/config";
import { team_dropdown_options } from "$lib/dropdown"; import { team_dropdown_options } from "$lib/dropdown";
import { enhance } from "$app/forms";
interface DriverCardProps { interface DriverCardProps {
/** The [Driver] object used to prefill values. */ /** The [Driver] object used to prefill values. */
@ -71,7 +72,7 @@
imgheight={DRIVER_HEADSHOT_HEIGHT} imgheight={DRIVER_HEADSHOT_HEIGHT}
imgonclick={(event: Event) => modalStore.close()} imgonclick={(event: Event) => modalStore.close()}
> >
<form method="POST" enctype="multipart/form-data"> <form method="POST" enctype="multipart/form-data" use:enhance>
<!-- This is also disabled, because the ID should only be --> <!-- This is also disabled, because the ID should only be -->
<!-- "leaked" to users that are allowed to use the inputs --> <!-- "leaked" to users that are allowed to use the inputs -->
{#if driver && !disable_inputs} {#if driver && !disable_inputs}
@ -158,6 +159,7 @@
disabled={disable_inputs} disabled={disable_inputs}
submit submit
width="w-1/2" width="w-1/2"
onclick={() => modalStore.close()}
> >
Save Save
</Button> </Button>
@ -167,6 +169,7 @@
disabled={disable_inputs} disabled={disable_inputs}
formaction="?/delete_driver" formaction="?/delete_driver"
width="w-1/2" width="w-1/2"
onclick={() => modalStore.close()}
> >
Delete Delete
</Button> </Button>
@ -177,6 +180,7 @@
submit submit
width="w-full" width="w-full"
disabled={disable_inputs} disabled={disable_inputs}
onclick={() => modalStore.close()}
> >
Create Driver Create Driver
</Button> </Button>

View File

@ -5,6 +5,7 @@
import type { Race } from "$lib/schema"; import type { Race } from "$lib/schema";
import { format } from "date-fns"; import { format } from "date-fns";
import { RACE_PICTOGRAM_HEIGHT, RACE_PICTOGRAM_WIDTH } from "$lib/config"; import { RACE_PICTOGRAM_HEIGHT, RACE_PICTOGRAM_WIDTH } from "$lib/config";
import { enhance } from "$app/forms";
interface RaceCardProps { interface RaceCardProps {
/** The [Race] object used to prefill values. */ /** The [Race] object used to prefill values. */
@ -76,7 +77,7 @@
imgheight={RACE_PICTOGRAM_HEIGHT} imgheight={RACE_PICTOGRAM_HEIGHT}
imgonclick={(event: Event) => modalStore.close()} imgonclick={(event: Event) => modalStore.close()}
> >
<form method="POST" enctype="multipart/form-data"> <form method="POST" enctype="multipart/form-data" use:enhance>
<!-- This is also disabled, because the ID should only be --> <!-- This is also disabled, because the ID should only be -->
<!-- "leaked" to users that are allowed to use the inputs --> <!-- "leaked" to users that are allowed to use the inputs -->
{#if race && !disable_inputs} {#if race && !disable_inputs}
@ -186,6 +187,7 @@
disabled={disable_inputs} disabled={disable_inputs}
submit submit
width="w-1/3" width="w-1/3"
onclick={() => modalStore.close()}
> >
Save Changes Save Changes
</Button> </Button>
@ -195,6 +197,7 @@
disabled={disable_inputs} disabled={disable_inputs}
formaction="?/delete_race" formaction="?/delete_race"
width="w-1/3" width="w-1/3"
onclick={() => modalStore.close()}
> >
Delete Delete
</Button> </Button>
@ -205,6 +208,7 @@
submit submit
width="w-1/2" width="w-1/2"
disabled={disable_inputs} disabled={disable_inputs}
onclick={() => modalStore.close()}
> >
Create Race Create Race
</Button> </Button>

View File

@ -6,6 +6,7 @@
import { getModalStore, type ModalStore } from "@skeletonlabs/skeleton"; import { getModalStore, type ModalStore } from "@skeletonlabs/skeleton";
import { DRIVER_HEADSHOT_HEIGHT, DRIVER_HEADSHOT_WIDTH } from "$lib/config"; import { DRIVER_HEADSHOT_HEIGHT, DRIVER_HEADSHOT_WIDTH } from "$lib/config";
import { driver_dropdown_options } from "$lib/dropdown"; import { driver_dropdown_options } from "$lib/dropdown";
import { enhance } from "$app/forms";
interface RacePickCardProps { interface RacePickCardProps {
/** The [RacePick] object used to prefill values. */ /** The [RacePick] object used to prefill values. */
@ -91,7 +92,7 @@
imgheight={DRIVER_HEADSHOT_HEIGHT} imgheight={DRIVER_HEADSHOT_HEIGHT}
imgonclick={(event: Event) => modalStore.close()} imgonclick={(event: Event) => modalStore.close()}
> >
<form method="POST" enctype="multipart/form-data"> <form method="POST" enctype="multipart/form-data" use:enhance>
<!-- This is also disabled, because the ID should only be --> <!-- This is also disabled, because the ID should only be -->
<!-- "leaked" to users that are allowed to use the inputs --> <!-- "leaked" to users that are allowed to use the inputs -->
{#if racepick && !disable_inputs} {#if racepick && !disable_inputs}
@ -134,6 +135,7 @@
disabled={disable_inputs} disabled={disable_inputs}
submit submit
width="w-1/2" width="w-1/2"
onclick={() => modalStore.close()}
> >
Save Changes Save Changes
</Button> </Button>
@ -143,11 +145,18 @@
disabled={disable_inputs} disabled={disable_inputs}
formaction="?/delete_racepick" formaction="?/delete_racepick"
width="w-1/2" width="w-1/2"
onclick={() => modalStore.close()}
> >
Delete Delete
</Button> </Button>
{:else} {:else}
<Button formaction="?/create_racepick" color="tertiary" submit width="w-full"> <Button
formaction="?/create_racepick"
color="tertiary"
submit
width="w-full"
onclick={() => modalStore.close()}
>
Make Pick Make Pick
</Button> </Button>
{/if} {/if}

View File

@ -10,6 +10,7 @@
import type { Driver, Race, RaceResult } from "$lib/schema"; import type { Driver, Race, RaceResult } from "$lib/schema";
import { get_by_value } from "$lib/database"; import { get_by_value } from "$lib/database";
import { race_dropdown_options } from "$lib/dropdown"; import { race_dropdown_options } from "$lib/dropdown";
import { enhance } from "$app/forms";
interface RaceResultCardProps { interface RaceResultCardProps {
/** The [RaceResult] object used to prefill values. */ /** The [RaceResult] object used to prefill values. */
@ -146,7 +147,7 @@
</script> </script>
<Card width="w-full sm:w-[512px]"> <Card width="w-full sm:w-[512px]">
<form method="POST" enctype="multipart/form-data"> <form method="POST" enctype="multipart/form-data" use:enhance>
<!-- This is also disabled, because the ID should only be --> <!-- This is also disabled, because the ID should only be -->
<!-- "leaked" to users that are allowed to use the inputs --> <!-- "leaked" to users that are allowed to use the inputs -->
{#if result2 && !disable_inputs2} {#if result2 && !disable_inputs2}
@ -224,6 +225,7 @@
disabled={disable_inputs2} disabled={disable_inputs2}
submit submit
width="w-1/2" width="w-1/2"
onclick={() => modalStore.close()}
> >
Save Save
</Button> </Button>
@ -233,6 +235,7 @@
disabled={disable_inputs2} disabled={disable_inputs2}
formaction="?/delete_raceresult" formaction="?/delete_raceresult"
width="w-1/2" width="w-1/2"
onclick={() => modalStore.close()}
> >
Delete Delete
</Button> </Button>
@ -243,6 +246,7 @@
submit submit
width="w-full" width="w-full"
disabled={disable_inputs2} disabled={disable_inputs2}
onclick={() => modalStore.close()}
> >
Create Result Create Result
</Button> </Button>

View File

@ -6,6 +6,7 @@
import { getModalStore, type ModalStore } from "@skeletonlabs/skeleton"; import { getModalStore, type ModalStore } from "@skeletonlabs/skeleton";
import { DRIVER_HEADSHOT_HEIGHT, DRIVER_HEADSHOT_WIDTH } from "$lib/config"; import { DRIVER_HEADSHOT_HEIGHT, DRIVER_HEADSHOT_WIDTH } from "$lib/config";
import { driver_dropdown_options, race_dropdown_options } from "$lib/dropdown"; import { driver_dropdown_options, race_dropdown_options } from "$lib/dropdown";
import { enhance } from "$app/forms";
interface SubstitutionCardProps { interface SubstitutionCardProps {
/** The [Substitution] object used to prefill values. */ /** The [Substitution] object used to prefill values. */
@ -104,7 +105,7 @@
imgheight={DRIVER_HEADSHOT_HEIGHT} imgheight={DRIVER_HEADSHOT_HEIGHT}
imgonclick={(event: Event) => modalStore.close()} imgonclick={(event: Event) => modalStore.close()}
> >
<form method="POST" enctype="multipart/form-data"> <form method="POST" enctype="multipart/form-data" use:enhance>
<!-- This is also disabled, because the ID should only be --> <!-- This is also disabled, because the ID should only be -->
<!-- "leaked" to users that are allowed to use the inputs --> <!-- "leaked" to users that are allowed to use the inputs -->
{#if substitution && !disable_inputs} {#if substitution && !disable_inputs}
@ -158,6 +159,7 @@
disabled={disable_inputs} disabled={disable_inputs}
submit submit
width="w-1/2" width="w-1/2"
onclick={() => modalStore.close()}
> >
Save Changes Save Changes
</Button> </Button>
@ -167,6 +169,7 @@
disabled={disable_inputs} disabled={disable_inputs}
formaction="?/delete_substitution" formaction="?/delete_substitution"
width="w-1/2" width="w-1/2"
onclick={() => modalStore.close()}
> >
Delete Delete
</Button> </Button>
@ -177,6 +180,7 @@
submit submit
width="w-full" width="w-full"
disabled={disable_inputs} disabled={disable_inputs}
onclick={() => modalStore.close()}
> >
Create Substitution Create Substitution
</Button> </Button>

View File

@ -4,6 +4,7 @@
import { Card, Button, Input, LazyImage } from "$lib/components"; import { Card, Button, Input, LazyImage } from "$lib/components";
import type { Team } from "$lib/schema"; import type { Team } from "$lib/schema";
import { TEAM_BANNER_HEIGHT, TEAM_BANNER_WIDTH } from "$lib/config"; import { TEAM_BANNER_HEIGHT, TEAM_BANNER_WIDTH } from "$lib/config";
import { enhance } from "$app/forms";
interface TeamCardProps { interface TeamCardProps {
/** The [Team] object used to prefill values. */ /** The [Team] object used to prefill values. */
@ -57,7 +58,7 @@
imgheight={TEAM_BANNER_HEIGHT} imgheight={TEAM_BANNER_HEIGHT}
imgonclick={(event: Event) => modalStore.close()} imgonclick={(event: Event) => modalStore.close()}
> >
<form method="POST" enctype="multipart/form-data"> <form method="POST" enctype="multipart/form-data" use:enhance>
<!-- This is also disabled, because the ID should only be --> <!-- This is also disabled, because the ID should only be -->
<!-- "leaked" to users that are allowed to use the inputs --> <!-- "leaked" to users that are allowed to use the inputs -->
{#if team && !disable_inputs} {#if team && !disable_inputs}
@ -147,6 +148,7 @@
disabled={disable_inputs} disabled={disable_inputs}
submit submit
width="w-1/2" width="w-1/2"
onclick={() => modalStore.close()}
> >
Save Save
</Button> </Button>
@ -156,6 +158,7 @@
disabled={disable_inputs} disabled={disable_inputs}
formaction="?/delete_team" formaction="?/delete_team"
width="w-1/2" width="w-1/2"
onclick={() => modalStore.close()}
> >
Delete Delete
</Button> </Button>
@ -166,6 +169,7 @@
submit submit
width="w-full" width="w-full"
disabled={disable_inputs} disabled={disable_inputs}
onclick={() => modalStore.close()}
> >
Create Team Create Team
</Button> </Button>