From 7a306e433e343818e259eaf757e5c63af3d1c93b Mon Sep 17 00:00:00 2001 From: Fuwn Date: Sat, 17 Feb 2024 16:32:59 -0800 Subject: refactor(hololive): move lives to component --- src/routes/hololive/+page.svelte | 174 +-------------------------------------- 1 file changed, 4 insertions(+), 170 deletions(-) (limited to 'src/routes') diff --git a/src/routes/hololive/+page.svelte b/src/routes/hololive/+page.svelte index 96fbea67..099a09fc 100644 --- a/src/routes/hololive/+page.svelte +++ b/src/routes/hololive/+page.svelte @@ -8,20 +8,8 @@ import locale from '$stores/locale'; import root from '$lib/Utility/root'; import identity from '$stores/identity'; - import Icon from '@iconify/svelte'; - - interface ParseResult { - lives: { - time: Date; - link: string; - videoId: string; - streamer: string; - livePreviewImage: string; - guests: string[]; - streaming: boolean; - }[]; - dict: Record; - } + import Lives from '$lib/Hololive/Lives.svelte'; + import type { ParseResult } from '$lib/Hololive/hololive'; let schedulePromise: Promise; let pinnedStreams: string[] = []; @@ -58,14 +46,6 @@ const typeSchedule = (schedule: any) => schedule as ParseResult; - const pinStream = (streamer: string) => - fetch(root(`/api/configuration/pin?stream=${encodeURIComponent(streamer)}`), { - method: 'PUT', - headers: { - 'Content-Type': 'application/json' - } - }).then(getPinnedStreams); - const getClosestUpcomingPinnedStreams = (schedule: ParseResult) => { const now = Date.now(); let closestUpcomingPinnedStreams = new Map(); @@ -101,94 +81,7 @@ {@const schedule = typeSchedule(parseScheduleHtml(untypedSchedule))} {@const closestUpcomingPinnedStreams = getClosestUpcomingPinnedStreams(schedule)} - {#if schedule.lives.length === 0} - - {/if} - -
- {#each schedule.lives - .filter((live) => { - try { - $locale().hololive.dateFormatter(new Date(live.time)); - - return true; - } catch { - return false; - } - }) - .sort((a, b) => { - const now = Date.now(); - const aTime = new Date(a.time).getTime(); - const bTime = new Date(b.time).getTime(); - const aIsLive = a.streaming; - const bIsLive = b.streaming; - const aIsClosestPinned = closestUpcomingPinnedStreams.get(a.streamer) === a; - const bIsClosestPinned = closestUpcomingPinnedStreams.get(b.streamer) === b; - - if (aIsLive && pinnedStreams.includes(a.streamer)) return -1; - if (bIsLive && pinnedStreams.includes(b.streamer)) return 1; - - if (aIsLive && !bIsLive) return -1; - if (bIsLive && !aIsLive) return 1; - - if (aIsClosestPinned && !bIsClosestPinned) return -1; - if (bIsClosestPinned && !aIsClosestPinned) return 1; - - if (aTime > now && !(aTime < now && !aIsLive)) return -1; - if (bTime > now && !(bTime < now && !bIsLive)) return 1; - - return bTime - aTime; - }) as live} -
- {#if $identity.id !== -2} - - {/if} - -

- [{#if live.streaming} - {$locale().hololive.live}{:else if new Date(live.time).getTime() < Date.now()} - {$locale().hololive.ended}{:else} - {$locale().hololive.upcoming}{/if}] - {live.streamer} | - {$locale().hololive.dateFormatter(new Date(live.time))} - {#if live.guests.length > 0} -
- - {$locale().hololive.with}{live.guests - .join($locale().hololive.comma) - .replace( - new RegExp( - `${$locale().hololive.comma}([^${$locale().hololive.commaNoSpace}]+)$`, - 'g' - ), - `${$locale().hololive.comma}${$locale().hololive.ampersand}$1` - )} - - {/if} -

- - - Stream Thumbnail - -
- {/each} -
+ {:catch} {$locale().hololive.parseError} @@ -201,67 +94,8 @@ {/if} {:catch} - + {$locale().hololive.loadError} Please location.reload()}>try again later. {/await} - - -- cgit v1.2.3