Compare commits

..

4 Commits

11 changed files with 304 additions and 187 deletions

View File

@ -1,11 +1,11 @@
<script lang="ts"> <script lang="ts">
import { get_image_preview_event_handler } from "$lib/image"; import { get_image_preview_event_handler } from "$lib/image";
import { FileDropzone, SlideToggle } from "@skeletonlabs/skeleton"; import { FileDropzone, SlideToggle } from "@skeletonlabs/skeleton";
import Card from "./Card.svelte"; import LazyCard from "./LazyCard.svelte";
import Button from "./Button.svelte"; import Button from "./Button.svelte";
import type { Driver } from "$lib/schema"; import type { Driver } from "$lib/schema";
import Input from "./Input.svelte"; import Input from "./Input.svelte";
import Dropdown, { type DropdownOption } from "./Dropdown.svelte"; import LazyDropdown, { type DropdownOption } from "./LazyDropdown.svelte";
import { DRIVER_HEADSHOT_HEIGHT, DRIVER_HEADSHOT_WIDTH } from "$lib/config"; import { DRIVER_HEADSHOT_HEIGHT, DRIVER_HEADSHOT_WIDTH } from "$lib/config";
interface DriverCardProps { interface DriverCardProps {
@ -42,7 +42,7 @@
}: DriverCardProps = $props(); }: DriverCardProps = $props();
</script> </script>
<Card <LazyCard
imgsrc={driver?.headshot_url ?? headshot_template} imgsrc={driver?.headshot_url ?? headshot_template}
imgwidth={DRIVER_HEADSHOT_WIDTH} imgwidth={DRIVER_HEADSHOT_WIDTH}
imgheight={DRIVER_HEADSHOT_HEIGHT} imgheight={DRIVER_HEADSHOT_HEIGHT}
@ -64,8 +64,9 @@
autocomplete="off" autocomplete="off"
labelwidth="120px" labelwidth="120px"
disabled={disable_inputs} disabled={disable_inputs}
required={require_inputs}>First Name</Input required={require_inputs}
> >First Name
</Input>
<Input <Input
id="driver_last_name_{driver?.id ?? 'create'}" id="driver_last_name_{driver?.id ?? 'create'}"
name="lastname" name="lastname"
@ -73,8 +74,9 @@
autocomplete="off" autocomplete="off"
labelwidth="120px" labelwidth="120px"
disabled={disable_inputs} disabled={disable_inputs}
required={require_inputs}>Last Name</Input required={require_inputs}
> >Last Name
</Input>
<Input <Input
id="driver_code_{driver?.id ?? 'create'}" id="driver_code_{driver?.id ?? 'create'}"
name="code" name="code"
@ -84,18 +86,20 @@
maxlength={3} maxlength={3}
labelwidth="120px" labelwidth="120px"
disabled={disable_inputs} disabled={disable_inputs}
required={require_inputs}>Driver Code</Input required={require_inputs}
> >Driver Code
</Input>
<!-- Driver team input --> <!-- Driver team input -->
<Dropdown <LazyDropdown
name="team" name="team"
input_variable={team_select_value} input_variable={team_select_value}
options={team_select_options} options={team_select_options}
labelwidth="120px" labelwidth="120px"
disabled={disable_inputs} disabled={disable_inputs}
required={require_inputs}>Team</Dropdown required={require_inputs}
> >Team
</LazyDropdown>
<!-- Headshot upload --> <!-- Headshot upload -->
<FileDropzone <FileDropzone
@ -133,4 +137,4 @@
</div> </div>
</div> </div>
</form> </form>
</Card> </LazyCard>

View File

@ -1,6 +1,7 @@
<script lang="ts"> <script lang="ts">
import type { Snippet } from "svelte"; import type { Snippet } from "svelte";
import LazyImage from "./LazyImage.svelte"; import LazyImage from "./LazyImage.svelte";
import { lazyload } from "$lib/lazyload";
interface CardProps { interface CardProps {
children: Snippet; children: Snippet;
@ -12,10 +13,10 @@
imgid?: string | undefined; imgid?: string | undefined;
/** The aspect ratio width used to reserve image space (while its loading) */ /** The aspect ratio width used to reserve image space (while its loading) */
imgwidth?: number; imgwidth: number;
/** The aspect ratio height used to reserve image space (while its loading) */ /** The aspect ratio height used to reserve image space (while its loading) */
imgheight?: number; imgheight: number;
/** Hide the header image element. It can be shown by removing the "hidden" property using JS and the imgid. */ /** Hide the header image element. It can be shown by removing the "hidden" property using JS and the imgid. */
imghidden?: boolean; imghidden?: boolean;
@ -28,29 +29,39 @@
children, children,
imgsrc = undefined, imgsrc = undefined,
imgid = undefined, imgid = undefined,
imgwidth = undefined, imgwidth,
imgheight = undefined, imgheight,
imghidden = false, imghidden = false,
fullwidth = false, fullwidth = false,
...restProps ...restProps
}: CardProps = $props(); }: CardProps = $props();
let load: boolean = $state(false);
const lazy_visible_handler = () => {
load = true;
};
</script> </script>
<div use:lazyload onLazyVisible={lazy_visible_handler}>
{#if load}
<div class="card overflow-hidden bg-white shadow {fullwidth ? 'w-full' : 'w-auto'}"> <div class="card overflow-hidden bg-white shadow {fullwidth ? 'w-full' : 'w-auto'}">
<!-- Allow empty strings for images that only appear after user action --> <!-- Allow empty strings for images that only appear after user action -->
{#if imgsrc !== undefined} {#if imgsrc !== undefined}
<div style="width: auto; aspect-ratio: {imgwidth} / {imgheight};">
<LazyImage <LazyImage
id={imgid} id={imgid}
src={imgsrc} src={imgsrc}
{imgwidth}
{imgheight}
alt="Card header" alt="Card header"
draggable="false" draggable="false"
class="select-none shadow" class="select-none shadow"
hidden={imghidden} hidden={imghidden}
/> />
</div>
{/if} {/if}
<div class="p-2" {...restProps}> <div class="p-2" {...restProps}>
{@render children()} {@render children()}
</div> </div>
</div> </div>
{/if}
</div>

View File

@ -4,13 +4,26 @@
import type { Action } from "svelte/action"; import type { Action } from "svelte/action";
import type { HTMLInputAttributes } from "svelte/elements"; import type { HTMLInputAttributes } from "svelte/elements";
import { v4 as uuid } from "uuid"; import { v4 as uuid } from "uuid";
import LazyImage from "./LazyImage.svelte";
export interface DropdownOption { export interface LazyDropdownOption {
/** The label displayed in the list of options. */
label: string; label: string;
/** The value assigned to the dropdown value variable */
value: string; value: string;
/** An optional icon displayed left to the label */
icon_url?: string;
/** The aspect ratio width of the optional icon */
icon_width?: number;
/** The aspect ratio height of the optional icon */
icon_height?: number;
} }
interface SearchProps extends HTMLInputAttributes { interface LazyDropdownProps extends HTMLInputAttributes {
children: Snippet; children: Snippet;
/** Placeholder for the empty input element */ /** Placeholder for the empty input element */
@ -37,7 +50,7 @@
/** The options this autocomplete component allows to choose from. /** The options this autocomplete component allows to choose from.
* Example: [[{ label: "Aston", value: "0" }, { label: "VCARB", value: "1" }]]. * Example: [[{ label: "Aston", value: "0" }, { label: "VCARB", value: "1" }]].
*/ */
options: DropdownOption[]; options: LazyDropdownOption[];
} }
let { let {
@ -56,7 +69,7 @@
}, },
options, options,
...restProps ...restProps
}: SearchProps = $props(); }: LazyDropdownProps = $props();
/** Find the "label" of an option by its "value" */ /** Find the "label" of an option by its "value" */
const get_label = (value: string): string | undefined => { const get_label = (value: string): string | undefined => {
@ -78,6 +91,12 @@
if (input) input.dispatchEvent(new CustomEvent("DropdownChange")); if (input) input.dispatchEvent(new CustomEvent("DropdownChange"));
}); });
let load: boolean = $state(false);
const lazy_click_handler = () => {
load = true;
};
</script> </script>
<div class="input-group input-group-divider grid-cols-[auto_1fr_auto]"> <div class="input-group input-group-divider grid-cols-[auto_1fr_auto]">
@ -87,6 +106,7 @@
> >
{@render children()} {@render children()}
</div> </div>
<!-- TODO: How to assign use: conditionally? I don't wan't to repeat the entire input... -->
{#if action} {#if action}
<input <input
use:popup={popup_settings} use:popup={popup_settings}
@ -95,6 +115,7 @@
style="height: 42px; text-align: start; text-indent: 12px; border-top-left-radius: 0; border-bottom-left-radius: 0;" style="height: 42px; text-align: start; text-indent: 12px; border-top-left-radius: 0; border-bottom-left-radius: 0;"
use:obtain_input use:obtain_input
use:action use:action
onmousedown={lazy_click_handler}
onkeypress={(event: Event) => event.preventDefault()} onkeypress={(event: Event) => event.preventDefault()}
value={get_label(input_variable) ?? placeholder} value={get_label(input_variable) ?? placeholder}
{...restProps} {...restProps}
@ -106,6 +127,7 @@
autocomplete="off" autocomplete="off"
style="height: 42px; text-align: start; text-indent: 12px; border-top-left-radius: 0; border-bottom-left-radius: 0;" style="height: 42px; text-align: start; text-indent: 12px; border-top-left-radius: 0; border-bottom-left-radius: 0;"
use:obtain_input use:obtain_input
onmousedown={lazy_click_handler}
onkeypress={(event: Event) => event.preventDefault()} onkeypress={(event: Event) => event.preventDefault()}
value={get_label(input_variable) ?? placeholder} value={get_label(input_variable) ?? placeholder}
{...restProps} {...restProps}
@ -118,14 +140,17 @@
class="card z-10 w-auto overflow-y-scroll p-2 shadow" class="card z-10 w-auto overflow-y-scroll p-2 shadow"
style="max-height: 350px;" style="max-height: 350px;"
> >
{#if load}
<ListBox> <ListBox>
{#each options as option} {#each options as option}
<ListBoxItem bind:group={input_variable} {name} value={option.value}> <ListBoxItem bind:group={input_variable} {name} value={option.value}>
<div class="flex flex-nowrap"> <div class="flex flex-nowrap">
{#if option.icon_url} {#if option.icon_url}
<img <LazyImage
src={option.icon_url} src={option.icon_url}
alt="" alt=""
imgwidth={option.icon_width ?? 1}
imgheight={option.icon_height ?? 1}
class="mr-2 rounded" class="mr-2 rounded"
style="height: 24px; max-width: 64px;" style="height: 24px; max-width: 64px;"
/> />
@ -135,4 +160,5 @@
</ListBoxItem> </ListBoxItem>
{/each} {/each}
</ListBox> </ListBox>
{/if}
</div> </div>

View File

@ -6,19 +6,30 @@
interface LazyImageProps extends HTMLImgAttributes { interface LazyImageProps extends HTMLImgAttributes {
/** The URL to the image resource to lazyload */ /** The URL to the image resource to lazyload */
src: string; src: string;
/** The aspect ratio width used to reserve image space (while its loading) */
imgwidth: number;
/** The aspect ratio height used to reserve image space (while its loading) */
imgheight: number;
} }
let { src, ...restProps }: LazyImageProps = $props(); let { src, imgwidth, imgheight, ...restProps }: LazyImageProps = $props();
// Once the image is visible, this will be set to true, triggering the loading
let load: boolean = $state(false);
const lazy_visible_handler = () => { const lazy_visible_handler = () => {
load = true; load = true;
}; };
// Once the image is visible, this will be set to true, triggering the loading
let load: boolean = $state(false);
</script> </script>
<div use:lazyload onLazyVisible={lazy_visible_handler}> <!-- Show a correctly sized div so the layout doesn't jump. -->
<div
use:lazyload
onLazyVisible={lazy_visible_handler}
style="width: 100%; aspect-ratio: {imgwidth} / {imgheight};"
>
{#if load} {#if load}
{#await fetch_image_base64(src) then data} {#await fetch_image_base64(src) then data}
<img src={data} style="width: 100%" {...restProps} /> <img src={data} style="width: 100%" {...restProps} />

View File

@ -1,7 +1,7 @@
<script lang="ts"> <script lang="ts">
import { get_image_preview_event_handler } from "$lib/image"; import { get_image_preview_event_handler } from "$lib/image";
import { FileDropzone } from "@skeletonlabs/skeleton"; import { FileDropzone } from "@skeletonlabs/skeleton";
import Card from "./Card.svelte"; import LazyCard from "./LazyCard.svelte";
import Button from "./Button.svelte"; import Button from "./Button.svelte";
import type { Race } from "$lib/schema"; import type { Race } from "$lib/schema";
import Input from "./Input.svelte"; import Input from "./Input.svelte";
@ -55,7 +55,7 @@
}; };
</script> </script>
<Card <LazyCard
imgsrc={race?.pictogram_url ?? pictogram_template} imgsrc={race?.pictogram_url ?? pictogram_template}
imgwidth={RACE_PICTOGRAM_WIDTH} imgwidth={RACE_PICTOGRAM_WIDTH}
imgheight={RACE_PICTOGRAM_HEIGHT} imgheight={RACE_PICTOGRAM_HEIGHT}
@ -175,4 +175,4 @@
</div> </div>
</div> </div>
</form> </form>
</Card> </LazyCard>

View File

@ -1,9 +1,9 @@
<script lang="ts"> <script lang="ts">
import Card from "./Card.svelte"; import LazyCard from "./LazyCard.svelte";
import Button from "./Button.svelte"; import Button from "./Button.svelte";
import type { Driver, Substitution } from "$lib/schema"; import type { Driver, Substitution } from "$lib/schema";
import { get_by_value } from "$lib/database"; import { get_by_value } from "$lib/database";
import Dropdown, { type DropdownOption } from "./Dropdown.svelte"; import LazyDropdown, { type DropdownOption } from "./LazyDropdown.svelte";
import type { Action } from "svelte/action"; import type { Action } from "svelte/action";
import { DRIVER_HEADSHOT_HEIGHT, DRIVER_HEADSHOT_WIDTH } from "$lib/config"; import { DRIVER_HEADSHOT_HEIGHT, DRIVER_HEADSHOT_WIDTH } from "$lib/config";
@ -76,7 +76,7 @@
}; };
</script> </script>
<Card <LazyCard
imgsrc={get_by_value(drivers, "id", substitution?.substitute ?? "")?.headshot_url ?? imgsrc={get_by_value(drivers, "id", substitution?.substitute ?? "")?.headshot_url ??
headshot_template} headshot_template}
imgwidth={DRIVER_HEADSHOT_WIDTH} imgwidth={DRIVER_HEADSHOT_WIDTH}
@ -92,35 +92,39 @@
<div class="flex flex-col gap-2"> <div class="flex flex-col gap-2">
<!-- Substitute select --> <!-- Substitute select -->
<Dropdown <LazyDropdown
name="substitute" name="substitute"
input_variable={substitute_select_value} input_variable={substitute_select_value}
action={register_substitute_preview_handler} action={register_substitute_preview_handler}
options={driver_select_options} options={driver_select_options}
labelwidth="120px" labelwidth="120px"
disabled={disable_inputs} disabled={disable_inputs}
required={require_inputs}>Substitute</Dropdown required={require_inputs}
> >
Substitute
</LazyDropdown>
<!-- Driver select --> <!-- Driver select -->
<Dropdown <LazyDropdown
name="for" name="for"
input_variable={driver_select_value} input_variable={driver_select_value}
options={driver_select_options} options={driver_select_options}
labelwidth="120px" labelwidth="120px"
disabled={disable_inputs} disabled={disable_inputs}
required={require_inputs}>For</Dropdown required={require_inputs}
> >For
</LazyDropdown>
<!-- Race select --> <!-- Race select -->
<Dropdown <LazyDropdown
name="race" name="race"
input_variable={race_select_value} input_variable={race_select_value}
options={race_select_options} options={race_select_options}
labelwidth="120px" labelwidth="120px"
disabled={disable_inputs} disabled={disable_inputs}
required={require_inputs}>Race</Dropdown required={require_inputs}
> >Race
</LazyDropdown>
<!-- Save/Delete buttons --> <!-- Save/Delete buttons -->
<div class="flex justify-end gap-2"> <div class="flex justify-end gap-2">
@ -145,4 +149,4 @@
</div> </div>
</div> </div>
</form> </form>
</Card> </LazyCard>

View File

@ -1,11 +1,11 @@
<script lang="ts"> <script lang="ts">
import { get_image_preview_event_handler } from "$lib/image"; import { get_image_preview_event_handler } from "$lib/image";
import { FileDropzone } from "@skeletonlabs/skeleton"; import { FileDropzone } from "@skeletonlabs/skeleton";
import Card from "./Card.svelte";
import Button from "./Button.svelte"; import Button from "./Button.svelte";
import type { Team } from "$lib/schema"; import type { Team } from "$lib/schema";
import Input from "./Input.svelte"; import Input from "./Input.svelte";
import { TEAM_LOGO_HEIGHT, TEAM_LOGO_WIDTH } from "$lib/config"; import { TEAM_LOGO_HEIGHT, TEAM_LOGO_WIDTH } from "$lib/config";
import LazyCard from "./LazyCard.svelte";
interface TeamCardProps { interface TeamCardProps {
/** The [Team] object used to prefill values. */ /** The [Team] object used to prefill values. */
@ -29,7 +29,7 @@
}: TeamCardProps = $props(); }: TeamCardProps = $props();
</script> </script>
<Card <LazyCard
imgsrc={team?.logo_url ?? logo_template} imgsrc={team?.logo_url ?? logo_template}
imgwidth={TEAM_LOGO_WIDTH} imgwidth={TEAM_LOGO_WIDTH}
imgheight={TEAM_LOGO_HEIGHT} imgheight={TEAM_LOGO_HEIGHT}
@ -83,4 +83,4 @@
</div> </div>
</div> </div>
</form> </form>
</Card> </LazyCard>

View File

@ -1,8 +1,8 @@
import Button from "./Button.svelte"; import Button from "./Button.svelte";
import Card from "./Card.svelte";
import DriverCard from "./DriverCard.svelte"; import DriverCard from "./DriverCard.svelte";
import Dropdown from "./Dropdown.svelte";
import Input from "./Input.svelte"; import Input from "./Input.svelte";
import LazyCard from "./LazyCard.svelte";
import LazyDropdown from "./LazyDropdown.svelte";
import LazyImage from "./LazyImage.svelte"; import LazyImage from "./LazyImage.svelte";
import LoadingIndicator from "./LoadingIndicator.svelte"; import LoadingIndicator from "./LoadingIndicator.svelte";
import RaceCard from "./RaceCard.svelte"; import RaceCard from "./RaceCard.svelte";
@ -17,10 +17,10 @@ import UserIcon from "./svg/UserIcon.svelte";
export { export {
// Components // Components
Button, Button,
Card,
DriverCard, DriverCard,
Dropdown,
Input, Input,
LazyCard,
LazyDropdown,
LazyImage, LazyImage,
LoadingIndicator, LoadingIndicator,
RaceCard, RaceCard,

View File

@ -1,3 +1,5 @@
import { browser } from "$app/environment";
/** /**
* Obtain an onchange event handler that updates an <Avatar> component * Obtain an onchange event handler that updates an <Avatar> component
* with a new image uploaded via a file input element. * with a new image uploaded via a file input element.
@ -46,8 +48,15 @@ export const get_image_preview_event_handler = (id: string): ((event: Event) =>
return handler; return handler;
}; };
/** Convert a binary [Blob] to base64 string */ /**
* Convert a binary [Blob] to base64 string.
* Can only be called clientside from a browser as it depends on FileReader!
*/
export const blob_to_base64 = (blob: Blob): Promise<string> => { export const blob_to_base64 = (blob: Blob): Promise<string> => {
if (!browser) {
console.error("Can't call blob_to_base64 on server (FileReader is not available)!");
}
return new Promise((resolve, _) => { return new Promise((resolve, _) => {
const reader = new FileReader(); const reader = new FileReader();
@ -58,9 +67,19 @@ export const blob_to_base64 = (blob: Blob): Promise<string> => {
}); });
}; };
/** Fetch an image from an URL using a fetch function [f] and return as base64 string */ /**
* Fetch an image from an URL using a fetch function [f] and return as base64 string .
* Can be called client- and server-side.
*/
export const fetch_image_base64 = async (url: string, f: Function = fetch): Promise<string> => { export const fetch_image_base64 = async (url: string, f: Function = fetch): Promise<string> => {
return f(url) if (browser) {
return await f(url)
.then((response: Response) => response.blob()) .then((response: Response) => response.blob())
.then((blob: Blob) => blob_to_base64(blob)); .then((blob: Blob) => blob_to_base64(blob));
}
// On the server
const response: Response = await f(url);
const buffer: Buffer = Buffer.from(await response.arrayBuffer());
return buffer.toString("base64");
}; };

View File

@ -33,12 +33,36 @@
// Drawer config // Drawer config
initializeStores(); initializeStores();
const drawerStore: DrawerStore = getDrawerStore(); const drawerStore: DrawerStore = getDrawerStore();
let drawerOpen: boolean = false;
let drawerId: string = "";
drawerStore.subscribe((settings: DrawerSettings) => {
drawerOpen = settings.open ?? false;
drawerId = settings.id ?? "";
});
const toggle_drawer = (settings: DrawerSettings) => {
if (drawerOpen) {
if (drawerId === settings.id) {
// We clicked the same button to close the drawer
drawerStore.close();
} else {
// We clicked another button to open another drawer
drawerStore.close();
setTimeout(() => drawerStore.open(settings), 200);
}
} else {
drawerStore.open(settings);
}
};
const close_drawer = () => drawerStore.close();
const drawer_settings_base: DrawerSettings = { const drawer_settings_base: DrawerSettings = {
position: "top", position: "top",
height: "auto", height: "auto",
padding: "lg:px-96", padding: "lg:px-96 pt-14", // pt-14 is 56px, so its missing 4px for the 60px navbar...
bgDrawer: "bg-surface-100", bgDrawer: "bg-surface-100",
duration: 150,
}; };
const menu_drawer = () => { const menu_drawer = () => {
@ -46,7 +70,7 @@
id: "menu_drawer", id: "menu_drawer",
...drawer_settings_base, ...drawer_settings_base,
}; };
drawerStore.open(drawerSettings); toggle_drawer(drawerSettings);
}; };
const data_drawer = () => { const data_drawer = () => {
@ -54,7 +78,7 @@
id: "data_drawer", id: "data_drawer",
...drawer_settings_base, ...drawer_settings_base,
}; };
drawerStore.open(drawerSettings); toggle_drawer(drawerSettings);
}; };
const login_drawer = () => { const login_drawer = () => {
@ -62,7 +86,7 @@
id: "login_drawer", id: "login_drawer",
...drawer_settings_base, ...drawer_settings_base,
}; };
drawerStore.open(drawerSettings); toggle_drawer(drawerSettings);
}; };
const profile_drawer = () => { const profile_drawer = () => {
@ -70,11 +94,9 @@
id: "profile_drawer", id: "profile_drawer",
...drawer_settings_base, ...drawer_settings_base,
}; };
drawerStore.open(drawerSettings); toggle_drawer(drawerSettings);
}; };
const close_drawer = () => drawerStore.close();
// Popups config // Popups config
storePopup.set({ computePosition, autoUpdate, offset, shift, flip, arrow }); storePopup.set({ computePosition, autoUpdate, offset, shift, flip, arrow });
@ -93,11 +115,12 @@
<LoadingIndicator /> <LoadingIndicator />
<Drawer> <Drawer>
<!-- Use p-3 because the drawer has a 5px overlap with the navbar -->
<div class="flex flex-col gap-2 p-3">
{#if $drawerStore.id === "menu_drawer"} {#if $drawerStore.id === "menu_drawer"}
<!-- Menu Drawer --> <!-- Menu Drawer -->
<!-- Menu Drawer --> <!-- Menu Drawer -->
<!-- Menu Drawer --> <!-- Menu Drawer -->
<div class="flex flex-col gap-2 p-2">
<Button href="/racepicks" onclick={close_drawer} color="surface" fullwidth>Race Picks</Button> <Button href="/racepicks" onclick={close_drawer} color="surface" fullwidth>Race Picks</Button>
<Button href="/seasonpicks" onclick={close_drawer} color="surface" fullwidth <Button href="/seasonpicks" onclick={close_drawer} color="surface" fullwidth
>Season Picks >Season Picks
@ -109,51 +132,46 @@
>Statistics >Statistics
</Button> </Button>
<Button href="/rules" onclick={close_drawer} color="surface" fullwidth>Rules</Button> <Button href="/rules" onclick={close_drawer} color="surface" fullwidth>Rules</Button>
</div>
{:else if $drawerStore.id === "data_drawer"} {:else if $drawerStore.id === "data_drawer"}
<!-- Data Drawer --> <!-- Data Drawer -->
<!-- Data Drawer --> <!-- Data Drawer -->
<!-- Data Drawer --> <!-- Data Drawer -->
<div class="flex flex-col gap-2 p-2"> <Button href="/data/raceresult" onclick={close_drawer} color="surface" fullwidth
<Button href="/data/raceresult" onclick={close_drawer} color="surface" fullwidth> >Race Results
Race Results
</Button> </Button>
<Button href="/data/season" onclick={close_drawer} color="surface" fullwidth>Season</Button> <Button href="/data/season" onclick={close_drawer} color="surface" fullwidth>Season</Button>
<Button href="/data/user" onclick={close_drawer} color="surface" fullwidth>Users</Button> <Button href="/data/user" onclick={close_drawer} color="surface" fullwidth>Users</Button>
</div>
{:else if $drawerStore.id === "login_drawer"} {:else if $drawerStore.id === "login_drawer"}
<!-- Login Drawer --> <!-- Login Drawer -->
<!-- Login Drawer --> <!-- Login Drawer -->
<!-- Login Drawer --> <!-- Login Drawer -->
<div class="flex flex-col gap-2 p-2">
<h4 class="h4 select-none">Enter Username and Password</h4> <h4 class="h4 select-none">Enter Username and Password</h4>
<form method="POST" class="contents"> <form method="POST" class="contents">
<!-- Supply the pathname so the form can redirect to the current page. --> <!-- Supply the pathname so the form can redirect to the current page. -->
<input type="hidden" name="redirect_url" value={$page.url.pathname} /> <input type="hidden" name="redirect_url" value={$page.url.pathname} />
<Input name="username" placeholder="Username" autocomplete="username" required> <Input name="username" placeholder="Username" autocomplete="username" required
<UserIcon /> ><UserIcon />
</Input> </Input>
<Input name="password" type="password" placeholder="Password" autocomplete="off" required> <Input name="password" type="password" placeholder="Password" autocomplete="off" required
<PasswordIcon /> ><PasswordIcon />
</Input> </Input>
<div class="flex justify-end gap-2"> <div class="flex justify-end gap-2">
<Button formaction="/profile?/login" onclick={close_drawer} color="tertiary" submit> <Button formaction="/profile?/login" onclick={close_drawer} color="tertiary" submit
Login >Login
</Button> </Button>
<Button <Button
formaction="/profile?/create_profile" formaction="/profile?/create_profile"
onclick={close_drawer} onclick={close_drawer}
color="tertiary" color="tertiary"
submit>Register</Button submit
> >Register
</Button>
</div> </div>
</form> </form>
</div>
{:else if $drawerStore.id === "profile_drawer" && data.user} {:else if $drawerStore.id === "profile_drawer" && data.user}
<!-- Profile Drawer --> <!-- Profile Drawer -->
<!-- Profile Drawer --> <!-- Profile Drawer -->
<!-- Profile Drawer --> <!-- Profile Drawer -->
<div class="flex flex-col gap-2 p-2">
<h4 class="h4 select-none">Edit Profile</h4> <h4 class="h4 select-none">Edit Profile</h4>
<form method="POST" enctype="multipart/form-data" class="contents"> <form method="POST" enctype="multipart/form-data" class="contents">
<!-- Supply the pathname so the form can redirect to the current page. --> <!-- Supply the pathname so the form can redirect to the current page. -->
@ -187,12 +205,12 @@
</Button> </Button>
</div> </div>
</form> </form>
</div>
{/if} {/if}
</div>
</Drawer> </Drawer>
<nav> <nav>
<!-- TODO: Make this stick to the top somehow (fixed/sticky). --> <div class="fixed left-0 right-0 top-0 z-50">
<AppBar <AppBar
slotDefault="place-self-center" slotDefault="place-self-center"
slotTrail="place-content-end" slotTrail="place-content-end"
@ -210,7 +228,8 @@
</div> </div>
<!-- Site logo --> <!-- Site logo -->
<Button href="/" color="primary"><span class="text-xl font-bold">Formula 11</span></Button> <Button href="/" color="primary"><span class="text-xl font-bold">Formula 11</span></Button
>
</div> </div>
</svelte:fragment> </svelte:fragment>
@ -250,9 +269,10 @@
</div> </div>
</svelte:fragment> </svelte:fragment>
</AppBar> </AppBar>
</div>
</nav> </nav>
<!-- Each child's contents will be inserted here --> <!-- Each child's contents will be inserted here -->
<div class="p-2"> <div class="p-2" style="margin-top: 60px;">
{@render children()} {@render children()}
</div> </div>

View File

@ -4,9 +4,17 @@
import { Tab, TabGroup } from "@skeletonlabs/skeleton"; import { Tab, TabGroup } from "@skeletonlabs/skeleton";
// TODO: Why does this work but import { type DropdownOption } from "$lib/components" does not? // TODO: Why does this work but import { type DropdownOption } from "$lib/components" does not?
import type { DropdownOption } from "$lib/components/Dropdown.svelte"; import type { LazyDropdownOption } from "$lib/components/LazyDropdown.svelte";
import { TeamCard, DriverCard, RaceCard, SubstitutionCard } from "$lib/components"; import { TeamCard, DriverCard, RaceCard, SubstitutionCard } from "$lib/components";
import { get_by_value } from "$lib/database"; import { get_by_value } from "$lib/database";
import {
DRIVER_HEADSHOT_HEIGHT,
DRIVER_HEADSHOT_WIDTH,
RACE_PICTOGRAM_HEIGHT,
RACE_PICTOGRAM_WIDTH,
TEAM_LOGO_HEIGHT,
TEAM_LOGO_WIDTH,
} from "$lib/config";
let { data, form }: { data: PageData; form: ActionData } = $props(); let { data, form }: { data: PageData; form: ActionData } = $props();
@ -44,28 +52,42 @@
update_substitution_race_select_values["create"] = ""; update_substitution_race_select_values["create"] = "";
// All options to create a <Dropdown> component for the teams // All options to create a <Dropdown> component for the teams
const team_dropdown_options: DropdownOption[] = []; const team_dropdown_options: LazyDropdownOption[] = [];
data.teams.forEach((team: Team) => { data.teams.forEach((team: Team) => {
team_dropdown_options.push({ label: team.name, value: team.id, icon_url: team.logo_url }); team_dropdown_options.push({
label: team.name,
value: team.id,
icon_url: team.logo_url,
icon_width: TEAM_LOGO_WIDTH,
icon_height: TEAM_LOGO_HEIGHT,
});
}); });
// All options to create a <Dropdown> component for the drivers // All options to create a <Dropdown> component for the drivers
const driver_dropdown_options: DropdownOption[] = []; const driver_dropdown_options: LazyDropdownOption[] = [];
data.drivers.then((drivers: Driver[]) => data.drivers.then((drivers: Driver[]) =>
drivers.forEach((driver: Driver) => { drivers.forEach((driver: Driver) => {
driver_dropdown_options.push({ driver_dropdown_options.push({
label: driver.code, label: driver.code,
value: driver.id, value: driver.id,
icon_url: driver.headshot_url, icon_url: driver.headshot_url,
icon_width: DRIVER_HEADSHOT_WIDTH,
icon_height: DRIVER_HEADSHOT_HEIGHT,
}); });
}), }),
); );
// All options to create a <Dropdown> component for the races // All options to create a <Dropdown> component for the races
const race_dropdown_options: DropdownOption[] = []; const race_dropdown_options: LazyDropdownOption[] = [];
data.races.then((races: Race[]) => data.races.then((races: Race[]) =>
races.forEach((race: Race) => { races.forEach((race: Race) => {
race_dropdown_options.push({ label: race.name, value: race.id }); race_dropdown_options.push({
label: race.name,
value: race.id,
icon_url: race.pictogram_url,
icon_width: RACE_PICTOGRAM_WIDTH,
icon_height: RACE_PICTOGRAM_HEIGHT,
});
}), }),
); );
</script> </script>