From 4de9cf9b0b4bddf9ece6e057808e489f99998be3 Mon Sep 17 00:00:00 2001 From: Christoph Urlacher Date: Mon, 16 Dec 2024 20:06:56 +0100 Subject: [PATCH] Lib: Remove previous lazy loading approach and replace with static aspect ratios The element size must be valid before it is loaded, this is a problem for cards, as they adapt to their content's size. Previously I tried to load the first card non-lazily and measure its dimensions for the next cards, but that was not stable on viewport changes (could have measured the aspect ratio instead...). Now, all the aspect ratios are just measured and defined manually, stupid but simple. --- src/lib/components/DriverCard.svelte | 10 +- src/lib/components/LazyCard.svelte | 101 +++++++-------------- src/lib/components/RaceCard.svelte | 10 +- src/lib/components/SubstitutionCard.svelte | 10 +- src/lib/components/TeamCard.svelte | 10 +- src/lib/config.ts | 20 ++++ 6 files changed, 83 insertions(+), 78 deletions(-) diff --git a/src/lib/components/DriverCard.svelte b/src/lib/components/DriverCard.svelte index cc5124c..652c9db 100644 --- a/src/lib/components/DriverCard.svelte +++ b/src/lib/components/DriverCard.svelte @@ -6,7 +6,12 @@ import type { Driver } from "$lib/schema"; import Input from "./Input.svelte"; import LazyDropdown, { type LazyDropdownOption } from "./LazyDropdown.svelte"; - import { DRIVER_HEADSHOT_HEIGHT, DRIVER_HEADSHOT_WIDTH } from "$lib/config"; + import { + DRIVER_CARD_ASPECT_HEIGHT, + DRIVER_CARD_ASPECT_WIDTH, + DRIVER_HEADSHOT_HEIGHT, + DRIVER_HEADSHOT_WIDTH, + } from "$lib/config"; interface DriverCardProps { /** The [Driver] object used to prefill values. */ @@ -43,7 +48,8 @@ - // The first element of a group of cards (e.g. driver cards or team cards) - // will register its height here, once its fully loaded. - // This height is then used as the height of following components. - // This is necessary, because for lazy loading depending on viewport intersection, - // the elements must have their actual height from the beginning. - let group_heights: { [key: string]: number } = {}; - - -
- {#if group_heights[group]} - -
- - {#if imgsrc !== undefined} -
- {:else} - -
- - {#if imgsrc !== undefined} -
diff --git a/src/lib/components/RaceCard.svelte b/src/lib/components/RaceCard.svelte index 3015cc4..f59247c 100644 --- a/src/lib/components/RaceCard.svelte +++ b/src/lib/components/RaceCard.svelte @@ -6,7 +6,12 @@ import type { Race } from "$lib/schema"; import Input from "./Input.svelte"; import { format } from "date-fns"; - import { RACE_PICTOGRAM_HEIGHT, RACE_PICTOGRAM_WIDTH } from "$lib/config"; + import { + RACE_CARD_ASPECT_HEIGHT, + RACE_CARD_ASPECT_WIDTH, + RACE_PICTOGRAM_HEIGHT, + RACE_PICTOGRAM_WIDTH, + } from "$lib/config"; interface RaceCardProps { /** The [Race] object used to prefill values. */ @@ -56,7 +61,8 @@