web-player: remove dead code and unused props

This commit is contained in:
2026-09-24 05:04:09 +02:00
parent bc43b4b6eb
commit 37fc229bf6
24 changed files with 37 additions and 149 deletions
+4 -32
View File
@@ -1,6 +1,6 @@
import { browser } from '$app/environment';
import { DEFAULT_ACCENT } from '$lib/theme/color';
import { extractAccent, type Accent } from '$lib/theme/palette';
import { extractAccent } from '$lib/theme/palette';
import { shuffle } from '$lib/data/collections';
import { dialog } from '$lib/state/dialog.svelte';
import { ListenTracker } from './listenTracker';
@@ -17,12 +17,6 @@ export interface PlayerTrack {
listensCount?: number | string;
}
export interface Playlist {
id: string | number;
name: string;
trackIds: (string | number)[];
}
export interface QueueItem {
id: string | number;
title: string;
@@ -139,7 +133,6 @@ class PlayerState {
muted = $state(browser ? readStorage(MUTED_KEY) === 'true' : false);
loading = $state(false);
recentlyPlayed = $state<PlayerTrack[]>([]);
playlists = $state<Playlist[]>([]);
shuffle = $state(false);
repeat = $state(false);
@@ -147,7 +140,7 @@ class PlayerState {
#audio: HTMLAudioElement | null = null;
#loadToken = 0;
#accentCache = new Map<string, Accent>();
#accentCache = new Map<string, string>();
#rafId: number | null = null;
#listen = new ListenTracker();
@@ -157,10 +150,6 @@ class PlayerState {
this.current.duration > 0 ? Math.min(100, (this.progress / this.current.duration) * 100) : 0
);
get isPlaying() {
return this.playing;
}
#audioEl(): HTMLAudioElement | null {
if (!browser) return null;
if (this.#audio) return this.#audio;
@@ -301,14 +290,14 @@ class PlayerState {
const key = String(id);
const cached = this.#accentCache.get(key);
if (cached) {
this.accentColor = cached.accent;
this.accentColor = cached;
return;
}
const result = await extractAccent(`/api/tracks/${id}/cover?size=small`);
if (this.currentId !== id) return;
if (result) {
this.#accentCache.set(key, result);
this.accentColor = result.accent;
this.accentColor = result;
} else {
this.accentColor = null;
}
@@ -395,12 +384,6 @@ class PlayerState {
this.#syncMediaSessionMetadata(track);
}
playlistTracks(ids: (string | number)[]): PlayerTrack[] {
return ids
.map((id) => this.tracks.find((t) => t.id === id))
.filter((t): t is PlayerTrack => Boolean(t));
}
playQueue(list: QueueItem[], startIndex = 0) {
if (list.length === 0) return;
this.tracks = list.map(toTrack);
@@ -415,10 +398,6 @@ class PlayerState {
else this.playQueue(list, index);
}
playNextItem(item: QueueItem) {
this.playNext([item]);
}
playNext(items: QueueItem[]) {
if (items.length === 0) return;
if (this.currentId === null) {
@@ -452,13 +431,6 @@ class PlayerState {
this.#loadCurrent();
}
playPlaylist(id: string | number) {
const playlist = this.playlists.find((p) => p.id === id);
if (!playlist) return;
const items = this.playlistTracks(playlist.trackIds);
if (items.length > 0) this.playQueue(items, 0);
}
toggle() {
const audio = this.#audioEl();
if (!audio || this.currentId === null) return;