add types
This commit is contained in:
@@ -2,10 +2,11 @@
|
||||
import { untrack } from 'svelte';
|
||||
import { goto } from '$app/navigation';
|
||||
import { currentStream, favoritedStreams } from '$lib/stores.svelte.js';
|
||||
import type { StreamSummary } from '$lib/types';
|
||||
import { hashColor, shorthandCode, formatSecondsToHms, formatDate } from '$lib/utils.js';
|
||||
import TagSelect from './TagSelect.svelte';
|
||||
|
||||
let { streams } = $props();
|
||||
let { streams }: { streams: StreamSummary[] } = $props();
|
||||
let filteredTags = $state([]);
|
||||
let favoritesOnly = $state(false);
|
||||
let listOpen = $state();
|
||||
@@ -21,13 +22,13 @@
|
||||
function streamsToDisplay() {
|
||||
return streams.filter(
|
||||
(stream) =>
|
||||
!('tags' in stream) || filteredTags.every((tag) => stream['tags'].includes(tag))
|
||||
!('tags' in stream) || filteredTags.every((tag) => stream.tags.includes(tag))
|
||||
);
|
||||
}
|
||||
|
||||
function getRemainingTags() {
|
||||
let tagCounts = displayedStreams.reduce((tags, stream) => {
|
||||
stream['tags'].forEach((tag) => (tag in tags ? (tags[tag] += 1) : (tags[tag] = 1)));
|
||||
let tagCounts = displayedStreams.reduce((tags: Record<string, number>, stream) => {
|
||||
stream.tags.forEach((tag) => (tags[tag] ? (tags[tag] += 1) : (tags[tag] = 1)));
|
||||
return tags;
|
||||
}, {});
|
||||
return Object.entries(tagCounts)
|
||||
@@ -35,14 +36,14 @@
|
||||
.map((el) => el[0]);
|
||||
}
|
||||
|
||||
function getDisplayedTagsInList(streamTags, remainingTags) {
|
||||
function getDisplayedTagsInList(streamTags: string[], remainingTags: string[]) {
|
||||
return streamTags.filter((tag) => remainingTags.includes(tag));
|
||||
}
|
||||
|
||||
function updateFavorites(stream) {
|
||||
favoritedStreams.has(stream['id'])
|
||||
? favoritedStreams.delete(stream['id'])
|
||||
: favoritedStreams.add(stream['id']);
|
||||
function updateFavorites(stream: StreamSummary) {
|
||||
favoritedStreams.has(stream.id)
|
||||
? favoritedStreams.delete(stream.id)
|
||||
: favoritedStreams.add(stream.id);
|
||||
}
|
||||
</script>
|
||||
|
||||
@@ -56,28 +57,26 @@
|
||||
|
||||
<ul class="stream-list">
|
||||
{#each streams as stream}
|
||||
{@const favorited = favoritedStreams.has(stream['id'])}
|
||||
{@const current = $currentStream['id'] === stream['id']}
|
||||
{@const favorited = favoritedStreams.has(stream.id)}
|
||||
{@const current = $currentStream?.id === stream.id}
|
||||
<li
|
||||
hidden={!displayedStreams.includes(stream) || (favoritesOnly && !favorited)}
|
||||
class="stream-item {current ? 'current-stream' : ''}"
|
||||
id="stream-{stream['id']}"
|
||||
id="stream-{stream.id}"
|
||||
>
|
||||
<button class="stream-item-button" onclick={() => goto('/streams/' + stream['id'])}>
|
||||
<button class="stream-item-button" onclick={() => goto('/streams/' + stream.id)}>
|
||||
<span class="stream-item-id">
|
||||
ID:
|
||||
{shorthandCode(stream['id'])}</span
|
||||
{shorthandCode(stream.id)}</span
|
||||
>
|
||||
|
||||
<span class="stream-item-date">{formatDate(stream['stream_date'])}</span>
|
||||
<span class="stream-item-date">{formatDate(stream.stream_date)}</span>
|
||||
|
||||
<span class="stream-item-length"
|
||||
>{formatSecondsToHms(stream['length_seconds'])}</span
|
||||
>
|
||||
<span class="stream-item-length">{formatSecondsToHms(stream.length_seconds)}</span>
|
||||
|
||||
<p class="stream-item-tags" hidden={!remainingTags.length}>
|
||||
Tags: <span hidden={!filteredTags.length}>[...] </span>{getDisplayedTagsInList(
|
||||
stream['tags'],
|
||||
stream.tags,
|
||||
remainingTags
|
||||
).join(', ')}
|
||||
</p>
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
<script>
|
||||
import { currentStream } from '$lib/stores.svelte.js';
|
||||
|
||||
currentStream.set({});
|
||||
currentStream.set(null);
|
||||
</script>
|
||||
|
||||
<div class="stream-information">
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
import Player from './Player.svelte';
|
||||
import { dev } from '$app/environment';
|
||||
import { currentStream, updateCurrentStream } from '$lib/stores.svelte.js';
|
||||
import type { Stream } from '$lib/types';
|
||||
|
||||
let { data } = $props();
|
||||
|
||||
@@ -23,7 +24,7 @@
|
||||
</div>
|
||||
<div id="player">
|
||||
{#key $currentStream}
|
||||
<Player display={true} src="/media/tracks/{$currentStream.filename}" />
|
||||
<Player display={true} src="/media/tracks/{$currentStream?.filename}" />
|
||||
{/key}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -25,6 +25,7 @@
|
||||
getSongAtTime,
|
||||
updateCurrentSong
|
||||
} from '$lib/stores.svelte.js';
|
||||
import type { Track } from '$lib/types';
|
||||
|
||||
interface Props {
|
||||
src: any;
|
||||
@@ -89,7 +90,7 @@
|
||||
// update browser metadata on track changes
|
||||
if ('mediaSession' in navigator) {
|
||||
currentSongIndex.subscribe((val) => {
|
||||
if (val != null && !paused) {
|
||||
if (val != null && !paused && $currentStream) {
|
||||
setMediaMetadata($currentStream.tracks[val]);
|
||||
}
|
||||
});
|
||||
@@ -111,7 +112,7 @@
|
||||
}
|
||||
}
|
||||
|
||||
function setMediaMetadata(track) {
|
||||
function setMediaMetadata(track: Track) {
|
||||
navigator.mediaSession.metadata = new MediaMetadata({
|
||||
artist: track[1],
|
||||
title: track[2]
|
||||
@@ -120,7 +121,7 @@
|
||||
|
||||
// browsers don't like if you update this while no media is playing
|
||||
function setMediaMetadataOnPlay() {
|
||||
if ('mediaSession' in navigator) {
|
||||
if ('mediaSession' in navigator && $currentStream && $currentSongIndex != null) {
|
||||
setMediaMetadata($currentStream.tracks[$currentSongIndex]);
|
||||
}
|
||||
}
|
||||
@@ -173,6 +174,7 @@
|
||||
}
|
||||
let bounds = songBar.getBoundingClientRect();
|
||||
let seekValue = ((event.pageX - bounds.left) * duration) / bounds.width;
|
||||
if (!$currentStream) return;
|
||||
let trackArray = $currentStream.tracks[getSongAtTime(seekValue)];
|
||||
seekTrack = trackArray[1] + ' - ' + trackArray[2];
|
||||
seekText = formatSeconds(seekValue);
|
||||
@@ -184,7 +186,9 @@
|
||||
if (volumeSeeking) seekVolume(event);
|
||||
}
|
||||
run(() => {
|
||||
updateCurrentSong(currentTime, $currentSongIndex);
|
||||
if ($currentSongIndex != null) {
|
||||
updateCurrentSong(currentTime, $currentSongIndex);
|
||||
}
|
||||
});
|
||||
run(() => {
|
||||
updateAudioAttributes(audio);
|
||||
|
||||
@@ -9,49 +9,53 @@
|
||||
sanitizer: DOMPurify.sanitize
|
||||
});
|
||||
|
||||
let formattedStreamDate = $derived(formatDate($currentStream.stream_date));
|
||||
let formattedStreamDate = $derived(
|
||||
$currentStream ? formatDate($currentStream.stream_date) : ''
|
||||
);
|
||||
</script>
|
||||
|
||||
<svelte:head>
|
||||
<title>{formattedStreamDate} | apt-get's auditorium</title>
|
||||
</svelte:head>
|
||||
|
||||
<div class="stream-information">
|
||||
<div class="stream-information-flexbox">
|
||||
<h3 class="stream-id">ID: {shorthandCode($currentStream.id)}</h3>
|
||||
<h1 class="stream-date">{formattedStreamDate}</h1>
|
||||
{#if $currentStream}
|
||||
<div class="stream-information">
|
||||
<div class="stream-information-flexbox">
|
||||
<h3 class="stream-id">ID: {shorthandCode($currentStream.id)}</h3>
|
||||
<h1 class="stream-date">{formattedStreamDate}</h1>
|
||||
</div>
|
||||
<h5 class="stream-tags"><u>Tags</u>: {$currentStream.tags.join(', ')}</h5>
|
||||
</div>
|
||||
<h5 class="stream-tags"><u>Tags</u>: {$currentStream.tags.join(', ')}</h5>
|
||||
</div>
|
||||
|
||||
<div class="description-bubble">
|
||||
{@html carta.renderSSR($currentStream.description || 'No description available.')}
|
||||
</div>
|
||||
<div class="description-bubble">
|
||||
{@html carta.renderSSR($currentStream.description || 'No description available.')}
|
||||
</div>
|
||||
|
||||
<div id="table-container">
|
||||
<table>
|
||||
<tbody>
|
||||
<tr><th>Timestamp</th><th>Artist</th><th>Title</th></tr>
|
||||
{#each $currentStream.tracks as track, i}
|
||||
<tr class:current={i == $currentSongIndex}>
|
||||
<td class="timestamp-field"
|
||||
><div class="timestamp-field-flex">
|
||||
{formatTrackTime(track[0])}
|
||||
<button
|
||||
onclick={() => jumpToTrack(track[0])}
|
||||
class="material-icons"
|
||||
style="padding: 4px 6px; margin-top: -4px; margin-bottom: -4px; margin-right: -6px"
|
||||
>fast_forward</button
|
||||
>
|
||||
</div>
|
||||
</td>
|
||||
<td class="artist-field">{track[1]}</td>
|
||||
<td class="track-field">{track[2]}</td>
|
||||
</tr>
|
||||
{/each}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
<div id="table-container">
|
||||
<table>
|
||||
<tbody>
|
||||
<tr><th>Timestamp</th><th>Artist</th><th>Title</th></tr>
|
||||
{#each $currentStream.tracks as track, i}
|
||||
<tr class:current={i == $currentSongIndex}>
|
||||
<td class="timestamp-field"
|
||||
><div class="timestamp-field-flex">
|
||||
{formatTrackTime(track[0])}
|
||||
<button
|
||||
onclick={() => jumpToTrack(track[0])}
|
||||
class="material-icons"
|
||||
style="padding: 4px 6px; margin-top: -4px; margin-bottom: -4px; margin-right: -6px"
|
||||
>fast_forward</button
|
||||
>
|
||||
</div>
|
||||
</td>
|
||||
<td class="artist-field">{track[1]}</td>
|
||||
<td class="track-field">{track[2]}</td>
|
||||
</tr>
|
||||
{/each}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
{/if}
|
||||
|
||||
<style>
|
||||
.stream-information {
|
||||
|
||||
Reference in New Issue
Block a user