diff --git a/src/lib/dropdown.ts b/src/lib/dropdown.ts index 3a5fac6..20af50b 100644 --- a/src/lib/dropdown.ts +++ b/src/lib/dropdown.ts @@ -9,35 +9,25 @@ import { TEAM_BANNER_WIDTH, } from "$lib/config"; -let team_dropdown_opts: DropdownOption[] | null = null; +/** + * Generates a list of [DropdownOptions] for a component. + */ +export const team_dropdown_options = (teams: Team[]): DropdownOption[] => + teams.map((team: Team) => { + return { + label: team.name, + value: team.id, + icon_url: team.banner_url, + icon_width: TEAM_BANNER_WIDTH, + icon_height: TEAM_BANNER_HEIGHT, + }; + }); /** * Generates a list of [DropdownOptions] for a component. - * Cached until page reload. */ -export const team_dropdown_options = (teams: Team[]): DropdownOption[] => { - if (!team_dropdown_opts) { - console.log("team_dropdown_options"); - team_dropdown_opts = teams.map((team: Team) => { - return { - label: team.name, - value: team.id, - icon_url: team.banner_url, - icon_width: TEAM_BANNER_WIDTH, - icon_height: TEAM_BANNER_HEIGHT, - }; - }); - } - - return team_dropdown_opts; -}; - -/** - * Generates a list of [DropdownOptions] for a component. - * Not cached, because drivers are often filtered by active/inactive. - */ -export const driver_dropdown_options = (drivers: Driver[]): DropdownOption[] => { - return drivers.map((driver: Driver) => { +export const driver_dropdown_options = (drivers: Driver[]): DropdownOption[] => + drivers.map((driver: Driver) => { return { label: driver.code, value: driver.id, @@ -46,27 +36,17 @@ export const driver_dropdown_options = (drivers: Driver[]): DropdownOption[] => icon_height: DRIVER_HEADSHOT_HEIGHT, }; }); -}; - -let race_dropdown_opts: DropdownOption[] | null = null; /** * Generates a list of [DropdownOptions] for a component. - * Cached until page reload. */ -export const race_dropdown_options = (races: Race[]): DropdownOption[] => { - if (!race_dropdown_opts) { - console.log("race_dropdown_options"); - race_dropdown_opts = races.map((race: Race) => { - return { - label: race.name, - value: race.id, - icon_url: race.pictogram_url, - icon_width: RACE_PICTOGRAM_WIDTH, - icon_height: RACE_PICTOGRAM_HEIGHT, - }; - }); - } - - return race_dropdown_opts; -}; +export const race_dropdown_options = (races: Race[]): DropdownOption[] => + races.map((race: Race) => { + return { + label: race.name, + value: race.id, + icon_url: race.pictogram_url, + icon_width: RACE_PICTOGRAM_WIDTH, + icon_height: RACE_PICTOGRAM_HEIGHT, + }; + });