Data/Season: Add "active" switches on drivers page
This commit is contained in:
@ -1,6 +1,6 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { get_image_preview_event_handler } from "$lib/image";
|
import { get_image_preview_event_handler } from "$lib/image";
|
||||||
import { FileDropzone } from "@skeletonlabs/skeleton";
|
import { FileDropzone, SlideToggle } from "@skeletonlabs/skeleton";
|
||||||
import Card from "./Card.svelte";
|
import Card from "./Card.svelte";
|
||||||
import Button from "./Button.svelte";
|
import Button from "./Button.svelte";
|
||||||
import type { Driver } from "$lib/schema";
|
import type { Driver } from "$lib/schema";
|
||||||
@ -20,13 +20,14 @@
|
|||||||
/** The [src] of the driver headshot template preview */
|
/** The [src] of the driver headshot template preview */
|
||||||
headshot_template?: string;
|
headshot_template?: string;
|
||||||
|
|
||||||
// TODO: Move into this component?
|
|
||||||
|
|
||||||
/** The value this component's team select dropdown will bind to */
|
/** The value this component's team select dropdown will bind to */
|
||||||
team_select_value: string;
|
team_select_value: string;
|
||||||
|
|
||||||
/** The options this component's team select dropdown will display */
|
/** The options this component's team select dropdown will display */
|
||||||
team_select_options: DropdownOption[];
|
team_select_options: DropdownOption[];
|
||||||
|
|
||||||
|
/** The value this component's active switch will bind to */
|
||||||
|
active_value: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
let {
|
let {
|
||||||
@ -36,6 +37,7 @@
|
|||||||
headshot_template = "",
|
headshot_template = "",
|
||||||
team_select_value,
|
team_select_value,
|
||||||
team_select_options,
|
team_select_options,
|
||||||
|
active_value,
|
||||||
}: DriverCardProps = $props();
|
}: DriverCardProps = $props();
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
@ -103,7 +105,15 @@
|
|||||||
</FileDropzone>
|
</FileDropzone>
|
||||||
|
|
||||||
<!-- Save/Delete buttons -->
|
<!-- Save/Delete buttons -->
|
||||||
<div class="flex justify-end gap-2">
|
<div class="flex items-center justify-end gap-2">
|
||||||
|
<div class="mr-auto">
|
||||||
|
<SlideToggle
|
||||||
|
name="active"
|
||||||
|
background="bg-primary-500"
|
||||||
|
active="bg-tertiary-500"
|
||||||
|
bind:checked={active_value}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
{#if driver}
|
{#if driver}
|
||||||
<Button formaction="?/update_driver" color="secondary" disabled={disable_inputs} submit
|
<Button formaction="?/update_driver" color="secondary" disabled={disable_inputs} submit
|
||||||
>Save Changes</Button
|
>Save Changes</Button
|
||||||
|
|||||||
@ -59,6 +59,9 @@ export const actions = {
|
|||||||
const data: FormData = form_data_clean(await request.formData());
|
const data: FormData = form_data_clean(await request.formData());
|
||||||
const id: string = form_data_get_and_remove_id(data);
|
const id: string = form_data_get_and_remove_id(data);
|
||||||
|
|
||||||
|
// The toggle switch will report "on" or nothing
|
||||||
|
data.set("active", data.has("active") ? "true" : "false");
|
||||||
|
|
||||||
await locals.pb.collection("drivers").update(id, data);
|
await locals.pb.collection("drivers").update(id, data);
|
||||||
|
|
||||||
return { tab: 1 };
|
return { tab: 1 };
|
||||||
|
|||||||
@ -19,13 +19,18 @@
|
|||||||
current_tab = form.tab;
|
current_tab = form.tab;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Values for driver cards
|
||||||
// Maps driver to team: <driver.id, team.id>
|
// Maps driver to team: <driver.id, team.id>
|
||||||
let update_driver_team_select_values: { [key: string]: string } = $state({});
|
let update_driver_team_select_values: { [key: string]: string } = $state({});
|
||||||
|
let update_driver_active_values: { [key: string]: boolean } = $state({});
|
||||||
data.drivers.forEach((driver: Driver) => {
|
data.drivers.forEach((driver: Driver) => {
|
||||||
update_driver_team_select_values[driver.id] = driver.team;
|
update_driver_team_select_values[driver.id] = driver.team;
|
||||||
|
update_driver_active_values[driver.id] = driver.active;
|
||||||
});
|
});
|
||||||
update_driver_team_select_values["create"] = "";
|
update_driver_team_select_values["create"] = "";
|
||||||
|
update_driver_active_values["create"] = true;
|
||||||
|
|
||||||
|
// Values for substitution cards
|
||||||
let update_substitution_substitute_select_values: { [key: string]: string } = $state({});
|
let update_substitution_substitute_select_values: { [key: string]: string } = $state({});
|
||||||
let update_substitution_for_select_values: { [key: string]: string } = $state({});
|
let update_substitution_for_select_values: { [key: string]: string } = $state({});
|
||||||
let update_substitution_race_select_values: { [key: string]: string } = $state({});
|
let update_substitution_race_select_values: { [key: string]: string } = $state({});
|
||||||
@ -105,6 +110,7 @@
|
|||||||
disable_inputs={!data.admin}
|
disable_inputs={!data.admin}
|
||||||
team_select_value={update_driver_team_select_values[driver.id]}
|
team_select_value={update_driver_team_select_values[driver.id]}
|
||||||
team_select_options={team_dropdown_options}
|
team_select_options={team_dropdown_options}
|
||||||
|
active_value={update_driver_active_values[driver.id]}
|
||||||
/>
|
/>
|
||||||
{/each}
|
{/each}
|
||||||
|
|
||||||
@ -114,6 +120,7 @@
|
|||||||
headshot_template={get_by_value(data.graphics, "name", "driver_template")?.file_url}
|
headshot_template={get_by_value(data.graphics, "name", "driver_template")?.file_url}
|
||||||
team_select_value={update_driver_team_select_values["create"]}
|
team_select_value={update_driver_team_select_values["create"]}
|
||||||
team_select_options={team_dropdown_options}
|
team_select_options={team_dropdown_options}
|
||||||
|
active_value={update_driver_active_values["create"]}
|
||||||
require_inputs
|
require_inputs
|
||||||
/>
|
/>
|
||||||
{/if}
|
{/if}
|
||||||
|
|||||||
Reference in New Issue
Block a user