diff --git a/src/routes/data/season/+page.server.ts b/src/routes/data/season/+page.server.ts index ccc5c66..e219d43 100644 --- a/src/routes/data/season/+page.server.ts +++ b/src/routes/data/season/+page.server.ts @@ -1,4 +1,4 @@ -import type { Actions, PageServerLoad } from "./$types"; +import type { ActionData, Actions, PageServerLoad } from "./$types"; import { form_data_clean, form_data_ensure_keys, @@ -286,10 +286,13 @@ export const load: PageServerLoad = async ({ fetch, locals }) => { }; return { + // Graphics and teams are awaited, since those are visible on page load. graphics: await fetch_graphics(), teams: await fetch_teams(), - drivers: await fetch_drivers(), - races: await fetch_races(), - substitutions: await fetch_substitutions(), + + // The rest is streamed gradually, since the user has to switch tabs to need them. + drivers: fetch_drivers(), + races: fetch_races(), + substitutions: fetch_substitutions(), }; }; diff --git a/src/routes/data/season/+page.svelte b/src/routes/data/season/+page.svelte index 521b632..9bb1e77 100644 --- a/src/routes/data/season/+page.svelte +++ b/src/routes/data/season/+page.svelte @@ -17,47 +17,57 @@ } // Values for driver cards - // Maps driver to team: - let update_driver_team_select_values: { [key: string]: string } = $state({}); + let update_driver_team_select_values: { [key: string]: string } = $state({}); // let update_driver_active_values: { [key: string]: boolean } = $state({}); - data.drivers.forEach((driver: Driver) => { - update_driver_team_select_values[driver.id] = driver.team; - update_driver_active_values[driver.id] = driver.active; - }); + data.drivers.then((drivers: Driver[]) => + drivers.forEach((driver: Driver) => { + update_driver_team_select_values[driver.id] = driver.team; + update_driver_active_values[driver.id] = driver.active; + }), + ); update_driver_team_select_values["create"] = ""; update_driver_active_values["create"] = true; // Values for substitution cards - let update_substitution_substitute_select_values: { [key: string]: string } = $state({}); - let update_substitution_for_select_values: { [key: string]: string } = $state({}); - let update_substitution_race_select_values: { [key: string]: string } = $state({}); - data.substitutions.forEach((substitution: Substitution) => { - update_substitution_substitute_select_values[substitution.id] = substitution.substitute; - update_substitution_for_select_values[substitution.id] = substitution.for; - update_substitution_race_select_values[substitution.id] = substitution.race; - }); + const update_substitution_substitute_select_values: { [key: string]: string } = $state({}); + const update_substitution_for_select_values: { [key: string]: string } = $state({}); + const update_substitution_race_select_values: { [key: string]: string } = $state({}); + data.substitutions.then((substitutions: Substitution[]) => + substitutions.forEach((substitution: Substitution) => { + update_substitution_substitute_select_values[substitution.id] = substitution.substitute; + update_substitution_for_select_values[substitution.id] = substitution.for; + update_substitution_race_select_values[substitution.id] = substitution.race; + }), + ); update_substitution_substitute_select_values["create"] = ""; update_substitution_for_select_values["create"] = ""; update_substitution_race_select_values["create"] = ""; // All options to create a component for the teams - const team_dropdown_options: DropdownOption[] = data.teams.map((team: Team) => { - return { label: team.name, value: team.id, icon_url: team.logo_url } as DropdownOption; + const team_dropdown_options: DropdownOption[] = []; + data.teams.forEach((team: Team) => { + team_dropdown_options.push({ label: team.name, value: team.id, icon_url: team.logo_url }); }); // All options to create a component for the drivers - const driver_dropdown_options: DropdownOption[] = data.drivers.map((driver: Driver) => { - return { - label: driver.code, - value: driver.id, - icon_url: driver.headshot_url, - } as DropdownOption; - }); + const driver_dropdown_options: DropdownOption[] = []; + data.drivers.then((drivers: Driver[]) => + drivers.forEach((driver: Driver) => { + driver_dropdown_options.push({ + label: driver.code, + value: driver.id, + icon_url: driver.headshot_url, + }); + }), + ); // All options to create a component for the races - const race_dropdown_options: DropdownOption[] = data.races.map((race: Race) => { - return { label: race.name, value: race.id } as DropdownOption; - }); + const race_dropdown_options: DropdownOption[] = []; + data.races.then((races: Race[]) => + races.forEach((race: Race) => { + race_dropdown_options.push({ label: race.name, value: race.id }); + }), + ); @@ -116,15 +126,17 @@ {/if} - {#each data.drivers as driver} - - {/each} + {#await data.drivers then drivers} + {#each drivers as driver} + + {/each} + {/await} {:else if current_tab === 2} @@ -138,40 +150,48 @@ /> {/if} - {#each data.races as race} - - {/each} + {#await data.races then races} + {#each races as race} + + {/each} + {/await} {:else if current_tab === 3}
- {#if data.admin} - - {/if} + {#await data.drivers then drivers} + {#if data.admin} + + {/if} - {#each data.substitutions as substitution} - - {/each} + {#await data.substitutions then substitutions} + {#each substitutions as substitution} + + {/each} + {/await} + {/await}
{/if}