feat(playlists): Add playlist management - filter, sort, view modes, collage artwork

- Add PlaylistCollage component with Qobuz-style overlapping covers
- Add playlist_settings columns (hidden, position) with migration
- Add playlist_stats table for play count tracking
- Add backend commands for playlist management:
  - playlist_get_all_settings, playlist_set_hidden
  - playlist_set_position, playlist_reorder
  - playlist_get_stats, playlist_get_all_stats
  - playlist_increment_play_count
- Update Sidebar with filter dropdown (All/Visible/Hidden)
- Add sort dropdown (Name/Recent/Custom)
- Add view toggle between list and grid modes
- Fix TypeScript errors in +page.svelte and TitleBar.svelte
This commit is contained in:
vicrodh committed 2026-01-11 20:37:23 -06:00
1 parent 7affd2bf13
commit 3fb9ee1381
8 files changed
+874 -33

No files matched your search

+113
View File
@@ -0,0 +1,113 @@
<script lang="ts">
import { Music } from 'lucide-svelte';
interface Props {
artworks: string[]; // Album art URLs from tracks
size?: number; // Total width in px
class?: string; // Additional CSS classes
}
let {
artworks = [],
size = 120,
class: className = ''
}: Props = $props();
// Get unique artworks (dedupe same album covers)
const uniqueArtworks = $derived(() => {
const seen = new Set<string>();
return artworks.filter(art => {
if (!art || seen.has(art)) return false;
seen.add(art);
return true;
}).slice(0, 4);
});
const count = $derived(uniqueArtworks().length);
</script>
<div
class="collage {className}"
class:single={count === 1}
class:empty={count === 0}
style="--size: {size}px; --count: {count}"
>
{#if count === 0}
<!-- Empty placeholder -->
<div class="placeholder">
<Music size={size * 0.3} />
</div>
{:else if count === 1}
<!-- Single cover -->
<img src={uniqueArtworks()[0]} alt="" class="single-cover" />
{:else}
<!-- Collage with overlap -->
{#each uniqueArtworks() as art, i}
<img
src={art}
alt=""
class="cover"
style="--index: {i}"
/>
{/each}
{/if}
</div>
<style>
.collage {
position: relative;
width: var(--size);
height: calc(var(--size) * 0.65);
overflow: hidden;
border-radius: 6px;
background: var(--bg-tertiary);
flex-shrink: 0;
}
.collage.single,
.collage.empty {
height: var(--size);
}
.placeholder {
width: 100%;
height: 100%;
display: flex;
align-items: center;
justify-content: center;
color: var(--text-muted);
background: var(--bg-tertiary);
}
.single-cover {
width: 100%;
height: 100%;
object-fit: cover;
}
.cover {
position: absolute;
top: 0;
height: 100%;
width: auto;
aspect-ratio: 1;
object-fit: cover;
/* Overlap calculation: each cover shifts right by percentage of container width */
left: calc(var(--index) * (var(--size) * 0.22));
/* First cover on top (highest z-index), last on bottom */
z-index: calc(4 - var(--index));
/* Shadow on right edge for depth */
box-shadow: 4px 0 12px rgba(0, 0, 0, 0.4);
border-radius: 2px;
}
/* Adjust for 2 covers - more spacing */
.collage[style*="--count: 2"] .cover {
left: calc(var(--index) * (var(--size) * 0.35));
}
/* Adjust for 3 covers */
.collage[style*="--count: 3"] .cover {
left: calc(var(--index) * (var(--size) * 0.28));
}
</style>
+377 -10
View File
@@ -1,16 +1,30 @@
<script lang="ts">
import { Search, Home, HardDrive, Music, Disc3, Mic2, Plus, RefreshCw, ChevronDown, ChevronUp, Heart, ListMusic, Download } from 'lucide-svelte';
import { Search, Home, HardDrive, Plus, RefreshCw, ChevronDown, ChevronUp, Heart, ListMusic, Download, Filter, ArrowUpDown, LayoutGrid, List, GripVertical, EyeOff, Eye } from 'lucide-svelte';
import { invoke } from '@tauri-apps/api/core';
import { onMount } from 'svelte';
import NavigationItem from './NavigationItem.svelte';
import UserCard from './UserCard.svelte';
import PlaylistCollage from './PlaylistCollage.svelte';
interface Playlist {
id: number;
name: string;
tracks_count: number;
images?: string[];
duration?: number;
}
interface PlaylistSettings {
qobuz_playlist_id: number;
hidden: boolean;
position: number;
play_count?: number;
}
type PlaylistFilter = 'all' | 'visible' | 'hidden';
type PlaylistSort = 'name' | 'recent' | 'custom';
type PlaylistViewMode = 'list' | 'grid';
interface Props {
activeView: string;
selectedPlaylistId?: number | null;
@@ -40,10 +54,67 @@
}: Props = $props();
let userPlaylists = $state<Playlist[]>([]);
let playlistSettings = $state<Map<number, PlaylistSettings>>(new Map());
let playlistsLoading = $state(false);
let playlistsCollapsed = $state(false);
let localLibraryCollapsed = $state(false);
// Playlist management state
let playlistFilter = $state<PlaylistFilter>(
(localStorage.getItem('qbz-playlist-filter') as PlaylistFilter) || 'visible'
);
let playlistSort = $state<PlaylistSort>(
(localStorage.getItem('qbz-playlist-sort') as PlaylistSort) || 'name'
);
let playlistViewMode = $state<PlaylistViewMode>(
(localStorage.getItem('qbz-playlist-view') as PlaylistViewMode) || 'list'
);
let showFilterMenu = $state(false);
let showSortMenu = $state(false);
// Persist preferences
$effect(() => {
localStorage.setItem('qbz-playlist-filter', playlistFilter);
});
$effect(() => {
localStorage.setItem('qbz-playlist-sort', playlistSort);
});
$effect(() => {
localStorage.setItem('qbz-playlist-view', playlistViewMode);
});
// Filtered and sorted playlists
const filteredPlaylists = $derived.by(() => {
let result = [...userPlaylists];
// Apply filter
if (playlistFilter === 'visible') {
result = result.filter(p => {
const settings = playlistSettings.get(p.id);
return !settings?.hidden;
});
} else if (playlistFilter === 'hidden') {
result = result.filter(p => {
const settings = playlistSettings.get(p.id);
return settings?.hidden;
});
}
// Apply sort
if (playlistSort === 'name') {
result.sort((a, b) => a.name.localeCompare(b.name));
} else if (playlistSort === 'custom') {
result.sort((a, b) => {
const posA = playlistSettings.get(a.id)?.position ?? 999;
const posB = playlistSettings.get(b.id)?.position ?? 999;
return posA - posB;
});
}
// 'recent' keeps original order from API (already sorted by recent)
return result;
});
// Expose playlists to parent via binding
export function getPlaylists(): Playlist[] {
return userPlaylists;
@@ -55,6 +126,7 @@
onMount(() => {
loadUserPlaylists();
loadPlaylistSettings();
});
async function loadUserPlaylists() {
@@ -69,6 +141,34 @@
}
}
async function loadPlaylistSettings() {
try {
const settings = await invoke<PlaylistSettings[]>('playlist_get_all_settings');
const map = new Map<number, PlaylistSettings>();
for (const s of settings) {
map.set(s.qobuz_playlist_id, s);
}
playlistSettings = map;
} catch (err) {
// Command might not exist yet, that's ok
console.debug('Failed to load playlist settings:', err);
}
}
async function togglePlaylistHidden(playlistId: number) {
const current = playlistSettings.get(playlistId);
const newHidden = !current?.hidden;
try {
await invoke('playlist_set_hidden', { playlistId, hidden: newHidden });
// Update local state
const updated = new Map(playlistSettings);
updated.set(playlistId, { ...current, qobuz_playlist_id: playlistId, hidden: newHidden, position: current?.position ?? 0 });
playlistSettings = updated;
} catch (err) {
console.error('Failed to toggle playlist hidden:', err);
}
}
function handleViewChange(view: string) {
onNavigate(view);
}
@@ -123,6 +223,68 @@
<div class="playlists-header">
<div class="section-header">Playlists</div>
<div class="header-actions">
<!-- Filter dropdown -->
<div class="dropdown-container">
<button
class="icon-btn"
class:active={playlistFilter !== 'visible'}
onclick={() => showFilterMenu = !showFilterMenu}
title="Filter playlists"
>
{#if playlistFilter === 'hidden'}
<EyeOff size={14} />
{:else}
<Filter size={14} />
{/if}
</button>
{#if showFilterMenu}
<div class="dropdown-menu" role="menu">
<button class="dropdown-item" class:selected={playlistFilter === 'all'} onclick={() => { playlistFilter = 'all'; showFilterMenu = false; }}>
All
</button>
<button class="dropdown-item" class:selected={playlistFilter === 'visible'} onclick={() => { playlistFilter = 'visible'; showFilterMenu = false; }}>
Visible
</button>
<button class="dropdown-item" class:selected={playlistFilter === 'hidden'} onclick={() => { playlistFilter = 'hidden'; showFilterMenu = false; }}>
Hidden
</button>
</div>
{/if}
</div>
<!-- Sort dropdown -->
<div class="dropdown-container">
<button class="icon-btn" onclick={() => showSortMenu = !showSortMenu} title="Sort playlists">
<ArrowUpDown size={14} />
</button>
{#if showSortMenu}
<div class="dropdown-menu" role="menu">
<button class="dropdown-item" class:selected={playlistSort === 'name'} onclick={() => { playlistSort = 'name'; showSortMenu = false; }}>
Name (A-Z)
</button>
<button class="dropdown-item" class:selected={playlistSort === 'recent'} onclick={() => { playlistSort = 'recent'; showSortMenu = false; }}>
Recent
</button>
<button class="dropdown-item" class:selected={playlistSort === 'custom'} onclick={() => { playlistSort = 'custom'; showSortMenu = false; }}>
Custom Order
</button>
</div>
{/if}
</div>
<!-- View toggle -->
<button
class="icon-btn"
onclick={() => playlistViewMode = playlistViewMode === 'list' ? 'grid' : 'list'}
title={playlistViewMode === 'list' ? 'Grid view' : 'List view'}
>
{#if playlistViewMode === 'list'}
<LayoutGrid size={14} />
{:else}
<List size={14} />
{/if}
</button>
<button class="icon-btn" onclick={onCreatePlaylist} title="New playlist">
<Plus size={14} />
</button>
@@ -145,16 +307,57 @@
{#if !playlistsCollapsed}
{#if playlistsLoading}
<div class="playlists-loading">Loading...</div>
{:else if filteredPlaylists.length > 0}
{#if playlistViewMode === 'list'}
<!-- List View -->
<div class="playlists-list">
{#each filteredPlaylists as playlist (playlist.id)}
{@const isHidden = playlistSettings.get(playlist.id)?.hidden}
<button
class="playlist-list-item"
class:active={activeView === 'playlist' && selectedPlaylistId === playlist.id}
class:hidden-playlist={isHidden}
onclick={() => handlePlaylistClick(playlist)}
>
<PlaylistCollage artworks={playlist.images ?? []} size={36} />
<div class="playlist-info">
<span class="playlist-name">{playlist.name}</span>
<span class="playlist-count">{playlist.tracks_count} tracks</span>
</div>
{#if playlistFilter === 'all' && isHidden}
<EyeOff size={12} class="hidden-indicator" />
{/if}
</button>
{/each}
</div>
{:else}
<!-- Grid View -->
<div class="playlists-grid">
{#each filteredPlaylists as playlist (playlist.id)}
{@const isHidden = playlistSettings.get(playlist.id)?.hidden}
<button
class="playlist-grid-item"
class:active={activeView === 'playlist' && selectedPlaylistId === playlist.id}
class:hidden-playlist={isHidden}
onclick={() => handlePlaylistClick(playlist)}
>
<div class="grid-artwork">
<PlaylistCollage artworks={playlist.images ?? []} size={100} />
{#if playlistFilter === 'all' && isHidden}
<div class="hidden-badge">
<EyeOff size={12} />
</div>
{/if}
</div>
<span class="playlist-name">{playlist.name}</span>
</button>
{/each}
</div>
{/if}
{:else if userPlaylists.length > 0}
{#each userPlaylists as playlist (playlist.id)}
<NavigationItem
label={playlist.name}
active={activeView === 'playlist' && selectedPlaylistId === playlist.id}
onclick={() => handlePlaylistClick(playlist)}
>
{#snippet icon()}<ListMusic size={14} />{/snippet}
</NavigationItem>
{/each}
<div class="no-playlists">
{playlistFilter === 'hidden' ? 'No hidden playlists' : 'No visible playlists'}
</div>
{:else}
<div class="no-playlists">No playlists yet</div>
{/if}
@@ -324,12 +527,176 @@
cursor: pointer;
padding: 2px;
transition: color 150ms ease;
border-radius: 4px;
}
.icon-btn:hover {
color: var(--text-primary);
}
.icon-btn.active {
color: var(--accent-primary);
}
/* Dropdown menus */
.dropdown-container {
position: relative;
}
.dropdown-menu {
position: absolute;
top: 100%;
right: 0;
margin-top: 4px;
background: var(--bg-secondary);
border: 1px solid var(--bg-tertiary);
border-radius: 6px;
padding: 4px;
min-width: 120px;
z-index: 100;
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}
.dropdown-item {
display: block;
width: 100%;
padding: 6px 10px;
background: none;
border: none;
color: var(--text-primary);
font-size: 12px;
text-align: left;
cursor: pointer;
border-radius: 4px;
transition: background-color 150ms ease;
}
.dropdown-item:hover {
background: var(--bg-tertiary);
}
.dropdown-item.selected {
color: var(--accent-primary);
}
/* Playlist list view */
.playlists-list {
display: flex;
flex-direction: column;
gap: 2px;
}
.playlist-list-item {
display: flex;
align-items: center;
gap: 10px;
padding: 6px 8px;
background: none;
border: none;
border-radius: 6px;
cursor: pointer;
transition: background-color 150ms ease;
text-align: left;
width: 100%;
}
.playlist-list-item:hover {
background: var(--bg-tertiary);
}
.playlist-list-item.active {
background: var(--bg-hover);
}
.playlist-list-item.hidden-playlist {
opacity: 0.5;
}
.playlist-info {
flex: 1;
min-width: 0;
display: flex;
flex-direction: column;
gap: 1px;
}
.playlist-name {
font-size: 13px;
color: var(--text-primary);
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
}
.playlist-count {
font-size: 11px;
color: var(--text-muted);
}
.playlist-list-item :global(.hidden-indicator) {
color: var(--text-muted);
flex-shrink: 0;
}
/* Playlist grid view */
.playlists-grid {
display: grid;
grid-template-columns: repeat(2, 1fr);
gap: 8px;
padding: 0 4px;
}
.playlist-grid-item {
display: flex;
flex-direction: column;
gap: 6px;
padding: 8px;
background: none;
border: none;
border-radius: 8px;
cursor: pointer;
transition: background-color 150ms ease;
text-align: center;
}
.playlist-grid-item:hover {
background: var(--bg-tertiary);
}
.playlist-grid-item.active {
background: var(--bg-hover);
}
.playlist-grid-item.hidden-playlist {
opacity: 0.5;
}
.grid-artwork {
position: relative;
width: 100%;
display: flex;
justify-content: center;
}
.hidden-badge {
position: absolute;
top: 4px;
right: 4px;
background: rgba(0, 0, 0, 0.7);
border-radius: 4px;
padding: 4px;
color: var(--text-muted);
}
.playlist-grid-item .playlist-name {
font-size: 12px;
line-height: 1.3;
display: -webkit-box;
-webkit-line-clamp: 2;
-webkit-box-orient: vertical;
overflow: hidden;
}
.playlists-loading,
.no-playlists {
font-size: 12px;
+12 -8
View File
@@ -6,19 +6,23 @@
let isMaximized = $state(false);
let appWindow: ReturnType<typeof getCurrentWindow>;
onMount(async () => {
appWindow = getCurrentWindow();
onMount(() => {
let unlisten: (() => void) | undefined;
// Check initial maximized state
isMaximized = await appWindow.isMaximized();
(async () => {
appWindow = getCurrentWindow();
// Listen for window state changes
const unlisten = await appWindow.onResized(async () => {
// Check initial maximized state
isMaximized = await appWindow.isMaximized();
});
// Listen for window state changes
unlisten = await appWindow.onResized(async () => {
isMaximized = await appWindow.isMaximized();
});
})();
return () => {
unlisten();
unlisten?.();
};
});