From 5ce33ff495db32b9dbdba6b4000a14c97cc94662 Mon Sep 17 00:00:00 2001 From: Santiago Cepeda Date: Mon, 2 Oct 2023 10:41:26 +0200 Subject: [PATCH] Implement dynamic index --- client/src/lib/WeatherOverview.svelte | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/client/src/lib/WeatherOverview.svelte b/client/src/lib/WeatherOverview.svelte index e8101a9..73f95f0 100644 --- a/client/src/lib/WeatherOverview.svelte +++ b/client/src/lib/WeatherOverview.svelte @@ -4,6 +4,17 @@ export let weatherData; export let size; + let currentIndex = -1; + + const currentDate = new Date(); + + for (let i = 0; i < weatherData.hours.length; i++) { + const date_time = new Date(weatherData.hours[i].date_time); + if (date_time >= currentDate) { + currentIndex = i; + break; + } + }
- {#if ["L", "M"].includes(size)} + {#if ["L", "M"].includes(size.toUpperCase())}
- {#each weatherData.hours as hours} - {#if new Date(hours.date_time) >= new Date()} + {#each weatherData.hours as hours, index} + {#if index >= currentIndex} - {/if} + {:else if size.toUpperCase() === "L"}{/if}