Lib: Add helpers to obtain certain template graphics

This commit is contained in:
2025-02-03 21:31:21 +01:00
parent 0dc5e63e25
commit 8db2b634d3

View File

@ -1,3 +1,5 @@
import type { Graphic } from "$lib/schema";
/**
* Select an element from an [objects] array where [key] matches [value].
* Supposed to be used on collections returned by the [PocketBase] client.
@ -9,3 +11,15 @@ export const get_by_value = <T extends object>(
): T | undefined => {
return objects.find((o: T) => (key in o ? o[key] === value : false));
};
export const get_team_banner_template = (graphics: Graphic[]) =>
get_by_value(graphics, "name", "team_banner_template")?.file_url ?? "Invalid";
export const get_team_logo_template = (graphics: Graphic[]) =>
get_by_value(graphics, "name", "team_logo_template")?.file_url ?? "Invalid";
export const get_driver_headshot_template = (graphics: Graphic[]) =>
get_by_value(graphics, "name", "driver_headshot_template")?.file_url ?? "Invalid";
export const get_race_pictogram_template = (graphics: Graphic[]) =>
get_by_value(graphics, "name", "race_pictogram_template")?.file_url ?? "Invalid";