Lib: Remove caching from dropdown options generators

This commit is contained in:
2025-02-05 01:49:40 +01:00
parent 206d897fca
commit 2a51c76e2f

View File

@ -9,16 +9,11 @@ import {
TEAM_BANNER_WIDTH, TEAM_BANNER_WIDTH,
} from "$lib/config"; } from "$lib/config";
let team_dropdown_opts: DropdownOption[] | null = null;
/** /**
* Generates a list of [DropdownOptions] for a <Dropdown> component. * Generates a list of [DropdownOptions] for a <Dropdown> component.
* Cached until page reload.
*/ */
export const team_dropdown_options = (teams: Team[]): DropdownOption[] => { export const team_dropdown_options = (teams: Team[]): DropdownOption[] =>
if (!team_dropdown_opts) { teams.map((team: Team) => {
console.log("team_dropdown_options");
team_dropdown_opts = teams.map((team: Team) => {
return { return {
label: team.name, label: team.name,
value: team.id, value: team.id,
@ -27,17 +22,12 @@ export const team_dropdown_options = (teams: Team[]): DropdownOption[] => {
icon_height: TEAM_BANNER_HEIGHT, icon_height: TEAM_BANNER_HEIGHT,
}; };
}); });
}
return team_dropdown_opts;
};
/** /**
* Generates a list of [DropdownOptions] for a <Dropdown> component. * Generates a list of [DropdownOptions] for a <Dropdown> component.
* Not cached, because drivers are often filtered by active/inactive.
*/ */
export const driver_dropdown_options = (drivers: Driver[]): DropdownOption[] => { export const driver_dropdown_options = (drivers: Driver[]): DropdownOption[] =>
return drivers.map((driver: Driver) => { drivers.map((driver: Driver) => {
return { return {
label: driver.code, label: driver.code,
value: driver.id, value: driver.id,
@ -46,18 +36,12 @@ export const driver_dropdown_options = (drivers: Driver[]): DropdownOption[] =>
icon_height: DRIVER_HEADSHOT_HEIGHT, icon_height: DRIVER_HEADSHOT_HEIGHT,
}; };
}); });
};
let race_dropdown_opts: DropdownOption[] | null = null;
/** /**
* Generates a list of [DropdownOptions] for a <Dropdown> component. * Generates a list of [DropdownOptions] for a <Dropdown> component.
* Cached until page reload.
*/ */
export const race_dropdown_options = (races: Race[]): DropdownOption[] => { export const race_dropdown_options = (races: Race[]): DropdownOption[] =>
if (!race_dropdown_opts) { races.map((race: Race) => {
console.log("race_dropdown_options");
race_dropdown_opts = races.map((race: Race) => {
return { return {
label: race.name, label: race.name,
value: race.id, value: race.id,
@ -66,7 +50,3 @@ export const race_dropdown_options = (races: Race[]): DropdownOption[] => {
icon_height: RACE_PICTOGRAM_HEIGHT, icon_height: RACE_PICTOGRAM_HEIGHT,
}; };
}); });
}
return race_dropdown_opts;
};