Skip to content

Commit

Permalink
Implement dynamic index
Browse files Browse the repository at this point in the history
  • Loading branch information
smcepeda committed Oct 2, 2023
1 parent 599b24f commit 5ce33ff
Showing 1 changed file with 16 additions and 5 deletions.
21 changes: 16 additions & 5 deletions client/src/lib/WeatherOverview.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
</script>

<div
Expand All @@ -27,16 +38,16 @@
/>
</div>
</div>
{#if ["L", "M"].includes(size)}
{#if ["L", "M"].includes(size.toUpperCase())}
<div
class="flex flex-row h-20 ml-6 space-x-6 overflow-scroll text-xs font-bold scrollbar-hide"
>
{#each weatherData.hours as hours}
{#if new Date(hours.date_time) >= new Date()}
{#each weatherData.hours as hours, index}
{#if index >= currentIndex}
<SingleDay
currentTime={new Date(hours.date_time).toLocaleTimeString([], {
hour: "2-digit",
minute: "2-digit"
minute: "2-digit",
})}
symbol={hours.symbol_code}
dimensions="w-6 h-6"
Expand All @@ -47,7 +58,7 @@
{/if}
{/each}
</div>
{/if}
{:else if size.toUpperCase() === "L"}{/if}
</div>

<style>
Expand Down

0 comments on commit 5ce33ff

Please sign in to comment.