feat(home): add Qobuz discover playlists section with tag filter
- Add backend endpoint for /discover/playlists API - Add PlaylistTagFilter dropdown component for filtering by genre - Add QobuzPlaylistCard with CSS blur background effect (color-thief style) - Add HorizontalScrollRow header snippet for custom headers with scroll controls - Add session cache store for caching API responses - Add i18n keys for playlist filter and discover section cc
This commit is contained in:
1 parent
9341e9ee19
commit
deaffa183d
15 files changed
+1608
-63
No files matched your search
@@ -3,11 +3,12 @@
|
||||
import type { Snippet } from 'svelte';
|
||||
|
||||
interface Props {
|
||||
title: string;
|
||||
title?: string;
|
||||
header?: Snippet;
|
||||
children: Snippet;
|
||||
}
|
||||
|
||||
let { title, children }: Props = $props();
|
||||
let { title, header, children }: Props = $props();
|
||||
|
||||
let scrollContainer: HTMLDivElement;
|
||||
|
||||
@@ -25,21 +26,31 @@
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
const hasHeader = $derived(!!title || !!header);
|
||||
</script>
|
||||
|
||||
<div class="scroll-row">
|
||||
<!-- Section Header -->
|
||||
<div class="header">
|
||||
<h2 class="title">{title}</h2>
|
||||
<div class="nav-buttons">
|
||||
<button onclick={() => scroll('left')} class="nav-btn">
|
||||
<ChevronLeft size={24} />
|
||||
</button>
|
||||
<button onclick={() => scroll('right')} class="nav-btn">
|
||||
<ChevronRight size={24} />
|
||||
</button>
|
||||
{#if hasHeader}
|
||||
<div class="header">
|
||||
{#if header}
|
||||
<div class="header-content">
|
||||
{@render header()}
|
||||
</div>
|
||||
{:else if title}
|
||||
<h2 class="title">{title}</h2>
|
||||
{/if}
|
||||
<div class="nav-buttons">
|
||||
<button onclick={() => scroll('left')} class="nav-btn">
|
||||
<ChevronLeft size={24} />
|
||||
</button>
|
||||
<button onclick={() => scroll('right')} class="nav-btn">
|
||||
<ChevronRight size={24} />
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{/if}
|
||||
|
||||
<!-- Horizontal Scroll Container -->
|
||||
<div class="scroll-container hide-scrollbar" bind:this={scrollContainer}>
|
||||
@@ -61,6 +72,14 @@
|
||||
margin-bottom: 16px;
|
||||
}
|
||||
|
||||
.header-content {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 16px;
|
||||
flex: 1;
|
||||
min-width: 0;
|
||||
}
|
||||
|
||||
.title {
|
||||
font-size: 22px;
|
||||
font-weight: 600;
|
||||
@@ -71,6 +90,7 @@
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
.nav-btn {
|
||||
|
||||
@@ -0,0 +1,215 @@
|
||||
<script lang="ts">
|
||||
import { tick } from 'svelte';
|
||||
import { ChevronDown, Check } from 'lucide-svelte';
|
||||
import { t } from '$lib/i18n';
|
||||
import type { PlaylistTag } from '$lib/types';
|
||||
|
||||
interface Props {
|
||||
tags: PlaylistTag[];
|
||||
selectedTag: string | null;
|
||||
onTagChange: (tag: string | null) => void;
|
||||
}
|
||||
|
||||
let { tags, selectedTag, onTagChange }: Props = $props();
|
||||
|
||||
let isOpen = $state(false);
|
||||
let buttonEl: HTMLButtonElement | null = $state(null);
|
||||
let menuEl: HTMLDivElement | null = $state(null);
|
||||
let menuStyle = $state('');
|
||||
|
||||
const selectedTagName = $derived.by(() => {
|
||||
if (!selectedTag) return null;
|
||||
const tag = tags.find(t => t.slug === selectedTag);
|
||||
return tag?.name ?? null;
|
||||
});
|
||||
|
||||
function portal(node: HTMLElement) {
|
||||
document.body.appendChild(node);
|
||||
return {
|
||||
destroy() {
|
||||
if (node.parentNode) node.parentNode.removeChild(node);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
async function positionMenu() {
|
||||
await tick();
|
||||
if (!buttonEl || !menuEl) return;
|
||||
const btnRect = buttonEl.getBoundingClientRect();
|
||||
const menuRect = menuEl.getBoundingClientRect();
|
||||
|
||||
let left = btnRect.left;
|
||||
let top = btnRect.bottom + 4;
|
||||
|
||||
// Keep within viewport
|
||||
if (left + menuRect.width > window.innerWidth - 8) {
|
||||
left = window.innerWidth - menuRect.width - 8;
|
||||
}
|
||||
if (top + menuRect.height > window.innerHeight - 8) {
|
||||
top = btnRect.top - menuRect.height - 4;
|
||||
}
|
||||
|
||||
menuStyle = `left: ${left}px; top: ${top}px;`;
|
||||
}
|
||||
|
||||
function toggleMenu() {
|
||||
isOpen = !isOpen;
|
||||
if (isOpen) positionMenu();
|
||||
}
|
||||
|
||||
function selectTag(slug: string | null) {
|
||||
onTagChange(slug);
|
||||
isOpen = false;
|
||||
}
|
||||
|
||||
function handleClickOutside(event: MouseEvent) {
|
||||
if (isOpen && menuEl && !menuEl.contains(event.target as Node) &&
|
||||
buttonEl && !buttonEl.contains(event.target as Node)) {
|
||||
isOpen = false;
|
||||
}
|
||||
}
|
||||
|
||||
$effect(() => {
|
||||
if (isOpen) {
|
||||
document.addEventListener('click', handleClickOutside);
|
||||
return () => document.removeEventListener('click', handleClickOutside);
|
||||
}
|
||||
});
|
||||
</script>
|
||||
|
||||
<div class="tag-filter-wrapper">
|
||||
<button
|
||||
class="tag-filter-btn"
|
||||
class:active={selectedTag !== null}
|
||||
bind:this={buttonEl}
|
||||
onclick={toggleMenu}
|
||||
type="button"
|
||||
>
|
||||
<span class="filter-label">
|
||||
{#if selectedTagName}
|
||||
{selectedTagName}
|
||||
{:else}
|
||||
{$t('home.allTags')}
|
||||
{/if}
|
||||
</span>
|
||||
<ChevronDown size={14} class={isOpen ? 'rotated' : ''} />
|
||||
</button>
|
||||
|
||||
{#if isOpen}
|
||||
<div class="tag-menu" bind:this={menuEl} style={menuStyle} use:portal>
|
||||
<button
|
||||
class="tag-item"
|
||||
class:selected={selectedTag === null}
|
||||
onclick={() => selectTag(null)}
|
||||
>
|
||||
<span>{$t('home.allTags')}</span>
|
||||
{#if selectedTag === null}
|
||||
<Check size={14} />
|
||||
{/if}
|
||||
</button>
|
||||
|
||||
{#each tags as tag (tag.id)}
|
||||
<button
|
||||
class="tag-item"
|
||||
class:selected={selectedTag === tag.slug}
|
||||
onclick={() => selectTag(tag.slug)}
|
||||
>
|
||||
<span>{tag.name}</span>
|
||||
{#if selectedTag === tag.slug}
|
||||
<Check size={14} />
|
||||
{/if}
|
||||
</button>
|
||||
{/each}
|
||||
</div>
|
||||
{/if}
|
||||
</div>
|
||||
|
||||
<style>
|
||||
.tag-filter-wrapper {
|
||||
position: relative;
|
||||
}
|
||||
|
||||
.tag-filter-btn {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 6px;
|
||||
padding: 6px 12px;
|
||||
border: 1px solid var(--border-subtle);
|
||||
border-radius: 6px;
|
||||
background: transparent;
|
||||
color: var(--text-secondary);
|
||||
font-size: 12px;
|
||||
cursor: pointer;
|
||||
transition: all 150ms ease;
|
||||
}
|
||||
|
||||
.tag-filter-btn:hover {
|
||||
background: var(--bg-hover);
|
||||
color: var(--text-primary);
|
||||
border-color: var(--border-subtle);
|
||||
}
|
||||
|
||||
.tag-filter-btn.active {
|
||||
background: var(--accent-primary);
|
||||
color: white;
|
||||
border-color: var(--accent-primary);
|
||||
}
|
||||
|
||||
.tag-filter-btn.active:hover {
|
||||
background: var(--accent-hover);
|
||||
border-color: var(--accent-hover);
|
||||
}
|
||||
|
||||
.filter-label {
|
||||
max-width: 120px;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.tag-filter-btn :global(.rotated) {
|
||||
transform: rotate(180deg);
|
||||
}
|
||||
|
||||
.tag-menu {
|
||||
position: fixed;
|
||||
z-index: 30000;
|
||||
min-width: 140px;
|
||||
max-height: 280px;
|
||||
overflow-y: auto;
|
||||
background-color: var(--bg-tertiary);
|
||||
border: 1px solid var(--border-subtle);
|
||||
border-radius: 8px;
|
||||
padding: 4px 0;
|
||||
box-shadow: 0 8px 24px rgba(0, 0, 0, 0.3);
|
||||
}
|
||||
|
||||
.tag-item {
|
||||
width: 100%;
|
||||
padding: 8px 12px;
|
||||
background: none;
|
||||
border: none;
|
||||
color: var(--text-secondary);
|
||||
text-align: left;
|
||||
font-size: 12px;
|
||||
cursor: pointer;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
gap: 8px;
|
||||
transition: background-color 150ms ease, color 150ms ease;
|
||||
}
|
||||
|
||||
.tag-item:hover {
|
||||
background-color: var(--bg-hover);
|
||||
color: var(--text-primary);
|
||||
}
|
||||
|
||||
.tag-item.selected {
|
||||
color: var(--accent-primary);
|
||||
}
|
||||
|
||||
.tag-item.selected:hover {
|
||||
color: var(--accent-primary);
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,473 @@
|
||||
<script lang="ts">
|
||||
import { tick } from 'svelte';
|
||||
import { Play, ListMusic, Plus, MoreHorizontal, ListPlus, Library, Share2 } from 'lucide-svelte';
|
||||
import { t } from '$lib/i18n';
|
||||
|
||||
interface Props {
|
||||
playlistId: number;
|
||||
name: string;
|
||||
owner: string;
|
||||
image?: string;
|
||||
trackCount?: number;
|
||||
duration?: number;
|
||||
genre?: string;
|
||||
onclick?: () => void;
|
||||
onPlay?: () => void;
|
||||
onPlayNext?: () => void;
|
||||
onPlayLater?: () => void;
|
||||
onCopyToLibrary?: () => void;
|
||||
onShareQobuz?: () => void;
|
||||
}
|
||||
|
||||
let {
|
||||
playlistId,
|
||||
name,
|
||||
owner,
|
||||
image,
|
||||
trackCount,
|
||||
duration,
|
||||
genre,
|
||||
onclick,
|
||||
onPlay,
|
||||
onPlayNext,
|
||||
onPlayLater,
|
||||
onCopyToLibrary,
|
||||
onShareQobuz
|
||||
}: Props = $props();
|
||||
|
||||
let imageError = $state(false);
|
||||
let imageLoaded = $state(false);
|
||||
let menuOpen = $state(false);
|
||||
let menuTriggerRef: HTMLButtonElement | null = $state(null);
|
||||
let menuEl: HTMLDivElement | null = $state(null);
|
||||
let menuStyle = $state('');
|
||||
|
||||
const cardSize = 180;
|
||||
|
||||
function handleImageError() {
|
||||
imageError = true;
|
||||
}
|
||||
|
||||
function handleImageLoad() {
|
||||
imageLoaded = true;
|
||||
}
|
||||
|
||||
function handlePlay(event: MouseEvent) {
|
||||
event.stopPropagation();
|
||||
onPlay?.();
|
||||
}
|
||||
|
||||
function handleCopyToLibrary(event: MouseEvent) {
|
||||
event.stopPropagation();
|
||||
onCopyToLibrary?.();
|
||||
}
|
||||
|
||||
function handleCardClick(event: MouseEvent) {
|
||||
const target = event.target;
|
||||
if (target instanceof HTMLElement && target.closest('.action-buttons')) return;
|
||||
onclick?.();
|
||||
}
|
||||
|
||||
function formatDuration(seconds: number): string {
|
||||
const hours = Math.floor(seconds / 3600);
|
||||
const minutes = Math.floor((seconds % 3600) / 60);
|
||||
if (hours > 0) {
|
||||
return `${hours}h ${minutes}m`;
|
||||
}
|
||||
return `${minutes}m`;
|
||||
}
|
||||
|
||||
// Portal for menu
|
||||
function portal(node: HTMLElement) {
|
||||
document.body.appendChild(node);
|
||||
return {
|
||||
destroy() {
|
||||
if (node.parentNode) node.parentNode.removeChild(node);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
async function positionMenu() {
|
||||
await tick();
|
||||
if (!menuTriggerRef || !menuEl) return;
|
||||
const triggerRect = menuTriggerRef.getBoundingClientRect();
|
||||
const menuRect = menuEl.getBoundingClientRect();
|
||||
let left = triggerRect.right - menuRect.width;
|
||||
let top = triggerRect.bottom + 8;
|
||||
if (left < 8) left = 8;
|
||||
if (left + menuRect.width > window.innerWidth - 8) {
|
||||
left = window.innerWidth - menuRect.width - 8;
|
||||
}
|
||||
if (top + menuRect.height > window.innerHeight - 8) {
|
||||
top = triggerRect.top - menuRect.height - 8;
|
||||
}
|
||||
menuStyle = `left: ${left}px; top: ${top}px;`;
|
||||
}
|
||||
|
||||
function toggleMenu(event: MouseEvent) {
|
||||
event.stopPropagation();
|
||||
menuOpen = !menuOpen;
|
||||
if (menuOpen) positionMenu();
|
||||
}
|
||||
|
||||
function closeMenu() {
|
||||
menuOpen = false;
|
||||
}
|
||||
|
||||
function handleClickOutside(event: MouseEvent) {
|
||||
if (menuOpen && menuEl && !menuEl.contains(event.target as Node) &&
|
||||
menuTriggerRef && !menuTriggerRef.contains(event.target as Node)) {
|
||||
menuOpen = false;
|
||||
}
|
||||
}
|
||||
|
||||
$effect(() => {
|
||||
if (menuOpen) {
|
||||
document.addEventListener('click', handleClickOutside);
|
||||
return () => document.removeEventListener('click', handleClickOutside);
|
||||
}
|
||||
});
|
||||
|
||||
const hasOverlay = $derived(!!(onPlay || onCopyToLibrary || genre || trackCount || duration));
|
||||
</script>
|
||||
|
||||
<div
|
||||
class="playlist-card"
|
||||
class:menu-open={menuOpen}
|
||||
style="width: {cardSize}px"
|
||||
onclick={handleCardClick}
|
||||
role="button"
|
||||
tabindex="0"
|
||||
onkeydown={(e) => e.key === 'Enter' && onclick?.()}
|
||||
>
|
||||
<!-- Artwork Container (Square) -->
|
||||
<div
|
||||
class="artwork-container"
|
||||
style="width: {cardSize}px; height: {cardSize}px;"
|
||||
>
|
||||
<!-- Blurred background image for color effect -->
|
||||
{#if !imageError && image}
|
||||
<div
|
||||
class="artwork-bg"
|
||||
style="background-image: url({image});"
|
||||
></div>
|
||||
{/if}
|
||||
|
||||
<!-- Placeholder -->
|
||||
<div class="artwork-placeholder">
|
||||
<ListMusic size={48} />
|
||||
</div>
|
||||
|
||||
<!-- Main Image (contain) -->
|
||||
{#if !imageError && image}
|
||||
<img
|
||||
src={image}
|
||||
alt={name}
|
||||
class="artwork-main"
|
||||
loading="lazy"
|
||||
decoding="async"
|
||||
onerror={handleImageError}
|
||||
onload={handleImageLoad}
|
||||
/>
|
||||
{/if}
|
||||
|
||||
<!-- Action Overlay -->
|
||||
{#if hasOverlay}
|
||||
<div class="action-overlay">
|
||||
<!-- Overlay Info (top) -->
|
||||
<div class="overlay-info">
|
||||
{#if genre}
|
||||
<span class="overlay-genre">{genre}</span>
|
||||
{/if}
|
||||
<div class="overlay-meta">
|
||||
{#if trackCount}
|
||||
<span>{trackCount} {$t('playlist.tracks')}</span>
|
||||
{/if}
|
||||
{#if duration}
|
||||
<span>{formatDuration(duration)}</span>
|
||||
{/if}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Action Buttons (bottom) -->
|
||||
<div class="action-buttons">
|
||||
{#if onCopyToLibrary}
|
||||
<button
|
||||
class="overlay-btn overlay-btn--minor"
|
||||
type="button"
|
||||
onclick={handleCopyToLibrary}
|
||||
title={$t('playlist.copyToLibrary')}
|
||||
>
|
||||
<Plus size={18} />
|
||||
</button>
|
||||
{:else}
|
||||
<div class="overlay-btn--spacer"></div>
|
||||
{/if}
|
||||
|
||||
{#if onPlay}
|
||||
<button class="overlay-btn" type="button" onclick={handlePlay} title={$t('actions.play')}>
|
||||
<Play size={18} fill="white" color="white" />
|
||||
</button>
|
||||
{/if}
|
||||
|
||||
<button
|
||||
class="overlay-btn overlay-btn--minor"
|
||||
type="button"
|
||||
bind:this={menuTriggerRef}
|
||||
onclick={toggleMenu}
|
||||
title={$t('actions.moreOptions')}
|
||||
>
|
||||
<MoreHorizontal size={18} />
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
{/if}
|
||||
</div>
|
||||
|
||||
<!-- Text Info -->
|
||||
<div class="info">
|
||||
<div class="title" title={name}>{name}</div>
|
||||
<div class="owner">{owner}</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Context Menu Portal -->
|
||||
{#if menuOpen}
|
||||
<div class="playlist-menu" bind:this={menuEl} style={menuStyle} use:portal>
|
||||
{#if onPlayNext}
|
||||
<button class="menu-item" onclick={() => { onPlayNext(); closeMenu(); }}>
|
||||
<ListPlus size={14} /> <span>{$t('player.playNext')}</span>
|
||||
</button>
|
||||
{/if}
|
||||
{#if onPlayLater}
|
||||
<button class="menu-item" onclick={() => { onPlayLater(); closeMenu(); }}>
|
||||
<ListMusic size={14} /> <span>{$t('player.addToQueue')}</span>
|
||||
</button>
|
||||
{/if}
|
||||
{#if (onPlayNext || onPlayLater) && (onCopyToLibrary || onShareQobuz)}
|
||||
<div class="menu-separator"></div>
|
||||
{/if}
|
||||
{#if onCopyToLibrary}
|
||||
<button class="menu-item" onclick={() => { onCopyToLibrary(); closeMenu(); }}>
|
||||
<Library size={14} /> <span>{$t('playlist.copyToLibrary')}</span>
|
||||
</button>
|
||||
{/if}
|
||||
{#if onCopyToLibrary && onShareQobuz}
|
||||
<div class="menu-separator"></div>
|
||||
{/if}
|
||||
{#if onShareQobuz}
|
||||
<button class="menu-item" onclick={() => { onShareQobuz(); closeMenu(); }}>
|
||||
<Share2 size={14} /> <span>{$t('actions.shareQobuz')}</span>
|
||||
</button>
|
||||
{/if}
|
||||
</div>
|
||||
{/if}
|
||||
|
||||
<style>
|
||||
.playlist-card {
|
||||
flex-shrink: 0;
|
||||
cursor: pointer;
|
||||
transition: transform 150ms ease;
|
||||
}
|
||||
|
||||
.artwork-container {
|
||||
position: relative;
|
||||
margin-bottom: 8px;
|
||||
border-radius: 8px;
|
||||
overflow: hidden;
|
||||
background: var(--bg-tertiary);
|
||||
}
|
||||
|
||||
/* Blurred background - simulates dominant color */
|
||||
.artwork-bg {
|
||||
position: absolute;
|
||||
inset: -20px;
|
||||
background-size: cover;
|
||||
background-position: center;
|
||||
filter: blur(30px) saturate(1.5);
|
||||
transform: scale(1.2);
|
||||
z-index: 0;
|
||||
}
|
||||
|
||||
/* Darken overlay on blurred bg */
|
||||
.artwork-bg::after {
|
||||
content: '';
|
||||
position: absolute;
|
||||
inset: 0;
|
||||
background: rgba(0, 0, 0, 0.25);
|
||||
}
|
||||
|
||||
.artwork-main {
|
||||
position: absolute;
|
||||
inset: 0;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
object-fit: contain;
|
||||
border-radius: inherit;
|
||||
z-index: 1;
|
||||
}
|
||||
|
||||
.artwork-placeholder {
|
||||
position: absolute;
|
||||
inset: 0;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
color: var(--text-muted);
|
||||
z-index: 0;
|
||||
}
|
||||
|
||||
/* Hide placeholder when image exists */
|
||||
.artwork-container:has(.artwork-bg) .artwork-placeholder {
|
||||
display: none;
|
||||
}
|
||||
|
||||
.action-overlay {
|
||||
position: absolute;
|
||||
inset: 0;
|
||||
background: linear-gradient(180deg, rgba(0,0,0,0.7) 0%, transparent 40%, transparent 60%, rgba(0,0,0,0.7) 100%);
|
||||
opacity: 0;
|
||||
transition: opacity 150ms ease;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
justify-content: space-between;
|
||||
padding: 8px 12px 12px;
|
||||
border-radius: inherit;
|
||||
z-index: 2;
|
||||
}
|
||||
|
||||
.playlist-card:hover .action-overlay,
|
||||
.playlist-card.menu-open .action-overlay {
|
||||
opacity: 1;
|
||||
}
|
||||
|
||||
.overlay-info {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 4px;
|
||||
}
|
||||
|
||||
.overlay-genre {
|
||||
font-size: 14px;
|
||||
font-weight: 600;
|
||||
color: white;
|
||||
text-shadow: 0 1px 3px rgba(0, 0, 0, 0.8);
|
||||
word-wrap: break-word;
|
||||
overflow-wrap: break-word;
|
||||
}
|
||||
|
||||
.overlay-meta {
|
||||
display: flex;
|
||||
gap: 8px;
|
||||
font-size: 12px;
|
||||
font-weight: 400;
|
||||
color: rgba(255, 255, 255, 0.85);
|
||||
text-shadow: 0 1px 3px rgba(0, 0, 0, 0.8);
|
||||
}
|
||||
|
||||
.overlay-meta span:not(:last-child)::after {
|
||||
content: '\2022';
|
||||
margin-left: 8px;
|
||||
opacity: 0.6;
|
||||
}
|
||||
|
||||
.action-buttons {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
gap: 12px;
|
||||
}
|
||||
|
||||
.overlay-btn {
|
||||
width: 38px;
|
||||
height: 38px;
|
||||
border-radius: 50%;
|
||||
border: none;
|
||||
background: transparent;
|
||||
color: white;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
cursor: pointer;
|
||||
box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.85), 0 0 1px rgba(0, 0, 0, 0.3);
|
||||
transition: transform 150ms ease, background-color 150ms ease, box-shadow 150ms ease;
|
||||
}
|
||||
|
||||
.overlay-btn:hover {
|
||||
background-color: rgba(0, 0, 0, 0.3);
|
||||
box-shadow: inset 0 0 0 1px var(--accent-primary), 0 0 4px rgba(0, 0, 0, 0.5);
|
||||
}
|
||||
|
||||
.overlay-btn--minor {
|
||||
width: 30px;
|
||||
height: 30px;
|
||||
}
|
||||
|
||||
.overlay-btn--spacer {
|
||||
width: 30px;
|
||||
height: 30px;
|
||||
visibility: hidden;
|
||||
}
|
||||
|
||||
.info {
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.title {
|
||||
font-size: 14px;
|
||||
font-weight: 500;
|
||||
color: var(--text-primary);
|
||||
line-height: 1.4;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
margin-bottom: 2px;
|
||||
}
|
||||
|
||||
.owner {
|
||||
font-size: 12px;
|
||||
font-weight: 400;
|
||||
color: var(--text-muted);
|
||||
line-height: 1.4;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
/* Context Menu */
|
||||
.playlist-menu {
|
||||
position: fixed;
|
||||
z-index: 30000;
|
||||
min-width: 160px;
|
||||
background-color: var(--bg-tertiary);
|
||||
border-radius: 8px;
|
||||
padding: 2px 0;
|
||||
box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
|
||||
}
|
||||
|
||||
.menu-item {
|
||||
width: 100%;
|
||||
padding: 8px 12px;
|
||||
background: none;
|
||||
border: none;
|
||||
color: var(--text-secondary);
|
||||
text-align: left;
|
||||
font-size: 12px;
|
||||
cursor: pointer;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
transition: background-color 150ms ease, color 150ms ease;
|
||||
}
|
||||
|
||||
.menu-item:hover {
|
||||
background-color: var(--bg-hover);
|
||||
color: var(--text-primary);
|
||||
}
|
||||
|
||||
.menu-separator {
|
||||
height: 1px;
|
||||
background-color: var(--bg-hover);
|
||||
margin: 4px 0;
|
||||
}
|
||||
</style>
|
||||
@@ -5,9 +5,11 @@
|
||||
import { t } from '$lib/i18n';
|
||||
import HorizontalScrollRow from '../HorizontalScrollRow.svelte';
|
||||
import AlbumCard from '../AlbumCard.svelte';
|
||||
import QobuzPlaylistCard from '../QobuzPlaylistCard.svelte';
|
||||
import TrackRow from '../TrackRow.svelte';
|
||||
import HomeSettingsModal from '../HomeSettingsModal.svelte';
|
||||
import GenreFilterButton from '../GenreFilterButton.svelte';
|
||||
import PlaylistTagFilter from '../PlaylistTagFilter.svelte';
|
||||
import { formatDuration, formatQuality, getQobuzImage } from '$lib/adapters/qobuzAdapters';
|
||||
import { isBlacklisted as isArtistBlacklisted } from '$lib/stores/artistBlacklistStore';
|
||||
import {
|
||||
@@ -24,7 +26,25 @@
|
||||
hasActiveFilter as hasGenreFilter
|
||||
} from '$lib/stores/genreFilterStore';
|
||||
import { setPlaybackContext } from '$lib/stores/playbackContextStore';
|
||||
import type { QobuzAlbum, QobuzArtist, QobuzTrack, DisplayTrack } from '$lib/types';
|
||||
import {
|
||||
getCachedArtist,
|
||||
setCachedArtist,
|
||||
getCachedAlbum,
|
||||
setCachedAlbum,
|
||||
getCachedTrack,
|
||||
setCachedTrack
|
||||
} from '$lib/stores/sessionCacheStore';
|
||||
import type {
|
||||
QobuzAlbum,
|
||||
QobuzArtist,
|
||||
QobuzTrack,
|
||||
DisplayTrack,
|
||||
DiscoverResponse,
|
||||
DiscoverPlaylist,
|
||||
DiscoverPlaylistsResponse,
|
||||
DiscoverAlbum,
|
||||
PlaylistTag
|
||||
} from '$lib/types';
|
||||
|
||||
interface TopArtistSeed {
|
||||
artistId: number;
|
||||
@@ -85,6 +105,12 @@
|
||||
onTrackReDownload?: (track: DisplayTrack) => void;
|
||||
checkTrackDownloaded?: (trackId: number) => boolean;
|
||||
getTrackOfflineCacheStatus?: (trackId: number) => { status: string; progress: number };
|
||||
onPlaylistClick?: (playlistId: number) => void;
|
||||
onPlaylistPlay?: (playlistId: number) => void;
|
||||
onPlaylistPlayNext?: (playlistId: number) => void;
|
||||
onPlaylistPlayLater?: (playlistId: number) => void;
|
||||
onPlaylistCopyToLibrary?: (playlistId: number) => void;
|
||||
onPlaylistShareQobuz?: (playlistId: number) => void;
|
||||
activeTrackId?: number | null;
|
||||
isPlaybackActive?: boolean;
|
||||
sidebarExpanded?: boolean;
|
||||
@@ -119,6 +145,12 @@
|
||||
onTrackReDownload,
|
||||
checkTrackDownloaded,
|
||||
getTrackOfflineCacheStatus,
|
||||
onPlaylistClick,
|
||||
onPlaylistPlay,
|
||||
onPlaylistPlayNext,
|
||||
onPlaylistPlayLater,
|
||||
onPlaylistCopyToLibrary,
|
||||
onPlaylistShareQobuz,
|
||||
activeTrackId = null,
|
||||
isPlaybackActive = false,
|
||||
sidebarExpanded = true
|
||||
@@ -149,13 +181,28 @@
|
||||
homeSettings.sections.filter(s => s.visible).map(s => s.id)
|
||||
);
|
||||
|
||||
// Deferred rendering: only render first N sections immediately, defer the rest
|
||||
const IMMEDIATE_SECTIONS = 3;
|
||||
let deferredSectionsReady = $state(false);
|
||||
|
||||
// Sections to render immediately vs deferred
|
||||
const immediateSections = $derived(visibleSections.slice(0, IMMEDIATE_SECTIONS));
|
||||
const deferredSections = $derived(visibleSections.slice(IMMEDIATE_SECTIONS));
|
||||
|
||||
// All sections ready to render
|
||||
const renderableSections = $derived(
|
||||
deferredSectionsReady ? visibleSections : immediateSections
|
||||
);
|
||||
|
||||
const LIMITS = {
|
||||
recentAlbums: 20,
|
||||
continueTracks: 10,
|
||||
topArtists: 20,
|
||||
topArtists: 8,
|
||||
favoriteAlbums: 12,
|
||||
favoriteTracks: 10,
|
||||
featuredAlbums: 12
|
||||
featuredAlbums: 12,
|
||||
qobuzPlaylists: 15,
|
||||
essentialDiscography: 15
|
||||
};
|
||||
|
||||
let homeLimits = $state(getSettings().limits);
|
||||
@@ -173,6 +220,8 @@
|
||||
let loadingContinueTracks = $state(true);
|
||||
let loadingTopArtists = $state(true);
|
||||
let loadingFavoriteAlbums = $state(true);
|
||||
let loadingQobuzPlaylists = $state(true);
|
||||
let loadingEssentialDiscography = $state(true);
|
||||
|
||||
// Track loading completion for overlay
|
||||
let totalVisibleSections = $state(0);
|
||||
@@ -191,6 +240,12 @@
|
||||
let topArtists = $state<ArtistCardData[]>([]);
|
||||
let favoriteAlbums = $state<AlbumCardData[]>([]);
|
||||
|
||||
// Discover sections
|
||||
let qobuzPlaylists = $state<DiscoverPlaylist[]>([]);
|
||||
let essentialDiscography = $state<DiscoverAlbum[]>([]);
|
||||
let playlistTags = $state<PlaylistTag[]>([]);
|
||||
let selectedTagSlug = $state<string | null>(null);
|
||||
|
||||
let failedArtistImages = $state<Set<number>>(new Set());
|
||||
|
||||
// Download status tracking
|
||||
@@ -211,7 +266,12 @@
|
||||
|
||||
async function loadAllAlbumDownloadStatuses(albums: AlbumCardData[]) {
|
||||
if (!checkAlbumFullyDownloaded || albums.length === 0) return;
|
||||
await Promise.all(albums.map(album => loadAlbumDownloadStatus(album.id)));
|
||||
|
||||
const BATCH_SIZE = 6;
|
||||
for (let i = 0; i < albums.length; i += BATCH_SIZE) {
|
||||
const batch = albums.slice(i, i + BATCH_SIZE);
|
||||
await Promise.all(batch.map(album => loadAlbumDownloadStatus(album.id)));
|
||||
}
|
||||
}
|
||||
|
||||
function isAlbumDownloaded(albumId: string): boolean {
|
||||
@@ -245,6 +305,8 @@
|
||||
|| continueTracks.length > 0
|
||||
|| topArtists.length > 0
|
||||
|| favoriteAlbums.length > 0
|
||||
|| qobuzPlaylists.length > 0
|
||||
|| essentialDiscography.length > 0
|
||||
);
|
||||
|
||||
// Mark a section as finished loading and check if we can hide overlay
|
||||
@@ -261,6 +323,17 @@
|
||||
isOverlayVisible = false;
|
||||
isInitializing = false;
|
||||
}, 150);
|
||||
|
||||
// Enable deferred sections after a short delay using requestIdleCallback
|
||||
if ('requestIdleCallback' in window) {
|
||||
requestIdleCallback(() => {
|
||||
deferredSectionsReady = true;
|
||||
}, { timeout: 500 });
|
||||
} else {
|
||||
setTimeout(() => {
|
||||
deferredSectionsReady = true;
|
||||
}, 300);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -288,40 +361,106 @@
|
||||
|
||||
async function fetchAlbums(ids: string[]): Promise<AlbumCardData[]> {
|
||||
if (ids.length === 0) return [];
|
||||
const results = await Promise.allSettled(
|
||||
ids.map(albumId => invoke<QobuzAlbum>('get_album', { albumId }))
|
||||
);
|
||||
|
||||
const BATCH_SIZE = 6;
|
||||
const albums: AlbumCardData[] = [];
|
||||
|
||||
// Separate cached vs uncached
|
||||
const uncachedIds: string[] = [];
|
||||
for (const id of ids) {
|
||||
const cached = getCachedAlbum(id);
|
||||
if (cached) {
|
||||
albums.push(toAlbumCard(cached));
|
||||
} else {
|
||||
uncachedIds.push(id);
|
||||
}
|
||||
}
|
||||
|
||||
// Fetch uncached in batches
|
||||
for (let i = 0; i < uncachedIds.length; i += BATCH_SIZE) {
|
||||
const batch = uncachedIds.slice(i, i + BATCH_SIZE);
|
||||
const results = await Promise.allSettled(
|
||||
batch.map(albumId => invoke<QobuzAlbum>('get_album', { albumId }))
|
||||
);
|
||||
|
||||
for (const result of results) {
|
||||
if (result.status === 'fulfilled') {
|
||||
setCachedAlbum(result.value);
|
||||
albums.push(toAlbumCard(result.value));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return results.flatMap(result => {
|
||||
if (result.status !== 'fulfilled') return [];
|
||||
return [toAlbumCard(result.value)];
|
||||
});
|
||||
return albums;
|
||||
}
|
||||
|
||||
async function fetchTracks(ids: number[]): Promise<DisplayTrack[]> {
|
||||
if (ids.length === 0) return [];
|
||||
const results = await Promise.allSettled(
|
||||
ids.map(trackId => invoke<QobuzTrack>('get_track', { trackId }))
|
||||
);
|
||||
|
||||
const BATCH_SIZE = 6;
|
||||
const tracks: DisplayTrack[] = [];
|
||||
|
||||
// Separate cached vs uncached
|
||||
const uncachedIds: number[] = [];
|
||||
for (const id of ids) {
|
||||
const cached = getCachedTrack(id);
|
||||
if (cached) {
|
||||
tracks.push(toDisplayTrack(cached));
|
||||
} else {
|
||||
uncachedIds.push(id);
|
||||
}
|
||||
}
|
||||
|
||||
// Fetch uncached in batches
|
||||
for (let i = 0; i < uncachedIds.length; i += BATCH_SIZE) {
|
||||
const batch = uncachedIds.slice(i, i + BATCH_SIZE);
|
||||
const results = await Promise.allSettled(
|
||||
batch.map(trackId => invoke<QobuzTrack>('get_track', { trackId }))
|
||||
);
|
||||
|
||||
for (const result of results) {
|
||||
if (result.status === 'fulfilled') {
|
||||
setCachedTrack(result.value);
|
||||
tracks.push(toDisplayTrack(result.value));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return results.flatMap(result => {
|
||||
if (result.status !== 'fulfilled') return [];
|
||||
return [toDisplayTrack(result.value)];
|
||||
});
|
||||
return tracks;
|
||||
}
|
||||
|
||||
// Fetch artists with limited concurrency and session cache
|
||||
async function fetchArtists(seeds: TopArtistSeed[]): Promise<ArtistCardData[]> {
|
||||
if (seeds.length === 0) return [];
|
||||
const results = await Promise.allSettled(
|
||||
seeds.map(seed => invoke<QobuzArtist>('get_artist', { artistId: seed.artistId }))
|
||||
);
|
||||
|
||||
|
||||
const BATCH_SIZE = 6; // Fetch 6 artists at a time (min visible at HD resolution)
|
||||
const artists: ArtistCardData[] = [];
|
||||
results.forEach((result, index) => {
|
||||
if (result.status !== 'fulfilled') return;
|
||||
const seed = seeds[index];
|
||||
artists.push(toArtistCard(result.value, seed.playCount));
|
||||
});
|
||||
|
||||
// Separate cached vs uncached
|
||||
const uncachedSeeds: TopArtistSeed[] = [];
|
||||
for (const seed of seeds) {
|
||||
const cached = getCachedArtist(seed.artistId);
|
||||
if (cached) {
|
||||
artists.push(toArtistCard(cached, seed.playCount));
|
||||
} else {
|
||||
uncachedSeeds.push(seed);
|
||||
}
|
||||
}
|
||||
|
||||
// Fetch uncached in batches (using basic endpoint - no albums, much faster)
|
||||
for (let i = 0; i < uncachedSeeds.length; i += BATCH_SIZE) {
|
||||
const batch = uncachedSeeds.slice(i, i + BATCH_SIZE);
|
||||
const results = await Promise.allSettled(
|
||||
batch.map(seed => invoke<QobuzArtist>('get_artist_basic', { artistId: seed.artistId }))
|
||||
);
|
||||
|
||||
results.forEach((result, index) => {
|
||||
if (result.status !== 'fulfilled') return;
|
||||
const seed = batch[index];
|
||||
setCachedArtist(result.value);
|
||||
artists.push(toArtistCard(result.value, seed.playCount));
|
||||
});
|
||||
}
|
||||
|
||||
return artists;
|
||||
}
|
||||
@@ -493,6 +632,76 @@
|
||||
);
|
||||
}
|
||||
|
||||
// Handle tag selection - fetch playlists with the new tag filter
|
||||
async function handleTagChange(slug: string | null) {
|
||||
selectedTagSlug = slug;
|
||||
loadingQobuzPlaylists = true;
|
||||
|
||||
try {
|
||||
console.log('[Home] Fetching playlists with tag:', slug);
|
||||
const response = await invoke<DiscoverPlaylistsResponse>('get_discover_playlists', {
|
||||
tag: slug,
|
||||
limit: LIMITS.qobuzPlaylists,
|
||||
offset: 0
|
||||
});
|
||||
|
||||
console.log('[Home] Response:', response);
|
||||
console.log('[Home] Playlists count:', response.items?.length);
|
||||
|
||||
if (response.items) {
|
||||
qobuzPlaylists = response.items;
|
||||
} else {
|
||||
console.warn('[Home] No playlists in response:', response);
|
||||
}
|
||||
} catch (err) {
|
||||
console.error('Failed to fetch playlists by tag:', err);
|
||||
} finally {
|
||||
loadingQobuzPlaylists = false;
|
||||
}
|
||||
}
|
||||
|
||||
async function fetchDiscoverData() {
|
||||
try {
|
||||
const response = await invoke<DiscoverResponse>('get_discover_index', { genreIds: null });
|
||||
|
||||
// Extract playlists (limited) - initial load without tag filter
|
||||
if (response.containers.playlists?.data?.items) {
|
||||
qobuzPlaylists = response.containers.playlists.data.items.slice(0, LIMITS.qobuzPlaylists);
|
||||
}
|
||||
|
||||
// Extract playlist tags
|
||||
if (response.containers.playlists_tags?.data?.items) {
|
||||
playlistTags = response.containers.playlists_tags.data.items;
|
||||
}
|
||||
|
||||
// Extract essential discography (limited)
|
||||
if (response.containers.ideal_discography?.data?.items) {
|
||||
essentialDiscography = response.containers.ideal_discography.data.items.slice(0, LIMITS.essentialDiscography);
|
||||
}
|
||||
|
||||
loadingQobuzPlaylists = false;
|
||||
loadingEssentialDiscography = false;
|
||||
|
||||
if (isSectionVisible('qobuzPlaylists')) {
|
||||
markSectionFinished();
|
||||
}
|
||||
if (isSectionVisible('essentialDiscography')) {
|
||||
markSectionFinished();
|
||||
}
|
||||
} catch (err) {
|
||||
console.error('Failed to fetch discover data:', err);
|
||||
loadingQobuzPlaylists = false;
|
||||
loadingEssentialDiscography = false;
|
||||
// Still mark sections as finished even on error
|
||||
if (isSectionVisible('qobuzPlaylists')) {
|
||||
markSectionFinished();
|
||||
}
|
||||
if (isSectionVisible('essentialDiscography')) {
|
||||
markSectionFinished();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
async function loadHome() {
|
||||
isInitializing = true;
|
||||
isOverlayVisible = true;
|
||||
@@ -507,6 +716,8 @@
|
||||
loadingContinueTracks = true;
|
||||
loadingTopArtists = true;
|
||||
loadingFavoriteAlbums = true;
|
||||
loadingQobuzPlaylists = true;
|
||||
loadingEssentialDiscography = true;
|
||||
|
||||
// Count total visible sections to know when we're done
|
||||
totalVisibleSections = 0;
|
||||
@@ -519,6 +730,8 @@
|
||||
if (isSectionVisible('continueTracks')) totalVisibleSections++;
|
||||
if (isSectionVisible('topArtists')) totalVisibleSections++;
|
||||
if (isSectionVisible('favoriteAlbums')) totalVisibleSections++;
|
||||
if (isSectionVisible('qobuzPlaylists')) totalVisibleSections++;
|
||||
if (isSectionVisible('essentialDiscography')) totalVisibleSections++;
|
||||
|
||||
// Start ML data loading FIRST (local SQLite) - this gets the seeds
|
||||
const mlPromise = invoke<HomeSeeds>('reco_get_home_ml', {
|
||||
@@ -587,6 +800,15 @@
|
||||
loadingEditorPicks = false;
|
||||
}
|
||||
|
||||
// Fetch Discover data (Qobuz Playlists + Essential Discography)
|
||||
const needsDiscoverData = isSectionVisible('qobuzPlaylists') || isSectionVisible('essentialDiscography');
|
||||
if (needsDiscoverData) {
|
||||
fetchDiscoverData();
|
||||
} else {
|
||||
loadingQobuzPlaylists = false;
|
||||
loadingEssentialDiscography = false;
|
||||
}
|
||||
|
||||
try {
|
||||
// Wait for ML seeds (local data)
|
||||
const seeds = await mlPromise;
|
||||
@@ -660,6 +882,8 @@
|
||||
loadingContinueTracks = false;
|
||||
loadingTopArtists = false;
|
||||
loadingFavoriteAlbums = false;
|
||||
loadingQobuzPlaylists = false;
|
||||
loadingEssentialDiscography = false;
|
||||
}
|
||||
}
|
||||
</script>
|
||||
@@ -711,7 +935,7 @@
|
||||
</div>
|
||||
{:else if hasContent}
|
||||
<!-- Render sections in user-defined order -->
|
||||
{#each visibleSections as sectionId (sectionId)}
|
||||
{#each renderableSections as sectionId (sectionId)}
|
||||
{#if sectionId === 'newReleases' && newReleases.length > 0}
|
||||
<HorizontalScrollRow title={$t('home.newReleases')}>
|
||||
{#snippet children()}
|
||||
@@ -872,6 +1096,83 @@
|
||||
</HorizontalScrollRow>
|
||||
{/if}
|
||||
|
||||
{#if sectionId === 'qobuzPlaylists' && qobuzPlaylists.length > 0}
|
||||
<HorizontalScrollRow>
|
||||
{#snippet header()}
|
||||
<h2 class="section-title">{$t('home.qobuzPlaylists')}</h2>
|
||||
{#if playlistTags.length > 0}
|
||||
<PlaylistTagFilter
|
||||
tags={playlistTags}
|
||||
selectedTag={selectedTagSlug}
|
||||
onTagChange={handleTagChange}
|
||||
/>
|
||||
{/if}
|
||||
{/snippet}
|
||||
{#snippet children()}
|
||||
{#if loadingQobuzPlaylists}
|
||||
<div class="loading-playlists">
|
||||
<Loader2 size={24} class="spinner" />
|
||||
</div>
|
||||
{:else}
|
||||
{#each qobuzPlaylists as playlist (playlist.id)}
|
||||
<QobuzPlaylistCard
|
||||
playlistId={playlist.id}
|
||||
name={playlist.name}
|
||||
owner={playlist.owner?.name || 'Qobuz'}
|
||||
image={playlist.image?.rectangle || playlist.image?.covers?.[0]}
|
||||
trackCount={playlist.tracks_count}
|
||||
duration={playlist.duration}
|
||||
genre={playlist.genres?.[0]?.name}
|
||||
onclick={onPlaylistClick ? () => onPlaylistClick(playlist.id) : undefined}
|
||||
onPlay={onPlaylistPlay ? () => onPlaylistPlay(playlist.id) : undefined}
|
||||
onPlayNext={onPlaylistPlayNext ? () => onPlaylistPlayNext(playlist.id) : undefined}
|
||||
onPlayLater={onPlaylistPlayLater ? () => onPlaylistPlayLater(playlist.id) : undefined}
|
||||
onCopyToLibrary={onPlaylistCopyToLibrary ? () => onPlaylistCopyToLibrary(playlist.id) : undefined}
|
||||
onShareQobuz={onPlaylistShareQobuz ? () => onPlaylistShareQobuz(playlist.id) : undefined}
|
||||
/>
|
||||
{/each}
|
||||
{/if}
|
||||
<div class="spacer"></div>
|
||||
{/snippet}
|
||||
</HorizontalScrollRow>
|
||||
{/if}
|
||||
|
||||
{#if sectionId === 'essentialDiscography' && essentialDiscography.length > 0}
|
||||
<HorizontalScrollRow title={$t('home.essentialDiscography')}>
|
||||
{#snippet children()}
|
||||
{#each essentialDiscography as album (album.id)}
|
||||
<AlbumCard
|
||||
albumId={album.id}
|
||||
artwork={album.image?.large || album.image?.small || ''}
|
||||
title={album.title}
|
||||
artist={album.artists?.[0]?.name || 'Unknown Artist'}
|
||||
genre={album.genre?.name || ''}
|
||||
releaseDate={album.dates?.original}
|
||||
size="large"
|
||||
quality={formatQuality(
|
||||
(album.audio_info?.maximum_bit_depth ?? 16) > 16,
|
||||
album.audio_info?.maximum_bit_depth,
|
||||
album.audio_info?.maximum_sampling_rate
|
||||
)}
|
||||
onPlay={onAlbumPlay ? () => onAlbumPlay(album.id) : undefined}
|
||||
onPlayNext={onAlbumPlayNext ? () => onAlbumPlayNext(album.id) : undefined}
|
||||
onPlayLater={onAlbumPlayLater ? () => onAlbumPlayLater(album.id) : undefined}
|
||||
onAddAlbumToPlaylist={onAddAlbumToPlaylist ? () => onAddAlbumToPlaylist(album.id) : undefined}
|
||||
onShareQobuz={onAlbumShareQobuz ? () => onAlbumShareQobuz(album.id) : undefined}
|
||||
onShareSonglink={onAlbumShareSonglink ? () => onAlbumShareSonglink(album.id) : undefined}
|
||||
onDownload={onAlbumDownload ? () => onAlbumDownload(album.id) : undefined}
|
||||
isAlbumFullyDownloaded={isAlbumDownloaded(album.id)}
|
||||
onOpenContainingFolder={onOpenAlbumFolder ? () => onOpenAlbumFolder(album.id) : undefined}
|
||||
onReDownloadAlbum={onReDownloadAlbum ? () => onReDownloadAlbum(album.id) : undefined}
|
||||
{downloadStateVersion}
|
||||
onclick={() => { onAlbumClick?.(album.id); loadAlbumDownloadStatus(album.id); }}
|
||||
/>
|
||||
{/each}
|
||||
<div class="spacer"></div>
|
||||
{/snippet}
|
||||
</HorizontalScrollRow>
|
||||
{/if}
|
||||
|
||||
{#if sectionId === 'recentAlbums' && recentAlbums.length > 0}
|
||||
<HorizontalScrollRow title={$t('home.recentlyPlayed')}>
|
||||
{#snippet children()}
|
||||
@@ -964,18 +1265,21 @@
|
||||
{#snippet children()}
|
||||
{#each topArtists as artist}
|
||||
<button class="artist-card" onclick={() => onArtistClick?.(artist.id)}>
|
||||
{#if failedArtistImages.has(artist.id) || !artist.image}
|
||||
<div class="artist-image-wrapper">
|
||||
<div class="artist-image-placeholder">
|
||||
<User size={32} />
|
||||
<User size={48} />
|
||||
</div>
|
||||
{:else}
|
||||
<img
|
||||
src={artist.image}
|
||||
alt={artist.name}
|
||||
class="artist-image"
|
||||
onerror={() => handleArtistImageError(artist.id)}
|
||||
/>
|
||||
{/if}
|
||||
{#if !failedArtistImages.has(artist.id) && artist.image}
|
||||
<img
|
||||
src={artist.image}
|
||||
alt={artist.name}
|
||||
class="artist-image"
|
||||
loading="lazy"
|
||||
decoding="async"
|
||||
onerror={() => handleArtistImageError(artist.id)}
|
||||
/>
|
||||
{/if}
|
||||
</div>
|
||||
<div class="artist-name">{artist.name}</div>
|
||||
{#if artist.playCount}
|
||||
<div class="artist-meta">{$t('home.artistPlays', { values: { count: artist.playCount } })}</div>
|
||||
@@ -1048,6 +1352,16 @@
|
||||
position: relative;
|
||||
}
|
||||
|
||||
/* Add spacing between sections - using :global to affect child components */
|
||||
.home-view > :global(*:not(:first-child)) {
|
||||
margin-top: 60px !important;
|
||||
}
|
||||
|
||||
/* Second child (first section after header) gets less spacing */
|
||||
.home-view > :global(*:nth-child(2)) {
|
||||
margin-top: 30px !important;
|
||||
}
|
||||
|
||||
/* Custom scrollbar */
|
||||
.home-view::-webkit-scrollbar {
|
||||
width: 6px;
|
||||
@@ -1190,6 +1504,26 @@
|
||||
color: var(--text-primary);
|
||||
}
|
||||
|
||||
.section-title {
|
||||
font-size: 22px;
|
||||
font-weight: 600;
|
||||
color: var(--text-primary);
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
.loading-playlists {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
min-width: 180px;
|
||||
min-height: 180px;
|
||||
color: var(--text-muted);
|
||||
}
|
||||
|
||||
.loading-playlists :global(.spinner) {
|
||||
animation: spin 1s linear infinite;
|
||||
}
|
||||
|
||||
.track-list {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
@@ -1206,11 +1540,11 @@
|
||||
}
|
||||
|
||||
.artist-card {
|
||||
width: 160px;
|
||||
width: 180px;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
gap: 10px;
|
||||
background: var(--bg-secondary);
|
||||
border: 1px solid var(--bg-tertiary);
|
||||
border-radius: 12px;
|
||||
@@ -1225,15 +1559,26 @@
|
||||
background-color: var(--bg-hover);
|
||||
}
|
||||
|
||||
.artist-image-wrapper {
|
||||
position: relative;
|
||||
width: 140px;
|
||||
height: 140px;
|
||||
border-radius: 50%;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.artist-image,
|
||||
.artist-image-placeholder {
|
||||
width: 96px;
|
||||
height: 96px;
|
||||
width: 140px;
|
||||
height: 140px;
|
||||
border-radius: 50%;
|
||||
}
|
||||
|
||||
.artist-image {
|
||||
position: absolute;
|
||||
inset: 0;
|
||||
object-fit: cover;
|
||||
z-index: 1;
|
||||
}
|
||||
|
||||
.artist-image-placeholder {
|
||||
|
||||
@@ -38,6 +38,9 @@
|
||||
"popularAlbums": "Popular Albums",
|
||||
"qobuzissimes": "Qobuzissimes",
|
||||
"editorPicks": "Editor's Picks",
|
||||
"qobuzPlaylists": "Qobuz Playlists",
|
||||
"essentialDiscography": "Essential Discography",
|
||||
"allTags": "All",
|
||||
"continueListening": "Continue Listening",
|
||||
"yourTopArtists": "Your Top Artists",
|
||||
"artistPlays": "{count} plays",
|
||||
@@ -265,7 +268,8 @@
|
||||
"makePublic": "Make playlist public",
|
||||
"hideFromSidebar": "Hide from sidebar",
|
||||
"createAndAdd": "Create & Add",
|
||||
"playlistWithTracks": "{name} ({count} tracks)"
|
||||
"playlistWithTracks": "{name} ({count} tracks)",
|
||||
"copyToLibrary": "Copy to library"
|
||||
},
|
||||
"sort": {
|
||||
"nameAZ": "Name (A-Z)",
|
||||
@@ -458,7 +462,9 @@
|
||||
"loading": "Loading...",
|
||||
"loadMore": "Load More",
|
||||
"collapse": "Collapse sidebar",
|
||||
"expand": "Expand sidebar"
|
||||
"expand": "Expand sidebar",
|
||||
"moreOptions": "More options",
|
||||
"shareQobuz": "Share (Qobuz)"
|
||||
},
|
||||
"settings": {
|
||||
"title": "Settings",
|
||||
|
||||
@@ -38,6 +38,9 @@
|
||||
"popularAlbums": "Álbumes Populares",
|
||||
"qobuzissimes": "Qobuzissimes",
|
||||
"editorPicks": "Selección del Editor",
|
||||
"qobuzPlaylists": "Playlists de Qobuz",
|
||||
"essentialDiscography": "Discografía Esencial",
|
||||
"allTags": "Todo",
|
||||
"continueListening": "Continuar Escuchando",
|
||||
"yourTopArtists": "Tus Artistas Favoritos",
|
||||
"artistPlays": "{count} reproducciones",
|
||||
@@ -265,7 +268,8 @@
|
||||
"makePublic": "Hacer lista pública",
|
||||
"hideFromSidebar": "Ocultar de la barra lateral",
|
||||
"createAndAdd": "Crear y Agregar",
|
||||
"playlistWithTracks": "{name} ({count} pistas)"
|
||||
"playlistWithTracks": "{name} ({count} pistas)",
|
||||
"copyToLibrary": "Copiar a mi biblioteca"
|
||||
},
|
||||
"sort": {
|
||||
"nameAZ": "Nombre (A-Z)",
|
||||
@@ -458,7 +462,9 @@
|
||||
"loading": "Cargando...",
|
||||
"loadMore": "Cargar Más",
|
||||
"collapse": "Contraer barra lateral",
|
||||
"expand": "Expandir barra lateral"
|
||||
"expand": "Expandir barra lateral",
|
||||
"moreOptions": "Más opciones",
|
||||
"shareQobuz": "Compartir (Qobuz)"
|
||||
},
|
||||
"settings": {
|
||||
"title": "Ajustes",
|
||||
|
||||
@@ -12,6 +12,8 @@ export type HomeSectionId =
|
||||
| 'mostStreamed'
|
||||
| 'qobuzissimes'
|
||||
| 'editorPicks'
|
||||
| 'qobuzPlaylists'
|
||||
| 'essentialDiscography'
|
||||
| 'recentAlbums'
|
||||
| 'continueTracks'
|
||||
| 'topArtists'
|
||||
@@ -50,6 +52,8 @@ const DEFAULT_SECTIONS: HomeSection[] = [
|
||||
{ id: 'mostStreamed', label: 'Popular Albums', visible: false, source: 'qobuz' },
|
||||
{ id: 'qobuzissimes', label: 'Qobuzissimes', visible: false, source: 'qobuz' },
|
||||
{ id: 'editorPicks', label: "Editor's Picks", visible: false, source: 'qobuz' },
|
||||
{ id: 'qobuzPlaylists', label: 'Qobuz Playlists', visible: true, source: 'qobuz' },
|
||||
{ id: 'essentialDiscography', label: 'Essential Discography', visible: true, source: 'qobuz' },
|
||||
{ id: 'recentAlbums', label: 'Recently Played', visible: true, source: 'ml' },
|
||||
{ id: 'continueTracks', label: 'Continue Listening', visible: true, source: 'ml' },
|
||||
{ id: 'topArtists', label: 'Your Top Artists', visible: true, source: 'ml' },
|
||||
|
||||
@@ -0,0 +1,56 @@
|
||||
/**
|
||||
* In-memory session cache for API responses.
|
||||
* Data is cached for the lifetime of the app session (cleared on app close).
|
||||
* This avoids repeated API calls for the same data during a session.
|
||||
*/
|
||||
|
||||
import type { QobuzArtist, QobuzAlbum, QobuzTrack } from '$lib/types';
|
||||
|
||||
// Artist cache by ID
|
||||
const artistCache = new Map<number, QobuzArtist>();
|
||||
|
||||
// Album cache by ID
|
||||
const albumCache = new Map<string, QobuzAlbum>();
|
||||
|
||||
// Track cache by ID
|
||||
const trackCache = new Map<number, QobuzTrack>();
|
||||
|
||||
export function getCachedArtist(artistId: number): QobuzArtist | undefined {
|
||||
return artistCache.get(artistId);
|
||||
}
|
||||
|
||||
export function setCachedArtist(artist: QobuzArtist): void {
|
||||
artistCache.set(artist.id, artist);
|
||||
}
|
||||
|
||||
export function getCachedAlbum(albumId: string): QobuzAlbum | undefined {
|
||||
return albumCache.get(albumId);
|
||||
}
|
||||
|
||||
export function setCachedAlbum(album: QobuzAlbum): void {
|
||||
albumCache.set(album.id, album);
|
||||
}
|
||||
|
||||
export function getCachedTrack(trackId: number): QobuzTrack | undefined {
|
||||
return trackCache.get(trackId);
|
||||
}
|
||||
|
||||
export function setCachedTrack(track: QobuzTrack): void {
|
||||
trackCache.set(track.id, track);
|
||||
}
|
||||
|
||||
// Clear all caches (useful for logout or refresh)
|
||||
export function clearSessionCache(): void {
|
||||
artistCache.clear();
|
||||
albumCache.clear();
|
||||
trackCache.clear();
|
||||
}
|
||||
|
||||
// Get cache stats (for debugging)
|
||||
export function getCacheStats(): { artists: number; albums: number; tracks: number } {
|
||||
return {
|
||||
artists: artistCache.size,
|
||||
albums: albumCache.size,
|
||||
tracks: trackCache.size
|
||||
};
|
||||
}
|
||||
@@ -389,3 +389,95 @@ export interface FavoritesPreferences {
|
||||
icon_background: string | null;
|
||||
tab_order: string[];
|
||||
}
|
||||
|
||||
// ============ Discover API Types ============
|
||||
|
||||
export interface DiscoverResponse {
|
||||
containers: DiscoverContainers;
|
||||
}
|
||||
|
||||
export interface DiscoverContainers {
|
||||
playlists?: DiscoverContainer<DiscoverPlaylist>;
|
||||
ideal_discography?: DiscoverContainer<DiscoverAlbum>;
|
||||
playlists_tags?: DiscoverContainer<PlaylistTag>;
|
||||
new_releases?: DiscoverContainer<DiscoverAlbum>;
|
||||
}
|
||||
|
||||
export interface DiscoverContainer<T> {
|
||||
id: string;
|
||||
data: DiscoverData<T>;
|
||||
}
|
||||
|
||||
export interface DiscoverData<T> {
|
||||
has_more: boolean;
|
||||
items: T[];
|
||||
}
|
||||
|
||||
export interface DiscoverPlaylist {
|
||||
id: number;
|
||||
name: string;
|
||||
owner: { id: number; name: string };
|
||||
image: DiscoverPlaylistImage;
|
||||
description?: string;
|
||||
duration: number;
|
||||
tracks_count: number;
|
||||
genres?: { id: number; name: string; path: number[] }[];
|
||||
tags?: PlaylistTag[];
|
||||
}
|
||||
|
||||
export interface DiscoverPlaylistImage {
|
||||
rectangle?: string;
|
||||
covers?: string[];
|
||||
}
|
||||
|
||||
export interface PlaylistTag {
|
||||
id: number;
|
||||
slug: string;
|
||||
name: string;
|
||||
}
|
||||
|
||||
// Response from discover/playlists endpoint
|
||||
// Note: This endpoint returns items directly at root level (not wrapped in "playlists")
|
||||
export interface DiscoverPlaylistsResponse {
|
||||
has_more: boolean;
|
||||
items: DiscoverPlaylist[];
|
||||
}
|
||||
|
||||
export interface DiscoverAlbum {
|
||||
id: string;
|
||||
title: string;
|
||||
version?: string;
|
||||
track_count?: number;
|
||||
duration?: number;
|
||||
parental_warning?: boolean;
|
||||
image: DiscoverAlbumImage;
|
||||
artists: DiscoverArtist[];
|
||||
label?: { id: number; name: string };
|
||||
genre?: { name: string };
|
||||
dates?: DiscoverAlbumDates;
|
||||
audio_info?: DiscoverAudioInfo;
|
||||
}
|
||||
|
||||
export interface DiscoverAlbumImage {
|
||||
small?: string;
|
||||
thumbnail?: string;
|
||||
large?: string;
|
||||
}
|
||||
|
||||
export interface DiscoverArtist {
|
||||
id: number;
|
||||
name: string;
|
||||
roles?: string[];
|
||||
}
|
||||
|
||||
export interface DiscoverAlbumDates {
|
||||
download?: string;
|
||||
original?: string;
|
||||
stream?: string;
|
||||
}
|
||||
|
||||
export interface DiscoverAudioInfo {
|
||||
maximum_sampling_rate?: number;
|
||||
maximum_bit_depth?: number;
|
||||
maximum_channel_count?: number;
|
||||
}
|
||||
@@ -2935,6 +2935,12 @@
|
||||
onTrackRemoveDownload={handleTrackRemoveDownload}
|
||||
checkTrackDownloaded={checkTrackDownloaded}
|
||||
getTrackOfflineCacheStatus={getTrackOfflineCacheStatus}
|
||||
onPlaylistClick={selectPlaylist}
|
||||
onPlaylistPlay={playPlaylistById}
|
||||
onPlaylistPlayNext={queuePlaylistNextById}
|
||||
onPlaylistPlayLater={queuePlaylistLaterById}
|
||||
onPlaylistCopyToLibrary={copyPlaylistToLibraryById}
|
||||
onPlaylistShareQobuz={sharePlaylistQobuzLinkById}
|
||||
activeTrackId={currentTrack?.id ?? null}
|
||||
isPlaybackActive={isPlaying}
|
||||
sidebarExpanded={sidebarExpanded}
|
||||
|
||||
Reference in new issue
Block a user