Racepicks: Use progressive form enhancement for racepicks
This commit is contained in:
@ -25,24 +25,26 @@
|
|||||||
|
|
||||||
let { data }: { data: PageData } = $props();
|
let { data }: { data: PageData } = $props();
|
||||||
|
|
||||||
const currentpick: RacePick | undefined =
|
let currentpick = (): RacePick | undefined =>
|
||||||
data.racepicks.filter(
|
data.racepicks.filter(
|
||||||
(racepick: RacePick) =>
|
(racepick: RacePick) =>
|
||||||
racepick.expand.user.username === data.user?.username &&
|
racepick.expand.user.username === data.user?.username &&
|
||||||
racepick.race === data.currentrace?.id,
|
racepick.race === data.currentrace?.id,
|
||||||
)[0] ?? undefined;
|
)[0] ?? undefined;
|
||||||
|
|
||||||
let pxx_select_value: string = $state(currentpick?.pxx ?? "");
|
let pxx_select_value: string = $state(currentpick()?.pxx ?? "");
|
||||||
let dnf_select_value: string = $state(currentpick?.dnf ?? "");
|
let dnf_select_value: string = $state(currentpick()?.dnf ?? "");
|
||||||
|
|
||||||
const active_drivers_and_substitutes = (
|
const active_drivers_and_substitutes = (
|
||||||
drivers: Driver[],
|
drivers: Driver[],
|
||||||
substitutions: Substitution[],
|
substitutions: Substitution[],
|
||||||
): Driver[] => {
|
): Driver[] => {
|
||||||
|
if (!data.currentrace) return [];
|
||||||
|
|
||||||
let active_and_substitutes: Driver[] = drivers.filter((driver: Driver) => driver.active);
|
let active_and_substitutes: Driver[] = drivers.filter((driver: Driver) => driver.active);
|
||||||
|
|
||||||
substitutions
|
substitutions
|
||||||
.filter((substitution: Substitution) => substitution.race === currentpick.race)
|
.filter((substitution: Substitution) => substitution.race === data.currentrace?.id)
|
||||||
.forEach((substitution: Substitution) => {
|
.forEach((substitution: Substitution) => {
|
||||||
const for_index = active_and_substitutes.findIndex(
|
const for_index = active_and_substitutes.findIndex(
|
||||||
(driver: Driver) => driver.id === substitution.for,
|
(driver: Driver) => driver.id === substitution.for,
|
||||||
@ -63,7 +65,7 @@
|
|||||||
type: "component",
|
type: "component",
|
||||||
component: "racePickCard",
|
component: "racePickCard",
|
||||||
meta: {
|
meta: {
|
||||||
racepick: currentpick,
|
racepick: currentpick(),
|
||||||
currentrace: data.currentrace,
|
currentrace: data.currentrace,
|
||||||
user: data.user,
|
user: data.user,
|
||||||
drivers: active_drivers_and_substitutes(await data.drivers, await data.substitutions),
|
drivers: active_drivers_and_substitutes(await data.drivers, await data.substitutions),
|
||||||
@ -156,7 +158,7 @@
|
|||||||
{#await data.graphics then graphics}
|
{#await data.graphics then graphics}
|
||||||
{#await data.drivers then drivers}
|
{#await data.drivers then drivers}
|
||||||
<LazyImage
|
<LazyImage
|
||||||
src={get_by_value(drivers, "id", currentpick?.pxx ?? "")?.headshot_url ??
|
src={get_by_value(drivers, "id", currentpick()?.pxx ?? "")?.headshot_url ??
|
||||||
get_driver_headshot_template(graphics)}
|
get_driver_headshot_template(graphics)}
|
||||||
imgwidth={DRIVER_HEADSHOT_WIDTH}
|
imgwidth={DRIVER_HEADSHOT_WIDTH}
|
||||||
imgheight={DRIVER_HEADSHOT_HEIGHT}
|
imgheight={DRIVER_HEADSHOT_HEIGHT}
|
||||||
@ -173,7 +175,7 @@
|
|||||||
{#await data.graphics then graphics}
|
{#await data.graphics then graphics}
|
||||||
{#await data.drivers then drivers}
|
{#await data.drivers then drivers}
|
||||||
<LazyImage
|
<LazyImage
|
||||||
src={get_by_value(drivers, "id", currentpick?.dnf ?? "")?.headshot_url ??
|
src={get_by_value(drivers, "id", currentpick()?.dnf ?? "")?.headshot_url ??
|
||||||
get_driver_headshot_template(graphics)}
|
get_driver_headshot_template(graphics)}
|
||||||
imgwidth={DRIVER_HEADSHOT_WIDTH}
|
imgwidth={DRIVER_HEADSHOT_WIDTH}
|
||||||
imgheight={DRIVER_HEADSHOT_HEIGHT}
|
imgheight={DRIVER_HEADSHOT_HEIGHT}
|
||||||
|
Reference in New Issue
Block a user