feat(playlists): Update PlaylistDetailView with collage, stats, edit button
- Replace artwork section with PlaylistCollage component - Add play count display in header info (with BarChart2 icon) - Increment play count when "Play All" is clicked - Add edit button that opens PlaylistModal - Add handleEditSuccess and handleDelete callbacks - Add onPlaylistUpdated and onPlaylistDeleted props - Update Sidebar to use NavigationItem in list view (icons only) - Keep PlaylistCollage in grid view only per user request - Add badge and class props to NavigationItem component
This commit is contained in:
1 parent
ec4df03455
commit
513ac9a8a0
3 files changed
+154
-86
No files matched your search
@@ -4,16 +4,18 @@
|
||||
interface Props {
|
||||
icon: Snippet;
|
||||
label: string;
|
||||
badge?: string;
|
||||
active?: boolean;
|
||||
onclick?: () => void;
|
||||
class?: string;
|
||||
}
|
||||
|
||||
let { icon, label, active = false, onclick }: Props = $props();
|
||||
let { icon, label, badge, active = false, onclick, class: className = '' }: Props = $props();
|
||||
</script>
|
||||
|
||||
<button
|
||||
{onclick}
|
||||
class="nav-item"
|
||||
class="nav-item {className}"
|
||||
class:active
|
||||
title={label}
|
||||
>
|
||||
@@ -21,6 +23,9 @@
|
||||
{@render icon()}
|
||||
</div>
|
||||
<span class="label">{label}</span>
|
||||
{#if badge}
|
||||
<span class="badge">{badge}</span>
|
||||
{/if}
|
||||
</button>
|
||||
|
||||
<style>
|
||||
@@ -67,4 +72,10 @@
|
||||
flex: 1;
|
||||
min-width: 0;
|
||||
}
|
||||
|
||||
.badge {
|
||||
font-size: 11px;
|
||||
color: var(--text-muted);
|
||||
flex-shrink: 0;
|
||||
}
|
||||
</style>
|
||||
@@ -309,27 +309,27 @@
|
||||
<div class="playlists-loading">Loading...</div>
|
||||
{:else if filteredPlaylists.length > 0}
|
||||
{#if playlistViewMode === 'list'}
|
||||
<!-- List View -->
|
||||
<div class="playlists-list">
|
||||
<!-- List View - use NavigationItem with icon -->
|
||||
<nav class="playlists-nav">
|
||||
{#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}
|
||||
<NavigationItem
|
||||
label={playlist.name}
|
||||
badge={playlist.tracks_count.toString()}
|
||||
active={activeView === 'playlist' && selectedPlaylistId === playlist.id}
|
||||
class={isHidden ? 'hidden-playlist' : ''}
|
||||
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>
|
||||
{#snippet icon()}
|
||||
{#if playlistFilter === 'all' && isHidden}
|
||||
<EyeOff size={14} />
|
||||
{:else}
|
||||
<ListMusic size={14} />
|
||||
{/if}
|
||||
{/snippet}
|
||||
</NavigationItem>
|
||||
{/each}
|
||||
</div>
|
||||
</nav>
|
||||
{:else}
|
||||
<!-- Grid View -->
|
||||
<div class="playlists-grid">
|
||||
@@ -580,64 +580,16 @@
|
||||
}
|
||||
|
||||
/* Playlist list view */
|
||||
.playlists-list {
|
||||
.playlists-nav {
|
||||
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 {
|
||||
.playlists-nav :global(.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;
|
||||
@@ -695,6 +647,7 @@
|
||||
-webkit-line-clamp: 2;
|
||||
-webkit-box-orient: vertical;
|
||||
overflow: hidden;
|
||||
color: var(--text-primary);
|
||||
}
|
||||
|
||||
.playlists-loading,
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
<script lang="ts">
|
||||
import { ArrowLeft, Play, Shuffle, ListMusic, Search, X, ChevronDown, ImagePlus, HardDrive, Info } from 'lucide-svelte';
|
||||
import { ArrowLeft, Play, Shuffle, ListMusic, Search, X, ChevronDown, ImagePlus, HardDrive, Info, Edit3, BarChart2 } from 'lucide-svelte';
|
||||
import AlbumMenu from '../AlbumMenu.svelte';
|
||||
import PlaylistCollage from '../PlaylistCollage.svelte';
|
||||
import PlaylistModal from '../PlaylistModal.svelte';
|
||||
import { writeText } from '@tauri-apps/plugin-clipboard-manager';
|
||||
import { invoke } from '@tauri-apps/api/core';
|
||||
import { open } from '@tauri-apps/plugin-dialog';
|
||||
@@ -73,6 +75,14 @@
|
||||
sort_order: string;
|
||||
last_search_query?: string;
|
||||
notes?: string;
|
||||
hidden?: boolean;
|
||||
position?: number;
|
||||
}
|
||||
|
||||
interface PlaylistStats {
|
||||
qobuz_playlist_id: number;
|
||||
play_count: number;
|
||||
last_played_at?: number;
|
||||
}
|
||||
|
||||
type SortField = 'default' | 'title' | 'artist' | 'album' | 'duration';
|
||||
@@ -97,6 +107,8 @@
|
||||
onLocalTrackPlay?: (track: LocalLibraryTrack) => void;
|
||||
onLocalTrackPlayNext?: (track: LocalLibraryTrack) => void;
|
||||
onLocalTrackPlayLater?: (track: LocalLibraryTrack) => void;
|
||||
onPlaylistUpdated?: () => void;
|
||||
onPlaylistDeleted?: (playlistId: number) => void;
|
||||
}
|
||||
|
||||
let {
|
||||
@@ -117,7 +129,9 @@
|
||||
downloadStateVersion,
|
||||
onLocalTrackPlay,
|
||||
onLocalTrackPlayNext,
|
||||
onLocalTrackPlayLater
|
||||
onLocalTrackPlayLater,
|
||||
onPlaylistUpdated,
|
||||
onPlaylistDeleted
|
||||
}: Props = $props();
|
||||
|
||||
let playlist = $state<Playlist | null>(null);
|
||||
@@ -135,6 +149,9 @@
|
||||
let sortOrder = $state<SortOrder>('asc');
|
||||
let customArtworkPath = $state<string | null>(null);
|
||||
let showSortMenu = $state(false);
|
||||
let playlistSettings = $state<PlaylistSettings | null>(null);
|
||||
let playlistStats = $state<PlaylistStats | null>(null);
|
||||
let editModalOpen = $state(false);
|
||||
|
||||
// Reload playlist when playlistId changes
|
||||
$effect(() => {
|
||||
@@ -143,6 +160,7 @@
|
||||
loadPlaylist();
|
||||
loadSettings();
|
||||
loadLocalTracks();
|
||||
loadStats();
|
||||
});
|
||||
|
||||
async function loadLocalTracks() {
|
||||
@@ -192,6 +210,7 @@
|
||||
async function loadSettings() {
|
||||
try {
|
||||
const settings = await invoke<PlaylistSettings | null>('playlist_get_settings', { playlistId });
|
||||
playlistSettings = settings;
|
||||
if (settings) {
|
||||
sortBy = (settings.sort_by as SortField) || 'default';
|
||||
sortOrder = (settings.sort_order as SortOrder) || 'asc';
|
||||
@@ -203,6 +222,15 @@
|
||||
}
|
||||
}
|
||||
|
||||
async function loadStats() {
|
||||
try {
|
||||
const stats = await invoke<PlaylistStats | null>('playlist_get_stats', { playlistId });
|
||||
playlistStats = stats;
|
||||
} catch (err) {
|
||||
console.error('Failed to load playlist stats:', err);
|
||||
}
|
||||
}
|
||||
|
||||
async function saveSort(field: SortField, order: SortOrder) {
|
||||
sortBy = field;
|
||||
sortOrder = order;
|
||||
@@ -399,12 +427,29 @@
|
||||
try {
|
||||
await invoke('set_queue', { tracks: queueTracks, startIndex: 0 });
|
||||
onTrackPlay(tracks[0]);
|
||||
|
||||
// Increment play count
|
||||
const stats = await invoke<PlaylistStats>('playlist_increment_play_count', { playlistId });
|
||||
playlistStats = stats;
|
||||
} catch (err) {
|
||||
console.error('Failed to set queue:', err);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function handleEditSuccess() {
|
||||
editModalOpen = false;
|
||||
loadPlaylist(); // Reload playlist data
|
||||
loadSettings(); // Reload settings (including hidden status)
|
||||
onPlaylistUpdated?.();
|
||||
}
|
||||
|
||||
function handleDelete(deletedPlaylistId: number) {
|
||||
editModalOpen = false;
|
||||
onPlaylistDeleted?.(deletedPlaylistId);
|
||||
onBack();
|
||||
}
|
||||
|
||||
async function handleShuffle() {
|
||||
if (tracks.length > 0 && onTrackPlay) {
|
||||
try {
|
||||
@@ -497,27 +542,30 @@
|
||||
{:else if playlist}
|
||||
<!-- Playlist Header -->
|
||||
<div class="playlist-header">
|
||||
<!-- Playlist Artwork with customization -->
|
||||
<!-- Playlist Artwork - Collage or Custom -->
|
||||
<div class="artwork-container">
|
||||
<div class="artwork">
|
||||
{#if getPlaylistImage()}
|
||||
<img src={getPlaylistImage()} alt={playlist.name} />
|
||||
{:else}
|
||||
<div class="artwork-placeholder">
|
||||
<ListMusic size={64} />
|
||||
</div>
|
||||
{/if}
|
||||
<div class="artwork-overlay">
|
||||
<button class="artwork-btn" onclick={selectCustomArtwork} title="Set custom artwork">
|
||||
<ImagePlus size={24} />
|
||||
</button>
|
||||
{#if customArtworkPath}
|
||||
{#if customArtworkPath}
|
||||
<div class="artwork custom-artwork">
|
||||
<img src={customArtworkPath} alt={playlist.name} />
|
||||
<div class="artwork-overlay">
|
||||
<button class="artwork-btn artwork-clear" onclick={clearCustomArtwork} title="Remove custom artwork">
|
||||
<X size={20} />
|
||||
</button>
|
||||
{/if}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{:else}
|
||||
<div class="collage-wrapper">
|
||||
<PlaylistCollage
|
||||
artworks={tracks.slice(0, 4).map(t => t.albumArt).filter((a): a is string => !!a)}
|
||||
size={200}
|
||||
/>
|
||||
<div class="artwork-overlay">
|
||||
<button class="artwork-btn" onclick={selectCustomArtwork} title="Set custom artwork">
|
||||
<ImagePlus size={24} />
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
{/if}
|
||||
</div>
|
||||
|
||||
<!-- Playlist Metadata -->
|
||||
@@ -533,6 +581,13 @@
|
||||
<span>{playlist.tracks_count} tracks</span>
|
||||
<span class="separator">•</span>
|
||||
<span>{formatTotalDuration(playlist.duration)}</span>
|
||||
{#if playlistStats && playlistStats.play_count > 0}
|
||||
<span class="separator">•</span>
|
||||
<span class="play-count" title="Times played">
|
||||
<BarChart2 size={12} />
|
||||
{playlistStats.play_count}
|
||||
</span>
|
||||
{/if}
|
||||
</div>
|
||||
|
||||
<!-- Action Buttons -->
|
||||
@@ -551,6 +606,9 @@
|
||||
<Shuffle size={18} />
|
||||
<span>Shuffle</span>
|
||||
</button>
|
||||
<button class="secondary-btn" onclick={() => editModalOpen = true} title="Edit playlist">
|
||||
<Edit3 size={18} />
|
||||
</button>
|
||||
<AlbumMenu
|
||||
onPlayNext={handlePlayAllNext}
|
||||
onPlayLater={handlePlayAllLater}
|
||||
@@ -695,6 +753,19 @@
|
||||
{/if}
|
||||
</div>
|
||||
|
||||
<!-- Edit Playlist Modal -->
|
||||
{#if playlist}
|
||||
<PlaylistModal
|
||||
isOpen={editModalOpen}
|
||||
mode="edit"
|
||||
playlist={{ id: playlist.id, name: playlist.name, tracks_count: playlist.tracks_count }}
|
||||
isHidden={playlistSettings?.hidden ?? false}
|
||||
onClose={() => editModalOpen = false}
|
||||
onSuccess={handleEditSuccess}
|
||||
onDelete={handleDelete}
|
||||
/>
|
||||
{/if}
|
||||
|
||||
<style>
|
||||
.playlist-detail {
|
||||
padding: 24px;
|
||||
@@ -769,6 +840,27 @@
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
.collage-wrapper {
|
||||
position: relative;
|
||||
}
|
||||
|
||||
.collage-wrapper .artwork-overlay {
|
||||
position: absolute;
|
||||
inset: 0;
|
||||
background: rgba(0, 0, 0, 0.6);
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
gap: 8px;
|
||||
opacity: 0;
|
||||
transition: opacity 150ms ease;
|
||||
border-radius: 6px;
|
||||
}
|
||||
|
||||
.collage-wrapper:hover .artwork-overlay {
|
||||
opacity: 1;
|
||||
}
|
||||
|
||||
.artwork {
|
||||
width: 186px;
|
||||
height: 186px;
|
||||
@@ -779,6 +871,11 @@
|
||||
box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
|
||||
}
|
||||
|
||||
.custom-artwork {
|
||||
width: 200px;
|
||||
height: 200px;
|
||||
}
|
||||
|
||||
.artwork img {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
@@ -889,6 +986,13 @@
|
||||
color: var(--text-muted);
|
||||
}
|
||||
|
||||
.play-count {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 4px;
|
||||
color: var(--text-muted);
|
||||
}
|
||||
|
||||
.actions {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
|
||||
Reference in new issue
Block a user