From 257d5e639418520a0820ee6a3cfacd8276647b9c Mon Sep 17 00:00:00 2001 From: Fuwn Date: Sat, 17 Feb 2024 17:19:06 -0800 Subject: feat(hololive): seperate categories --- src/lib/Hololive/Lives.svelte | 168 +++++++++++++---------------------------- src/lib/Hololive/Stream.svelte | 106 ++++++++++++++++++++++++++ src/lib/Hololive/hololive.ts | 20 ++--- 3 files changed, 170 insertions(+), 124 deletions(-) create mode 100644 src/lib/Hololive/Stream.svelte diff --git a/src/lib/Hololive/Lives.svelte b/src/lib/Hololive/Lives.svelte index c7ecfdf8..38def6fa 100644 --- a/src/lib/Hololive/Lives.svelte +++ b/src/lib/Hololive/Lives.svelte @@ -1,10 +1,8 @@ - -{#if schedule.lives.length === 0} - -{/if} -
- {#each schedule.lives - .filter((live) => { - try { - $locale().hololive.dateFormatter(new Date(live.time)); - - return true; - } catch { - return false; - } - }) + $: categorisedStreams = schedule.lives .sort((a, b) => new Date(a.time).getTime() - new Date(b.time).getTime()) .sort((a, b) => { const now = Date.now(); @@ -58,111 +41,66 @@ 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 - -
+ }) + .reduce( + ( + acc: { + live: Live[]; + upcoming: Live[]; + ended: Live[]; + }, + live + ) => { + const now = Date.now(); + const time = new Date(live.time).getTime(); + const isLive = live.streaming; + const isUpcoming = time > now && !isLive; + const isEnded = time < now && !isLive; + + if (isLive) { + acc.live.push(live); + } else if (isUpcoming) { + acc.upcoming.push(live); + } else if (isEnded) { + acc.ended.push(live); + } + + return acc; + }, + { live: [], upcoming: [], ended: [] } + ); + + +{#if schedule.lives.length === 0} + +{/if} + +
+ {#each categorisedStreams.live as live} + {/each}
- diff --git a/src/lib/Hololive/Stream.svelte b/src/lib/Hololive/Stream.svelte new file mode 100644 index 00000000..3d59fd72 --- /dev/null +++ b/src/lib/Hololive/Stream.svelte @@ -0,0 +1,106 @@ + + +
+ {#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 + +
+ + diff --git a/src/lib/Hololive/hololive.ts b/src/lib/Hololive/hololive.ts index 4ba7e46e..6ad97430 100644 --- a/src/lib/Hololive/hololive.ts +++ b/src/lib/Hololive/hololive.ts @@ -1,12 +1,14 @@ +export interface Live { + time: Date; + link: string; + videoId: string; + streamer: string; + livePreviewImage: string; + guests: string[]; + streaming: boolean; +} + export interface ParseResult { - lives: { - time: Date; - link: string; - videoId: string; - streamer: string; - livePreviewImage: string; - guests: string[]; - streaming: boolean; - }[]; + lives: Live[]; dict: Record; } -- cgit v1.2.3