From 23ca178e25e24a24badbd2e083b5f6f5df31c308 Mon Sep 17 00:00:00 2001
From: Fuwn <contact@fuwn.me>
Date: Sat, 17 Feb 2024 01:10:33 -0800
Subject: fix(hololive): wait for pinned streams

---
 src/routes/hololive/+page.svelte | 38 +++++++++++++++++---------------------
 1 file changed, 17 insertions(+), 21 deletions(-)

(limited to 'src/routes/hololive/+page.svelte')

diff --git a/src/routes/hololive/+page.svelte b/src/routes/hololive/+page.svelte
index 771bc808..50e4ee2c 100644
--- a/src/routes/hololive/+page.svelte
+++ b/src/routes/hololive/+page.svelte
@@ -26,38 +26,34 @@
 	let schedulePromise: Promise<Response>;
 	let pinnedStreams: string[] = [];
 
-	$: {
-		pinnedStreams = pinnedStreams;
-
-		schedulePromise = fetch(proxy('https://schedule.hololive.tv'), {
-			headers: {
-				Cookie: 'timezone=Asia/Tokyo'
-			}
-		});
-	}
-
-	onMount(async () => {
-		// schedulePromise = fetch(proxy('https://schedule.hololive.tv'), {
-		// 	headers: {
-		// 		Cookie: 'timezone=Asia/Tokyo'
-		// 	}
-		// });
-
-		getPinnedStreams();
-	});
+	onMount(() => getPinnedStreams());
 
 	const getPinnedStreams = () => {
 		let streams: string[] = [];
 
-		if ($identity.id !== -2)
+		const setSchedule = () => {
+			pinnedStreams = streams;
+			schedulePromise = fetch(proxy('https://schedule.hololive.tv'), {
+				headers: {
+					Cookie: 'timezone=Asia/Tokyo'
+				}
+			});
+		};
+
+		if ($identity.id !== -2) {
 			fetch(root(`/api/configuration?id=${$identity.id}`)).then((response) => {
 				if (response.ok)
 					response.json().then((data) => {
 						if (data && data.configuration) streams = data.pinned_hololive_streams;
+
+						setSchedule();
 					});
 			});
 
-		pinnedStreams = streams;
+			return;
+		}
+
+		setSchedule();
 	};
 
 	const typeSchedule = (schedule: any) => schedule as ParseResult;
-- 
cgit v1.2.3

