Compare commits

..

3 Commits

Author SHA1 Message Date
91fc3ae7a2 Lib: Add "Select Random" button to RacePickCard
All checks were successful
Build Formula11 Docker Image / pocketbase-docker (push) Successful in 26s
2025-02-07 00:04:40 +01:00
88fb24a20c Lib: Refactor nullhandling in RaceResultCard 2025-02-06 23:59:26 +01:00
6f4b5e45cc Lib: Update RacePickCard labelwidth 2025-02-06 23:13:35 +01:00
2 changed files with 22 additions and 6 deletions

View File

@ -46,7 +46,7 @@
data.substitutions.then((s: Substitution[]) => (substitutions = s));
// Constants
const labelwidth: string = "60px";
const labelwidth: string = "70px";
// Reactive state
let required: boolean = $derived(!racepick);
@ -84,6 +84,18 @@
const img: HTMLImageElement = document.getElementById("headshot_preview") as HTMLImageElement;
if (img) img.src = src;
});
const random_select_handler = (event: Event): void => {
pxx_select_value =
active_drivers_and_substitutes[
Math.floor(Math.random() * active_drivers_and_substitutes.length)
].id;
dnf_select_value =
active_drivers_and_substitutes[
Math.floor(Math.random() * active_drivers_and_substitutes.length)
].id;
};
</script>
{#await Promise.all([data.graphics, data.drivers]) then [graphics, drivers]}
@ -136,6 +148,10 @@
DNF
</Dropdown>
<Button color="tertiary" {disabled} width="w-full" onclick={random_select_handler}>
Select Random
</Button>
<!-- Save/Delete buttons -->
<div class="flex justify-end gap-2">
{#if racepick}

View File

@ -118,7 +118,7 @@
};
const on_pxxs_chip_select = (event: CustomEvent<AutocompleteOption<string>>): void => {
if (disabled) return;
if (disabled || !currentrace || !drivers) return;
// Can only select 7 drivers
if (pxxs_chips.length >= 7) return;
@ -127,11 +127,11 @@
if (pxxs_chips.some((label: string) => label.endsWith(event.detail.value))) return;
// Manage labels that are displayed
pxxs_chips.push(`P${(currentrace?.pxx ?? -10) + pxxs_chips.length - 3}: ${event.detail.value}`);
pxxs_chips.push(`P${currentrace.pxx + pxxs_chips.length - 3}: ${event.detail.value}`);
pxxs_input = "";
// Manage ids that are submitted via form
const id: string = get_by_value(drivers ?? [], "code", event.detail.value)?.id ?? "Invalid";
const id: string = get_by_value(drivers, "code", event.detail.value)?.id ?? "Invalid";
if (!pxxs_ids.includes(id)) {
pxxs_ids.push(id);
}
@ -147,7 +147,7 @@
};
const on_dnfs_chip_select = (event: CustomEvent<AutocompleteOption<string>>): void => {
if (disabled) return;
if (disabled || !drivers) return;
// Can only select a driver once
if (dnfs_chips.includes(event.detail.value)) return;
@ -157,7 +157,7 @@
dnfs_input = "";
// Manage ids that are submitted via form
const id: string = get_by_value(drivers ?? [], "code", event.detail.value)?.id ?? "Invalid";
const id: string = get_by_value(drivers, "code", event.detail.value)?.id ?? "Invalid";
if (!dnfs_ids.includes(id)) {
dnfs_ids.push(id);
}