Lib: Add helpers to obtain certain template graphics
This commit is contained in:
@ -1,3 +1,5 @@
|
|||||||
|
import type { Graphic } from "$lib/schema";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Select an element from an [objects] array where [key] matches [value].
|
* Select an element from an [objects] array where [key] matches [value].
|
||||||
* Supposed to be used on collections returned by the [PocketBase] client.
|
* 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 => {
|
): T | undefined => {
|
||||||
return objects.find((o: T) => (key in o ? o[key] === value : false));
|
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";
|
||||||
|
Reference in New Issue
Block a user