From 3e0c9e79937a3d8da23d7e43743a7810485e3c6f Mon Sep 17 00:00:00 2001
From: Fuwn <contact@fuwn.me>
Date: Sun, 17 Mar 2024 05:25:40 -0700
Subject: fix(umamusume): null-check birthdays

---
 src/lib/Tools/UmaMusumeBirthdays.svelte | 91 +++++++++++++++++++--------------
 1 file changed, 52 insertions(+), 39 deletions(-)

(limited to 'src/lib/Tools/UmaMusumeBirthdays.svelte')

diff --git a/src/lib/Tools/UmaMusumeBirthdays.svelte b/src/lib/Tools/UmaMusumeBirthdays.svelte
index d941cabe..8a8e33db 100644
--- a/src/lib/Tools/UmaMusumeBirthdays.svelte
+++ b/src/lib/Tools/UmaMusumeBirthdays.svelte
@@ -8,6 +8,7 @@
 	import Message from '$lib/Loading/Message.svelte';
 	import tooltip from '$lib/Tooltip/tooltip';
 	import settings from '$stores/settings';
+	import locale from '$stores/locale';
 
 	interface Birthday {
 		birth_day: number;
@@ -51,50 +52,62 @@
 
 	<Skeleton grid={true} count={100} width="150px" height="170px" />
 {:then birthdays}
-	{@const todaysBirthdays = birthdays.filter(
-		(birthday) => birthday.birth_month === month && birthday.birth_day === day
-	)}
+	{#if birthdays}
+		{@const todaysBirthdays = birthdays.filter(
+			(birthday) => birthday.birth_month === month && birthday.birth_day === day
+		)}
 
-	<p>
-		<select bind:value={month}>
-			{#each Array.from({ length: 12 }, (_, i) => i + 1) as month}
-				<option value={month}>
-					{new Date(0, month - 1).toLocaleString('default', { month: 'long' })}
-				</option>
-			{/each}
-		</select>
+		<p>
+			<select bind:value={month}>
+				{#each Array.from({ length: 12 }, (_, i) => i + 1) as month}
+					<option value={month}>
+						{new Date(0, month - 1).toLocaleString('default', { month: 'long' })}
+					</option>
+				{/each}
+			</select>
 
-		<select bind:value={day}>
-			{#each Array.from({ length: new Date(new Date().getFullYear(), month, 0).getDate() }, (_, i) => i + 1) as day}
-				<option value={day}>{day}</option>
-			{/each}
-		</select>
-	</p>
+			<select bind:value={day}>
+				{#each Array.from({ length: new Date(new Date().getFullYear(), month, 0).getDate() }, (_, i) => i + 1) as day}
+					<option value={day}>{day}</option>
+				{/each}
+			</select>
+		</p>
 
-	{#if todaysBirthdays.length === 0}
-		<Message message="No birthdays today." fullscreen={false} loader="ripple" />
+		{#if todaysBirthdays.length === 0}
+			<Message
+				message={`No birthdays for ${$locale().dayFormatter(
+					new Date(new Date().getFullYear(), month - 1, day)
+				)}.`}
+				fullscreen={false}
+				loader="ripple"
+			/>
+		{:else}
+			<div class="characters">
+				{#each todaysBirthdays as birthday}
+					{@const name = $settings.displayLanguage === 'en' ? birthday.name_en : birthday.name_jp}
+					{@const nameOther =
+						$settings.displayLanguage === 'ja' ? birthday.name_en : birthday.name_jp}
+
+					<div class="card card-small">
+						<a
+							href={`https://anilist.co/search/characters?search=${encodeURIComponent(
+								birthday.name_en
+							).replace(/%20/g, '+')}`}
+							target="_blank"
+							title={nameOther}
+							use:tooltip
+						>
+							{name}
+							<img src={birthday.sns_icon} alt="Character" class="character-image" />
+						</a>
+					</div>
+				{/each}
+			</div>
+		{/if}
 	{:else}
-		<div class="characters">
-			{#each todaysBirthdays as birthday}
-				{@const name = $settings.displayLanguage === 'en' ? birthday.name_en : birthday.name_jp}
-				{@const nameOther =
-					$settings.displayLanguage === 'ja' ? birthday.name_en : birthday.name_jp}
+		<Message message="Validating birthdays ..." />
 
-				<div class="card card-small">
-					<a
-						href={`https://anilist.co/search/characters?search=${encodeURIComponent(
-							birthday.name_en
-						).replace(/%20/g, '+')}`}
-						target="_blank"
-						title={nameOther}
-						use:tooltip
-					>
-						{name}
-						<img src={birthday.sns_icon} alt="Character" class="character-image" />
-					</a>
-				</div>
-			{/each}
-		</div>
+		<Skeleton grid={true} count={100} width="150px" height="170px" />
 	{/if}
 {:catch}
 	<Error type="Character" card />
-- 
cgit v1.2.3

