diff options
Diffstat (limited to 'src/lib/Tools/HololiveBirthdays.svelte')
| -rw-r--r-- | src/lib/Tools/HololiveBirthdays.svelte | 14 |
1 files changed, 8 insertions, 6 deletions
diff --git a/src/lib/Tools/HololiveBirthdays.svelte b/src/lib/Tools/HololiveBirthdays.svelte index 68a591de..769f5d6f 100644 --- a/src/lib/Tools/HololiveBirthdays.svelte +++ b/src/lib/Tools/HololiveBirthdays.svelte @@ -1,4 +1,6 @@ <script lang="ts"> + import { run } from 'svelte/legacy'; + import { browser } from '$app/environment'; import { page } from '$app/stores'; import { onMount } from 'svelte'; @@ -9,14 +11,14 @@ const urlParameters = browser ? new URLSearchParams(window.location.search) : null; let date = new Date(); - let month = parseOrDefault(urlParameters, 'month', date.getMonth() + 1); - let day = parseOrDefault(urlParameters, 'day', date.getDate()); + let month = $state(parseOrDefault(urlParameters, 'month', date.getMonth() + 1)); + let day = $state(parseOrDefault(urlParameters, 'day', date.getDate())); - $: todaysBirthdays = birthdays.filter( + let todaysBirthdays = $derived(birthdays.filter( (birthday) => birthday.month === month && birthday.day === day - ); + )); - $: { + run(() => { month = Math.min(month, 12); month = Math.max(month, 1); day = Math.min(day, new Date(new Date().getFullYear(), month, 0).getDate()); @@ -28,7 +30,7 @@ clearAllParameters(['month', 'day']); history.replaceState(null, '', `?${$page.url.searchParams.toString()}`); } - } + }); onMount(() => clearAllParameters(['month', 'day'])); </script> |