From 2a124b72015caa3dfb904482baed37712c1d05a8 Mon Sep 17 00:00:00 2001 From: Christoph Urlacher Date: Sun, 26 Jan 2025 13:02:49 +0100 Subject: [PATCH] Data/Season: Sort substitutions table by race step --- src/routes/data/season/+layout.server.ts | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/routes/data/season/+layout.server.ts b/src/routes/data/season/+layout.server.ts index 95c83af..0923e88 100644 --- a/src/routes/data/season/+layout.server.ts +++ b/src/routes/data/season/+layout.server.ts @@ -29,6 +29,7 @@ export const load: LayoutServerLoad = async ({ fetch, locals }) => { return teams; }; + // TODO: Duplicated code from racepicks/+page.server.ts const fetch_drivers = async (): Promise => { const drivers: Driver[] = await locals.pb.collection("drivers").getFullList({ sort: "+code", @@ -56,11 +57,14 @@ export const load: LayoutServerLoad = async ({ fetch, locals }) => { }; const fetch_substitutions = async (): Promise => { - // TODO: Sort by race step (does the race need to be expanded for this?) const substitutions: Substitution[] = await locals.pb.collection("substitutions").getFullList({ + expand: "race", fetch: fetch, }); + // Sort by race step (ascending) + substitutions.sort((a, b) => a.expand.race.step - b.expand.race.step); + return substitutions; }; @@ -69,7 +73,7 @@ export const load: LayoutServerLoad = async ({ fetch, locals }) => { graphics: await fetch_graphics(), teams: await fetch_teams(), - // The rest is streamed gradually, since the user has to switch tabs to need them. + // The rest is streamed gradually, since the user has to switch pages to need them. drivers: fetch_drivers(), races: fetch_races(), substitutions: fetch_substitutions(),