add stream caching ("offline mode")

This commit is contained in:
2026-03-16 20:32:33 +01:00
parent 8573b82515
commit 3aa762d544
12 changed files with 153 additions and 17 deletions
+60 -4
View File
@@ -2,7 +2,8 @@
import { untrack } from 'svelte';
import { goto } from '$app/navigation';
import { favoritedStreams } from '$lib/stores.svelte.ts';
import { getStreamContext } from '$lib/stream-context.svelte.ts';
import * as streamCache from '$lib/streamCache.svelte.ts';
import { getStreamContext } from '$lib/streamContext.svelte.ts';
import type { StreamSummary } from '$lib/types';
import { hashColor, shorthandCode, formatSecondsToHms, formatDate } from '$lib/utils.ts';
import TagSelect from './TagSelect.svelte';
@@ -10,6 +11,7 @@
const ctx = getStreamContext();
let filteredTags = $state([]);
let favoritesOnly = $state(false);
let cachedOnly = $state(false);
let listOpen = $state();
let displayedStreams = $derived.by(streamsToDisplay);
let remainingTags = $derived.by(getRemainingTags);
@@ -50,6 +52,10 @@
<div class="tag-select">
<TagSelect bind:listOpen bind:checked={filteredTags} {remainingTags} />
<button
onclick={() => (cachedOnly = !cachedOnly)}
class="material-icons filter-download {cachedOnly ? 'select-faves-star' : 'unselect-faves-star'}">file_download</button
>
<button
onclick={() => (favoritesOnly = !favoritesOnly)}
class="material-icons {favoritesOnly ? '' : 'un'}select-faves-star">star</button
@@ -59,9 +65,10 @@
<ul class="stream-list">
{#each ctx.streams as stream}
{@const favorited = favoritedStreams.has(stream.id)}
{@const isCached = streamCache.cached.has(stream.id)}
{@const current = ctx.current?.id === stream.id}
<li
hidden={!displayedStreams.includes(stream) || (favoritesOnly && !favorited)}
hidden={!displayedStreams.includes(stream) || (favoritesOnly && !favorited) || (cachedOnly && !isCached)}
class="stream-item {current ? 'current-stream' : ''}"
id="stream-{stream.id}"
>
@@ -91,6 +98,19 @@
class="material-icons stream-item-star {favorited ? 'stream-item-star-faved' : ''}"
>{favorited ? 'star' : 'star_border'}</button
>
{#if streamCache.downloading.has(stream.id)}
<span class="stream-item-cached">{streamCache.downloading.get(stream.id)}%</span>
{:else if isCached}
<button
onclick={(e) => { e.stopPropagation(); streamCache.remove(stream.id); }}
class="material-icons stream-item-cached stream-item-cached-btn">delete</button
>
{:else}
<button
onclick={(e) => { e.stopPropagation(); streamCache.download(stream); }}
class="material-icons filter-download stream-item-cached stream-item-cached-btn">file_download</button
>
{/if}
</li>
{/each}
</ul>
@@ -168,24 +188,51 @@
.select-faves-star {
color: rgba(255, 219, 88, 1);
font-size: 24px;
transform: translateX(-1px);
}
.unselect-faves-star {
color: #bbbbbb;
font-size: 24px;
transform: translateX(-1px);
}
.filter-download {
transform: translateY(1px);
}
.stream-item-star {
font-size: 18px;
position: absolute;
bottom: 0;
right: 0;
bottom: 2px;
right: 2px;
opacity: 0;
}
.stream-item-star-faved {
opacity: 0.5;
}
.stream-item-cached {
font-size: 18px;
position: absolute;
bottom: 2px;
right: 22px;
opacity: 0;
}
.stream-item-cached-btn {
cursor: pointer;
}
.stream-item:hover .stream-item-cached {
opacity: 0.5;
}
.stream-item:hover .stream-item-cached-btn:hover {
opacity: 1;
}
.stream-item:hover .stream-item-star {
opacity: 0.5;
}
@@ -202,6 +249,15 @@
.stream-item-star {
opacity: 0.5;
font-size: 24px;
bottom: 4px;
right: 4px;
}
.stream-item-cached {
opacity: 0.4;
font-size: 24px;
bottom: 4px;
right: 30px;
}
}
</style>