feat(label): redesign Label Releases view with logo, sorting, and filters

- Replace generic icon with circular label logo (matches LabelView)
- Fix double close button in search: single X that clears and closes
- Add sort options: newest, oldest, title A-Z/Z-A, artist A-Z
- Add Hi-Res filter toggle
- Load all albums automatically when sorting/filtering
- i18n: add labelReleases keys to all 4 locales
- Search bar now replaces title area instead of floating separately

API analysis: Qobuz label endpoints have no server-side sort/filter
params, so all sorting and filtering is done client-side after
paginated fetch.
This commit is contained in:
vicrodh committed 2026-03-05 14:33:42 -06:00
1 parent 97f42f4fea
commit 4e6a52e453
5 files changed
+379 -117

No files matched your search

+311 -117
View File
@@ -1,7 +1,8 @@
<script lang="ts">
import { invoke } from '@tauri-apps/api/core';
import { onMount } from 'svelte';
import { ArrowLeft, Search, X, Disc3, Loader2 } from 'lucide-svelte';
import { t } from 'svelte-i18n';
import { ArrowLeft, Search, X, Disc3, Loader2, ArrowUpDown, Filter, ChevronDown } from 'lucide-svelte';
import AlbumCard from '../AlbumCard.svelte';
import type { QobuzAlbum, LabelDetail } from '$lib/types';
import type { OfflineCacheStatus } from '$lib/stores/offlineCacheState';
@@ -55,6 +56,12 @@
let totalAlbums = $state(0);
let albumsFetched = $state(0);
// Sort/filter state
type SortOption = 'newest' | 'oldest' | 'title-az' | 'title-za' | 'artist-az';
let sortBy = $state<SortOption>('newest');
let filterHiRes = $state(false);
let showSortMenu = $state(false);
// API search state
let apiSearchResults = $state<QobuzAlbum[] | null>(null);
let apiSearching = $state(false);
@@ -64,8 +71,53 @@
// Download status tracking
let albumOfflineCacheStatuses = $state<Map<string, boolean>>(new Map());
// When API search is active, show API results; otherwise show all loaded albums
let displayAlbums = $derived(apiSearchResults !== null ? apiSearchResults : albums);
// Sorted + filtered albums
let processedAlbums = $derived.by(() => {
let source = apiSearchResults !== null ? apiSearchResults : albums;
// Filter
if (filterHiRes) {
source = source.filter(album => album.hires_streamable);
}
// Local text filter (when search is open but < 2 chars for API search)
if (searchQuery.trim().length > 0 && searchQuery.trim().length < 2 && apiSearchResults === null) {
const q = searchQuery.trim().toLowerCase();
source = source.filter(album =>
album.title?.toLowerCase().includes(q) ||
album.artist?.name?.toLowerCase().includes(q)
);
}
// Sort
const sorted = [...source];
switch (sortBy) {
case 'newest':
sorted.sort((a, b) => (b.release_date_original || '').localeCompare(a.release_date_original || ''));
break;
case 'oldest':
sorted.sort((a, b) => (a.release_date_original || '').localeCompare(b.release_date_original || ''));
break;
case 'title-az':
sorted.sort((a, b) => (a.title || '').localeCompare(b.title || ''));
break;
case 'title-za':
sorted.sort((a, b) => (b.title || '').localeCompare(a.title || ''));
break;
case 'artist-az':
sorted.sort((a, b) => (a.artist?.name || '').localeCompare(b.artist?.name || ''));
break;
}
return sorted;
});
const sortLabels: Record<SortOption, string> = {
'newest': 'labelReleases.sortNewest',
'oldest': 'labelReleases.sortOldest',
'title-az': 'labelReleases.sortTitleAZ',
'title-za': 'labelReleases.sortTitleZA',
'artist-az': 'labelReleases.sortArtistAZ'
};
async function loadLabel() {
loading = true;
@@ -95,7 +147,6 @@
totalAlbums = label.totalAlbums;
albumsFetched = label.albumsFetched;
// Load download statuses
await loadAllAlbumOfflineCacheStatuses(albums);
} catch (e) {
console.error('Failed to load label:', e);
@@ -121,7 +172,6 @@
albums = [...albums, ...newAlbums];
albumsFetched += newAlbums.length;
// Load download statuses for new albums
await loadAllAlbumOfflineCacheStatuses(newAlbums);
} catch (e) {
console.error('Failed to load more albums:', e);
@@ -130,6 +180,12 @@
}
}
async function loadAllAlbums() {
while (albumsFetched < totalAlbums && !loadingMore) {
await loadMore();
}
}
async function loadAlbumOfflineCacheStatus(albumId: string) {
if (!checkAlbumFullyDownloaded) return false;
try {
@@ -164,31 +220,35 @@
return album.genre?.name || '';
}
function clearSearch() {
function getLabelImage(): string {
if (!label?.image) return '';
return label.image.large || label.image.thumbnail || label.image.small || '';
}
function closeSearch() {
searchQuery = '';
searchExpanded = false;
apiSearchResults = null;
apiSearching = false;
if (searchTimeout) clearTimeout(searchTimeout);
}
function toggleSearch() {
searchExpanded = !searchExpanded;
if (!searchExpanded) {
searchQuery = '';
apiSearchResults = null;
apiSearching = false;
if (searchTimeout) clearTimeout(searchTimeout);
}
}
function handleSearchInput() {
if (searchTimeout) clearTimeout(searchTimeout);
const query = searchQuery.trim();
if (!query) {
apiSearchResults = null;
apiSearching = false;
return;
}
if (query.length < 2) {
apiSearchResults = null;
apiSearching = false;
return;
}
apiSearching = true;
searchTimeout = setTimeout(() => performLabelSearch(query), 300);
}
@@ -212,7 +272,6 @@
}
}
// Scroll handler for infinite loading (disabled during API search)
function handleScroll(e: Event) {
if (apiSearchResults !== null) return;
const target = e.target as HTMLElement;
@@ -223,6 +282,22 @@
}
}
function handleSortSelect(option: SortOption) {
sortBy = option;
showSortMenu = false;
// Load all albums when sorting to ensure complete results
if (albumsFetched < totalAlbums) {
loadAllAlbums();
}
}
function toggleHiResFilter() {
filterHiRes = !filterHiRes;
if (filterHiRes && albumsFetched < totalAlbums) {
loadAllAlbums();
}
}
onMount(() => {
loadLabel();
});
@@ -231,95 +306,133 @@
<div class="label-view" onscroll={handleScroll}>
<!-- Header -->
<header class="header">
<button class="back-btn" onclick={onBack} title="Go back">
<button class="back-btn" onclick={onBack} title={$t('actions.back')}>
<ArrowLeft size={20} />
</button>
<div class="header-icon">
<Disc3 size={36} strokeWidth={1.5} />
<div class="label-image-wrapper">
{#if getLabelImage()}
<img src={getLabelImage()} alt={label?.name || labelName} class="label-image" loading="lazy" decoding="async" />
{:else}
<div class="label-image-placeholder">
<Disc3 size={36} />
</div>
{/if}
</div>
<div class="header-content">
<div class="header-subtitle">{$t('label.title')}</div>
<h1>{label?.name || labelName || 'Label'}</h1>
<p class="subtitle">
{#if loading}
Loading...
{$t('actions.loading')}
{:else if totalAlbums > 0}
{totalAlbums} album{totalAlbums !== 1 ? 's' : ''}
{totalAlbums} {$t('labelReleases.albumCount', { values: { count: totalAlbums } })}
{/if}
</p>
</div>
</header>
<!-- Fixed Navigation/Search Bar -->
<!-- Toolbar: Search + Sort + Filter -->
<nav class="label-nav">
<div class="nav-left">
<span class="nav-title">Albums</span>
{#if apiSearchResults !== null}
<span class="nav-count">{apiSearchResults.length} result{apiSearchResults.length !== 1 ? 's' : ''}</span>
{:else if albumsFetched > 0 && albumsFetched < totalAlbums}
<span class="nav-count">Showing {albumsFetched} of {totalAlbums}</span>
{/if}
</div>
<div class="nav-right">
{#if searchExpanded}
<div class="search-expanded">
<Search size={16} class="search-icon-inline" />
<div class="search-bar">
<Search size={15} class="search-icon-inline" />
<!-- svelte-ignore a11y_autofocus -->
<input
type="text"
class="search-input-inline"
placeholder="Search albums..."
placeholder={$t('labelReleases.searchPlaceholder')}
bind:value={searchQuery}
oninput={handleSearchInput}
autofocus
/>
{#if searchQuery}
<button class="search-clear-btn" onclick={clearSearch}>
<X size={14} />
</button>
{/if}
<button class="search-close-btn" onclick={toggleSearch}>
<X size={16} />
<button class="search-clear-btn" onclick={closeSearch} title={$t('actions.close')}>
<X size={15} />
</button>
</div>
{:else}
<button class="search-icon-btn" onclick={toggleSearch} title="Search albums">
<Search size={18} />
<span class="nav-title">{$t('label.releases')}</span>
{#if apiSearchResults !== null}
<span class="nav-count">{processedAlbums.length} {$t('labelReleases.results')}</span>
{:else if albumsFetched > 0 && albumsFetched < totalAlbums}
<span class="nav-count">{$t('labelReleases.showingOf', { values: { shown: albumsFetched, total: totalAlbums } })}</span>
{:else if filterHiRes && albums.length > 0}
<span class="nav-count">{processedAlbums.length} Hi-Res</span>
{/if}
{/if}
</div>
<div class="nav-right">
{#if !searchExpanded}
<button class="toolbar-btn" onclick={() => searchExpanded = true} title={$t('labelReleases.searchAlbums')}>
<Search size={16} />
</button>
{/if}
<button
class="toolbar-btn"
class:active={filterHiRes}
onclick={toggleHiResFilter}
title={$t('labelReleases.filterHiRes')}
>
<Filter size={16} />
<span class="toolbar-label">Hi-Res</span>
</button>
<div class="sort-dropdown">
<button class="toolbar-btn" onclick={() => showSortMenu = !showSortMenu} title={$t('labelReleases.sort')}>
<ArrowUpDown size={16} />
<span class="toolbar-label">{$t(sortLabels[sortBy])}</span>
<ChevronDown size={12} />
</button>
{#if showSortMenu}
<!-- svelte-ignore a11y_no_static_element_interactions -->
<div class="sort-menu" onmouseleave={() => showSortMenu = false}>
{#each Object.entries(sortLabels) as [key, labelKey]}
<button
class="sort-option"
class:active={sortBy === key}
onclick={() => handleSortSelect(key as SortOption)}
>
{$t(labelKey)}
</button>
{/each}
</div>
{/if}
</div>
</div>
</nav>
<!-- Content -->
<div class="content">
{#if loading}
<div class="loading">
<div class="status-message">
<div class="spinner"></div>
<p>Loading label...</p>
<p>{$t('actions.loading')}</p>
</div>
{:else if error}
<div class="error">
<p>Failed to load label</p>
<div class="status-message">
<p>{$t('errors.generic')}</p>
<p class="error-detail">{error}</p>
<button class="retry-btn" onclick={loadLabel}>Retry</button>
<button class="retry-btn" onclick={loadLabel}>{$t('actions.retry')}</button>
</div>
{:else if albums.length === 0}
<div class="empty">
<div class="status-message">
<Disc3 size={48} />
<p>No albums found for this label</p>
<p>{$t('labelReleases.noAlbums')}</p>
</div>
{:else if apiSearching}
<div class="loading">
<div class="status-message">
<div class="spinner"></div>
<p>Searching...</p>
<p>{$t('actions.loading')}</p>
</div>
{:else if displayAlbums.length === 0}
<div class="empty">
{:else if processedAlbums.length === 0}
<div class="status-message">
<Search size={48} />
<p>No albums match "{searchQuery}"</p>
<p>{$t('labelReleases.noResults')}</p>
</div>
{:else}
<div class="album-grid">
{#each displayAlbums as album (album.id)}
{#each processedAlbums as album (album.id)}
<AlbumCard
albumId={album.id}
artwork={album.image?.large || album.image?.thumbnail || ''}
@@ -350,7 +463,7 @@
{#if loadingMore}
<div class="loading-more">
<Loader2 size={20} class="spinner-icon" />
<span>Loading more albums...</span>
<span>{$t('labelReleases.loadingMore')}</span>
</div>
{/if}
{/if}
@@ -367,24 +480,12 @@
height: 100%;
}
/* Custom scrollbar */
.label-view::-webkit-scrollbar {
width: 6px;
}
.label-view::-webkit-scrollbar-track {
background: transparent;
}
.label-view::-webkit-scrollbar-thumb {
background: var(--bg-tertiary);
border-radius: 3px;
}
.label-view::-webkit-scrollbar-thumb:hover {
background: var(--text-muted);
}
.label-view::-webkit-scrollbar { width: 6px; }
.label-view::-webkit-scrollbar-track { background: transparent; }
.label-view::-webkit-scrollbar-thumb { background: var(--bg-tertiary); border-radius: 3px; }
.label-view::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }
/* Header */
.header {
display: flex;
align-items: center;
@@ -404,6 +505,7 @@
color: var(--text-secondary);
cursor: pointer;
transition: all 150ms ease;
flex-shrink: 0;
}
.back-btn:hover {
@@ -411,34 +513,62 @@
color: var(--text-primary);
}
.header-icon {
width: 80px;
height: 80px;
.label-image-wrapper {
width: 72px;
height: 72px;
border-radius: 50%;
overflow: hidden;
flex-shrink: 0;
background: var(--bg-tertiary);
}
.label-image {
width: 100%;
height: 100%;
object-fit: cover;
}
.label-image-placeholder {
width: 100%;
height: 100%;
display: flex;
align-items: center;
justify-content: center;
background: linear-gradient(135deg, #6366f1 0%, #8b5cf6 100%);
border-radius: 16px;
color: white;
}
.header-content {
flex: 1;
min-width: 0;
}
.header-subtitle {
font-size: 11px;
font-weight: 600;
color: var(--text-muted);
text-transform: uppercase;
letter-spacing: 0.1em;
margin-bottom: 2px;
}
.header-content h1 {
font-size: 24px;
font-size: 22px;
font-weight: 700;
color: var(--text-primary);
margin: 0 0 4px 0;
margin: 0 0 2px 0;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
}
.subtitle {
font-size: 14px;
font-size: 13px;
color: var(--text-muted);
margin: 0;
}
/* Toolbar */
.label-nav {
position: sticky;
top: -24px;
@@ -447,7 +577,7 @@
justify-content: space-between;
align-items: center;
gap: 10px;
padding: 12px 24px;
padding: 10px 24px;
margin: 0 -8px 16px -24px;
width: calc(100% + 32px);
background: var(--bg-primary);
@@ -459,12 +589,15 @@
display: flex;
align-items: center;
gap: 12px;
flex: 1;
min-width: 0;
}
.nav-title {
font-size: 14px;
font-weight: 600;
color: var(--text-primary);
flex-shrink: 0;
}
.nav-count {
@@ -475,37 +608,21 @@
.nav-right {
display: flex;
align-items: center;
gap: 8px;
gap: 4px;
flex-shrink: 0;
}
.search-icon-btn {
display: flex;
align-items: center;
justify-content: center;
width: 32px;
height: 32px;
border: none;
background: none;
color: var(--text-muted);
cursor: pointer;
border-radius: 6px;
transition: all 150ms ease;
}
.search-icon-btn:hover {
color: var(--text-primary);
background: var(--bg-tertiary);
}
.search-expanded {
/* Search bar (replaces nav-left content when expanded) */
.search-bar {
display: flex;
align-items: center;
gap: 8px;
padding: 6px 12px;
padding: 5px 10px;
background: var(--bg-secondary);
border: 1px solid var(--bg-tertiary);
border-radius: 8px;
min-width: 280px;
flex: 1;
min-width: 0;
}
:global(.search-icon-inline) {
@@ -520,19 +637,19 @@
outline: none;
color: var(--text-primary);
font-size: 13px;
min-width: 0;
}
.search-input-inline::placeholder {
color: var(--text-muted);
}
.search-clear-btn,
.search-close-btn {
.search-clear-btn {
display: flex;
align-items: center;
justify-content: center;
width: 20px;
height: 20px;
width: 22px;
height: 22px;
border: none;
background: none;
color: var(--text-muted);
@@ -542,19 +659,98 @@
flex-shrink: 0;
}
.search-clear-btn:hover,
.search-close-btn:hover {
.search-clear-btn:hover {
color: var(--text-primary);
background: var(--bg-tertiary);
}
/* Toolbar buttons */
.toolbar-btn {
display: flex;
align-items: center;
gap: 5px;
height: 30px;
padding: 0 8px;
border: 1px solid transparent;
background: none;
color: var(--text-muted);
cursor: pointer;
border-radius: 6px;
font-size: 12px;
transition: all 150ms ease;
white-space: nowrap;
}
.toolbar-btn:hover {
color: var(--text-primary);
background: var(--bg-tertiary);
}
.toolbar-btn.active {
color: var(--accent-primary);
background: color-mix(in srgb, var(--accent-primary) 12%, transparent);
border-color: color-mix(in srgb, var(--accent-primary) 30%, transparent);
}
.toolbar-label {
display: none;
}
@media (min-width: 600px) {
.toolbar-label {
display: inline;
}
}
/* Sort dropdown */
.sort-dropdown {
position: relative;
}
.sort-menu {
position: absolute;
top: 100%;
right: 0;
margin-top: 4px;
background: var(--bg-secondary);
border: 1px solid var(--border-subtle);
border-radius: 8px;
padding: 4px;
min-width: 160px;
box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
z-index: 10;
}
.sort-option {
display: block;
width: 100%;
padding: 7px 12px;
border: none;
background: none;
color: var(--text-secondary);
font-size: 13px;
text-align: left;
cursor: pointer;
border-radius: 5px;
transition: all 100ms ease;
}
.sort-option:hover {
background: var(--bg-tertiary);
color: var(--text-primary);
}
.sort-option.active {
color: var(--accent-primary);
font-weight: 600;
}
/* Content */
.content {
min-height: 200px;
}
.loading,
.error,
.empty {
.status-message {
display: flex;
flex-direction: column;
align-items: center;
@@ -564,9 +760,7 @@
text-align: center;
}
.loading p,
.error p,
.empty p {
.status-message p {
margin: 16px 0 0 0;
}
+17
View File
@@ -98,6 +98,23 @@
"showMore": "Mehr anzeigen",
"showLess": "Weniger anzeigen"
},
"labelReleases": {
"albumCount": "{count} Alben",
"searchPlaceholder": "Alben suchen...",
"searchAlbums": "Alben suchen",
"results": "Ergebnisse",
"showingOf": "{shown} von {total} angezeigt",
"noAlbums": "Keine Alben fur dieses Label gefunden",
"noResults": "Keine passenden Alben",
"loadingMore": "Weitere Alben werden geladen...",
"filterHiRes": "Nur Hi-Res",
"sort": "Sortieren",
"sortNewest": "Neueste",
"sortOldest": "Alteste",
"sortTitleAZ": "Titel A-Z",
"sortTitleZA": "Titel Z-A",
"sortArtistAZ": "Kunstler A-Z"
},
"library": {
"title": "Lokale Bibliothek",
"browse": "Bibliothek durchsuchen",
+17
View File
@@ -101,6 +101,23 @@
"showMore": "Show more",
"showLess": "Show less"
},
"labelReleases": {
"albumCount": "{count} albums",
"searchPlaceholder": "Search albums...",
"searchAlbums": "Search albums",
"results": "results",
"showingOf": "Showing {shown} of {total}",
"noAlbums": "No albums found for this label",
"noResults": "No matching albums",
"loadingMore": "Loading more albums...",
"filterHiRes": "Hi-Res only",
"sort": "Sort",
"sortNewest": "Newest",
"sortOldest": "Oldest",
"sortTitleAZ": "Title A-Z",
"sortTitleZA": "Title Z-A",
"sortArtistAZ": "Artist A-Z"
},
"library": {
"title": "Local Library",
"browse": "Browse Library",
+17
View File
@@ -101,6 +101,23 @@
"showMore": "Ver más",
"showLess": "Ver menos"
},
"labelReleases": {
"albumCount": "{count} albums",
"searchPlaceholder": "Buscar albums...",
"searchAlbums": "Buscar albums",
"results": "resultados",
"showingOf": "Mostrando {shown} de {total}",
"noAlbums": "No se encontraron albums para este sello",
"noResults": "No hay albums que coincidan",
"loadingMore": "Cargando mas albums...",
"filterHiRes": "Solo Hi-Res",
"sort": "Ordenar",
"sortNewest": "Mas recientes",
"sortOldest": "Mas antiguos",
"sortTitleAZ": "Titulo A-Z",
"sortTitleZA": "Titulo Z-A",
"sortArtistAZ": "Artista A-Z"
},
"library": {
"title": "Biblioteca Local",
"browse": "Explorar Biblioteca",
+17
View File
@@ -98,6 +98,23 @@
"showMore": "Voir plus",
"showLess": "Voir moins"
},
"labelReleases": {
"albumCount": "{count} albums",
"searchPlaceholder": "Rechercher des albums...",
"searchAlbums": "Rechercher des albums",
"results": "resultats",
"showingOf": "{shown} sur {total} affiches",
"noAlbums": "Aucun album trouve pour ce label",
"noResults": "Aucun album correspondant",
"loadingMore": "Chargement d'autres albums...",
"filterHiRes": "Hi-Res uniquement",
"sort": "Trier",
"sortNewest": "Plus recents",
"sortOldest": "Plus anciens",
"sortTitleAZ": "Titre A-Z",
"sortTitleZA": "Titre Z-A",
"sortArtistAZ": "Artiste A-Z"
},
"library": {
"title": "Bibliothèque locale",
"browse": "Parcourir la bibliothèque",