Move domain data helpers into lib/data

This commit is contained in:
2026-09-22 14:10:55 +02:00
parent ff5fa501af
commit 53fc24d4bc
10 changed files with 176 additions and 8 deletions
+22
View File
@@ -0,0 +1,22 @@
import { player, toQueueItems, type ApiTrackLike, type QueueItem } from '$lib/player/player.svelte';
export function mergeRecentlyPlayed(history: ApiTrackLike[], limit: number): QueueItem[] {
const seen = new Set<string>();
const merged: QueueItem[] = [];
for (const t of player.recentlyPlayed) {
const id = String(t.id);
if (seen.has(id)) continue;
seen.add(id);
merged.push({ ...t, id });
}
for (const item of toQueueItems(history)) {
const id = String(item.id);
if (seen.has(id)) continue;
seen.add(id);
merged.push({ ...item, id });
}
return merged.slice(0, limit);
}