Data/Raceresults: Implement initial raceresult display table

This commit is contained in:
2025-01-31 22:56:06 +01:00
parent 25e41f7ae4
commit 43b0fd9aa2
4 changed files with 140 additions and 5 deletions

View File

@ -0,0 +1,47 @@
import type { Driver, Race, RaceResult } from "$lib/schema";
import type { Actions, PageServerLoad } from "./$types";
export const actions = {} as Actions;
export const load: PageServerLoad = async ({ fetch, locals }) => {
// TODO: Duplicated code from racepicks/+page.server.ts
const fetch_raceresults = async (): Promise<RaceResult[]> => {
const raceresults: RaceResult[] = await locals.pb.collection("raceresultsdesc").getFullList();
return raceresults;
};
// TODO: Duplicated code from data/season/+layout.server.ts and racepicks/+page.server.ts
const fetch_races = async (): Promise<Race[]> => {
const races: Race[] = await locals.pb.collection("races").getFullList({
sort: "+step",
fetch: fetch,
});
races.map((race: Race) => {
race.pictogram_url = locals.pb.files.getURL(race, race.pictogram);
});
return races;
};
// TODO: Duplicated code from data/season/+layout.server.ts and racepicks/+page.server.ts
const fetch_drivers = async (): Promise<Driver[]> => {
const drivers: Driver[] = await locals.pb.collection("drivers").getFullList({
sort: "+code",
fetch: fetch,
});
drivers.map((driver: Driver) => {
driver.headshot_url = locals.pb.files.getURL(driver, driver.headshot);
});
return drivers;
};
return {
results: await fetch_raceresults(),
races: await fetch_races(),
drivers: await fetch_drivers(),
};
};

View File

@ -1 +1,88 @@
<h1>Race Results</h1>
<script lang="ts">
import { getModalStore, type ModalSettings, type ModalStore } from "@skeletonlabs/skeleton";
import type { PageData } from "./$types";
import { Button, Table, type TableColumn } from "$lib/components";
import { get_by_value } from "$lib/database";
import type { Driver } from "$lib/schema";
let { data }: { data: PageData } = $props();
const results_columns: TableColumn[] = [
{
data_value_name: "race",
label: "Step",
valuefun: async (value: string): Promise<string> =>
`<span class='badge variant-filled-surface'>${get_by_value(data.races, "id", value)?.step}</span>`,
},
{
data_value_name: "race",
label: "Race",
valuefun: async (value: string): Promise<string> =>
`<span class='badge variant-filled-surface'>${get_by_value(data.races, "id", value)?.name}</span>`,
},
{
data_value_name: "race",
label: "Guessed",
valuefun: async (value: string): Promise<string> =>
`<span>P${get_by_value(data.races, "id", value)?.pxx}</span>`,
},
{
data_value_name: "pxxs",
label: "Standing",
valuefun: async (value: string): Promise<string> => {
const pxxs_array: string[] = value.toString().split(",");
const pxxs_codes: string[] = pxxs_array.map(
(id: string) => get_by_value(data.drivers, "id", id)?.code ?? "Invalid",
);
return pxxs_codes.join(" - ");
},
},
{
data_value_name: "dnfs",
label: "DNFs",
valuefun: async (value: string): Promise<string> => {
if (value.length === 0 || value === "") return "";
const dnfs_array: string[] = value.toString().split(",");
const dnfs_codes: string[] = dnfs_array.map(
(id: string) => get_by_value(data.drivers, "id", id)?.code ?? "Invalid",
);
return dnfs_codes.join(" - ");
},
},
];
const modalStore: ModalStore = getModalStore();
const results_handler = async (event: Event, id: string) => {
const modalSettings: ModalSettings = {
type: "component",
component: "raceResultCard",
meta: {
disable_inputs: !data.admin,
},
};
modalStore.trigger(modalSettings);
};
const create_result_handler = (event: Event) => {
const modalSettings: ModalSettings = {
type: "component",
component: "raceResultsCard",
meta: {
require_inputs: true,
disable_inputs: !data.admin,
},
};
};
</script>
<div class="pb-2">
<Button width="w-full" color="tertiary" onclick={create_result_handler} shadow>
<span class="font-bold">Create Race Result</span>
</Button>
</div>
<Table data={data.results} columns={results_columns} handler={results_handler} />

View File

@ -30,7 +30,7 @@ export const load: LayoutServerLoad = async ({ fetch, locals }) => {
return teams;
};
// TODO: Duplicated code from racepicks/+page.server.ts
// TODO: Duplicated code from racepicks/+page.server.ts and data/raceresults/+page.server.ts
const fetch_drivers = async (): Promise<Driver[]> => {
const drivers: Driver[] = await locals.pb.collection("drivers").getFullList({
sort: "+code",
@ -44,7 +44,7 @@ export const load: LayoutServerLoad = async ({ fetch, locals }) => {
return drivers;
};
// TODO: Duplicated code from racepicks/+page.server.ts
// TODO: Duplicated code from racepicks/+page.server.ts and data/raceresults/+page.server.ts
const fetch_races = async (): Promise<Race[]> => {
const races: Race[] = await locals.pb.collection("races").getFullList({
sort: "+step",

View File

@ -45,6 +45,7 @@ export const load: PageServerLoad = async ({ fetch, locals }) => {
return currentpickedusers;
};
// TODO: Duplicated code from data/raceresults/+page.server.ts
const fetch_raceresults = async (): Promise<RaceResult[]> => {
// Don't expand races/pxxs/dnfs since we already fetched those
const raceresults: RaceResult[] = await locals.pb.collection("raceresultsdesc").getFullList();
@ -52,7 +53,7 @@ export const load: PageServerLoad = async ({ fetch, locals }) => {
return raceresults;
};
// TODO: Duplicated code from data/season/+layout.server.ts
// TODO: Duplicated code from data/season/+layout.server.ts and data/raceresults/+page.server.ts
const fetch_drivers = async (): Promise<Driver[]> => {
const drivers: Driver[] = await locals.pb.collection("drivers").getFullList({
sort: "+code",
@ -66,7 +67,7 @@ export const load: PageServerLoad = async ({ fetch, locals }) => {
return drivers;
};
// TODO: Duplicated code from data/season/+layout.server.ts
// TODO: Duplicated code from data/season/+layout.server.ts and data/raceresults/+page.server.ts
const fetch_races = async (): Promise<Race[]> => {
const races: Race[] = await locals.pb.collection("races").getFullList({
sort: "+step",