Compare commits

...

3 Commits

3 changed files with 49 additions and 5 deletions

View File

@ -82,3 +82,15 @@ export interface RacePick {
user: User;
};
}
export interface RaceResult {
id: string;
race: string;
pxxs: string[];
dnfs: string[];
expand: {
dnfs: Driver[];
pxxs: Driver[];
race: Race;
};
}

View File

@ -57,7 +57,8 @@
{
data_value_name: "expand",
label: "Step",
valuefun: async (value: { race: Race }): Promise<string> => value.race.step.toString(),
valuefun: async (value: { race: Race }): Promise<string> =>
`<span class='badge variant-filled-surface'>${value.race.step.toString()}</span>`,
},
{
data_value_name: "substitute",

View File

@ -1,18 +1,49 @@
import type { RacePick } from "$lib/schema";
import type { Driver, Race, RacePick, RaceResult } from "$lib/schema";
import type { PageServerLoad } from "./$types";
export const load: PageServerLoad = async ({ fetch, locals }) => {
const fetch_racepicks = async (): Promise<RacePick[]> => {
// TODO: What is faster, expanding everything or filling in using individual requests?
// Probably expanding everything directly...
// PXX/DNF is not expanded, as we have the drivers anyways (for guessing)
const racepicks: RacePick[] = await locals.pb
.collection("racepicks")
.getFullList({ fetch: fetch, expand: "user,race,pxx,dnf" });
.getFullList({ fetch: fetch, expand: "user,race" });
return racepicks;
};
const fetch_currentrace = async (): Promise<Race | null> => {
const currentrace: Race[] = await locals.pb.collection("currentrace").getFullList();
// The currentrace collection either has a single or no entries
return currentrace[0] ?? null;
};
const fetch_raceresults = async (): Promise<RaceResult[]> => {
const raceresults: RaceResult[] = await locals.pb
.collection("raceresults")
.getFullList({ expand: "race,pxxs,dnfs" });
return raceresults;
};
// TODO: Duplicated code from data/season/+layout.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 {
racepicks: await fetch_racepicks(),
currentrace: await fetch_currentrace(),
raceresults: await fetch_raceresults(),
drivers: await fetch_drivers(),
};
};