feat: add Home customization with greeting and section ordering
- Add homeSettingsStore for persistent settings (localStorage)
- Create reusable Modal component with overlay
- Create HomeSettingsModal for customizing home layout
- Add time-based greeting (Good morning/afternoon/evening/night)
- Support custom greeting text with {name} placeholder
- Allow reordering and toggling visibility of sections
- Show Qobuz badge for editorial sections (New Releases, Press Awards)
- Add settings icon in home header using home-gear.svg
This commit is contained in:
1 parent
6f8dc41a98
commit
d86db5745e
7 files changed
+1059
-111
No files matched your search
@@ -0,0 +1,379 @@
|
||||
<script lang="ts">
|
||||
import { ChevronUp, ChevronDown, RotateCcw } from 'lucide-svelte';
|
||||
import Modal from './Modal.svelte';
|
||||
import {
|
||||
getSettings,
|
||||
subscribe,
|
||||
setSectionVisibility,
|
||||
moveSectionUp,
|
||||
moveSectionDown,
|
||||
setGreetingEnabled,
|
||||
setCustomGreeting,
|
||||
resetToDefaults,
|
||||
type HomeSettings
|
||||
} from '$lib/stores/homeSettingsStore';
|
||||
|
||||
interface Props {
|
||||
isOpen: boolean;
|
||||
onClose: () => void;
|
||||
}
|
||||
|
||||
let { isOpen, onClose }: Props = $props();
|
||||
|
||||
let settings = $state<HomeSettings>(getSettings());
|
||||
let customGreetingInput = $state(settings.greeting.customText || '');
|
||||
|
||||
// Subscribe to settings changes
|
||||
$effect(() => {
|
||||
const unsubscribe = subscribe(() => {
|
||||
settings = getSettings();
|
||||
customGreetingInput = settings.greeting.customText || '';
|
||||
});
|
||||
return unsubscribe;
|
||||
});
|
||||
|
||||
function handleToggleSection(sectionId: string, visible: boolean) {
|
||||
setSectionVisibility(sectionId as any, visible);
|
||||
}
|
||||
|
||||
function handleMoveUp(sectionId: string) {
|
||||
moveSectionUp(sectionId as any);
|
||||
}
|
||||
|
||||
function handleMoveDown(sectionId: string) {
|
||||
moveSectionDown(sectionId as any);
|
||||
}
|
||||
|
||||
function handleToggleGreeting(enabled: boolean) {
|
||||
setGreetingEnabled(enabled);
|
||||
}
|
||||
|
||||
function handleCustomGreetingChange() {
|
||||
setCustomGreeting(customGreetingInput || null);
|
||||
}
|
||||
|
||||
function handleReset() {
|
||||
resetToDefaults();
|
||||
}
|
||||
</script>
|
||||
|
||||
<Modal {isOpen} {onClose} title="Customize Home">
|
||||
{#snippet children()}
|
||||
<!-- Greeting Settings -->
|
||||
<div class="settings-section">
|
||||
<div class="section-title">Greeting</div>
|
||||
|
||||
<div class="setting-row">
|
||||
<div class="setting-info">
|
||||
<span class="setting-label">Show greeting</span>
|
||||
<span class="setting-desc">Display personalized greeting at top</span>
|
||||
</div>
|
||||
<label class="toggle">
|
||||
<input
|
||||
type="checkbox"
|
||||
checked={settings.greeting.enabled}
|
||||
onchange={(e) => handleToggleGreeting(e.currentTarget.checked)}
|
||||
/>
|
||||
<span class="toggle-slider"></span>
|
||||
</label>
|
||||
</div>
|
||||
|
||||
{#if settings.greeting.enabled}
|
||||
<div class="setting-row greeting-input-row">
|
||||
<div class="setting-info">
|
||||
<span class="setting-label">Custom greeting</span>
|
||||
<span class="setting-desc">Use {'{name}'} for your name. Leave empty for time-based.</span>
|
||||
</div>
|
||||
<input
|
||||
type="text"
|
||||
class="greeting-input"
|
||||
placeholder="Good vibes, {name}!"
|
||||
bind:value={customGreetingInput}
|
||||
onblur={handleCustomGreetingChange}
|
||||
onkeydown={(e) => e.key === 'Enter' && handleCustomGreetingChange()}
|
||||
/>
|
||||
</div>
|
||||
{/if}
|
||||
</div>
|
||||
|
||||
<!-- Sections Order -->
|
||||
<div class="settings-section">
|
||||
<div class="section-title">Sections</div>
|
||||
<p class="section-desc">Reorder with arrows. Toggle visibility with switch.</p>
|
||||
|
||||
<div class="sections-list">
|
||||
{#each settings.sections as section, index (section.id)}
|
||||
<div class="section-item" class:disabled={!section.visible}>
|
||||
<div class="section-controls">
|
||||
<button
|
||||
class="order-btn"
|
||||
onclick={() => handleMoveUp(section.id)}
|
||||
disabled={index === 0}
|
||||
title="Move up"
|
||||
>
|
||||
<ChevronUp size={16} />
|
||||
</button>
|
||||
<button
|
||||
class="order-btn"
|
||||
onclick={() => handleMoveDown(section.id)}
|
||||
disabled={index === settings.sections.length - 1}
|
||||
title="Move down"
|
||||
>
|
||||
<ChevronDown size={16} />
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<span class="section-label">
|
||||
{section.label}
|
||||
{#if section.source === 'qobuz'}
|
||||
<span class="source-badge">Qobuz</span>
|
||||
{/if}
|
||||
</span>
|
||||
|
||||
<label class="toggle">
|
||||
<input
|
||||
type="checkbox"
|
||||
checked={section.visible}
|
||||
onchange={(e) => handleToggleSection(section.id, e.currentTarget.checked)}
|
||||
/>
|
||||
<span class="toggle-slider"></span>
|
||||
</label>
|
||||
</div>
|
||||
{/each}
|
||||
</div>
|
||||
</div>
|
||||
{/snippet}
|
||||
|
||||
{#snippet footer()}
|
||||
<button class="reset-btn" onclick={handleReset}>
|
||||
<RotateCcw size={14} />
|
||||
Reset to defaults
|
||||
</button>
|
||||
{/snippet}
|
||||
</Modal>
|
||||
|
||||
<style>
|
||||
.settings-section {
|
||||
margin-bottom: 24px;
|
||||
}
|
||||
|
||||
.settings-section:last-child {
|
||||
margin-bottom: 0;
|
||||
}
|
||||
|
||||
.section-title {
|
||||
font-size: 14px;
|
||||
font-weight: 600;
|
||||
color: var(--text-primary);
|
||||
margin-bottom: 4px;
|
||||
}
|
||||
|
||||
.section-desc {
|
||||
font-size: 12px;
|
||||
color: var(--text-muted);
|
||||
margin: 0 0 12px 0;
|
||||
}
|
||||
|
||||
.setting-row {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
padding: 12px 0;
|
||||
border-bottom: 1px solid var(--bg-tertiary);
|
||||
}
|
||||
|
||||
.setting-row:last-child {
|
||||
border-bottom: none;
|
||||
}
|
||||
|
||||
.greeting-input-row {
|
||||
flex-direction: column;
|
||||
align-items: stretch;
|
||||
gap: 8px;
|
||||
}
|
||||
|
||||
.greeting-input-row .setting-info {
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.setting-info {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 2px;
|
||||
}
|
||||
|
||||
.setting-label {
|
||||
font-size: 14px;
|
||||
color: var(--text-primary);
|
||||
}
|
||||
|
||||
.setting-desc {
|
||||
font-size: 12px;
|
||||
color: var(--text-muted);
|
||||
}
|
||||
|
||||
.greeting-input {
|
||||
width: 100%;
|
||||
padding: 10px 12px;
|
||||
background: var(--bg-secondary);
|
||||
border: 1px solid var(--bg-tertiary);
|
||||
border-radius: 8px;
|
||||
color: var(--text-primary);
|
||||
font-size: 14px;
|
||||
transition: border-color 150ms ease;
|
||||
}
|
||||
|
||||
.greeting-input:focus {
|
||||
outline: none;
|
||||
border-color: var(--accent-primary);
|
||||
}
|
||||
|
||||
.greeting-input::placeholder {
|
||||
color: var(--text-muted);
|
||||
}
|
||||
|
||||
/* Toggle Switch */
|
||||
.toggle {
|
||||
position: relative;
|
||||
display: inline-block;
|
||||
width: 44px;
|
||||
height: 24px;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
.toggle input {
|
||||
opacity: 0;
|
||||
width: 0;
|
||||
height: 0;
|
||||
}
|
||||
|
||||
.toggle-slider {
|
||||
position: absolute;
|
||||
cursor: pointer;
|
||||
inset: 0;
|
||||
background-color: var(--bg-tertiary);
|
||||
border-radius: 24px;
|
||||
transition: all 200ms ease;
|
||||
}
|
||||
|
||||
.toggle-slider::before {
|
||||
position: absolute;
|
||||
content: "";
|
||||
height: 18px;
|
||||
width: 18px;
|
||||
left: 3px;
|
||||
bottom: 3px;
|
||||
background-color: white;
|
||||
border-radius: 50%;
|
||||
transition: transform 200ms ease;
|
||||
}
|
||||
|
||||
.toggle input:checked + .toggle-slider {
|
||||
background-color: var(--accent-primary);
|
||||
}
|
||||
|
||||
.toggle input:checked + .toggle-slider::before {
|
||||
transform: translateX(20px);
|
||||
}
|
||||
|
||||
/* Sections List */
|
||||
.sections-list {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 2px;
|
||||
background: var(--bg-secondary);
|
||||
border-radius: 8px;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.section-item {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 12px;
|
||||
padding: 10px 12px;
|
||||
background: var(--bg-secondary);
|
||||
transition: all 150ms ease;
|
||||
}
|
||||
|
||||
.section-item:hover {
|
||||
background: var(--bg-hover);
|
||||
}
|
||||
|
||||
.section-item.disabled {
|
||||
opacity: 0.5;
|
||||
}
|
||||
|
||||
.section-controls {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 2px;
|
||||
}
|
||||
|
||||
.order-btn {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
width: 24px;
|
||||
height: 20px;
|
||||
background: transparent;
|
||||
border: none;
|
||||
border-radius: 4px;
|
||||
color: var(--text-muted);
|
||||
cursor: pointer;
|
||||
transition: all 150ms ease;
|
||||
}
|
||||
|
||||
.order-btn:hover:not(:disabled) {
|
||||
background: var(--bg-tertiary);
|
||||
color: var(--text-primary);
|
||||
}
|
||||
|
||||
.order-btn:disabled {
|
||||
opacity: 0.3;
|
||||
cursor: not-allowed;
|
||||
}
|
||||
|
||||
.section-label {
|
||||
flex: 1;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
font-size: 14px;
|
||||
color: var(--text-primary);
|
||||
}
|
||||
|
||||
.section-item.disabled .section-label {
|
||||
color: var(--text-muted);
|
||||
}
|
||||
|
||||
.source-badge {
|
||||
font-size: 10px;
|
||||
font-weight: 500;
|
||||
color: var(--accent-primary);
|
||||
background: rgba(99, 102, 241, 0.15);
|
||||
padding: 2px 6px;
|
||||
border-radius: 4px;
|
||||
text-transform: uppercase;
|
||||
letter-spacing: 0.5px;
|
||||
}
|
||||
|
||||
.reset-btn {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 6px;
|
||||
padding: 8px 12px;
|
||||
background: transparent;
|
||||
border: 1px solid var(--bg-tertiary);
|
||||
border-radius: 6px;
|
||||
color: var(--text-muted);
|
||||
font-size: 13px;
|
||||
cursor: pointer;
|
||||
transition: all 150ms ease;
|
||||
}
|
||||
|
||||
.reset-btn:hover {
|
||||
background: var(--bg-hover);
|
||||
border-color: var(--text-muted);
|
||||
color: var(--text-primary);
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,157 @@
|
||||
<script lang="ts">
|
||||
import { X } from 'lucide-svelte';
|
||||
import type { Snippet } from 'svelte';
|
||||
|
||||
interface Props {
|
||||
isOpen: boolean;
|
||||
onClose: () => void;
|
||||
title?: string;
|
||||
showCloseButton?: boolean;
|
||||
maxWidth?: string;
|
||||
children: Snippet;
|
||||
footer?: Snippet;
|
||||
}
|
||||
|
||||
let {
|
||||
isOpen,
|
||||
onClose,
|
||||
title,
|
||||
showCloseButton = true,
|
||||
maxWidth = '480px',
|
||||
children,
|
||||
footer
|
||||
}: Props = $props();
|
||||
|
||||
function handleBackdropClick(e: MouseEvent) {
|
||||
if (e.target === e.currentTarget) {
|
||||
onClose();
|
||||
}
|
||||
}
|
||||
|
||||
function handleKeydown(e: KeyboardEvent) {
|
||||
if (e.key === 'Escape' && isOpen) {
|
||||
onClose();
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<svelte:window onkeydown={handleKeydown} />
|
||||
|
||||
{#if isOpen}
|
||||
<div class="modal-overlay" onclick={handleBackdropClick} role="dialog" aria-modal="true">
|
||||
<div class="modal" style="max-width: {maxWidth}">
|
||||
{#if title || showCloseButton}
|
||||
<div class="modal-header">
|
||||
{#if title}
|
||||
<h2>{title}</h2>
|
||||
{:else}
|
||||
<div></div>
|
||||
{/if}
|
||||
{#if showCloseButton}
|
||||
<button class="close-btn" onclick={onClose} title="Close">
|
||||
<X size={20} />
|
||||
</button>
|
||||
{/if}
|
||||
</div>
|
||||
{/if}
|
||||
|
||||
<div class="modal-content">
|
||||
{@render children()}
|
||||
</div>
|
||||
|
||||
{#if footer}
|
||||
<div class="modal-footer">
|
||||
{@render footer()}
|
||||
</div>
|
||||
{/if}
|
||||
</div>
|
||||
</div>
|
||||
{/if}
|
||||
|
||||
<style>
|
||||
.modal-overlay {
|
||||
position: fixed;
|
||||
inset: 0;
|
||||
background: rgba(0, 0, 0, 0.7);
|
||||
backdrop-filter: blur(4px);
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
z-index: 1000;
|
||||
animation: fade-in 150ms ease;
|
||||
}
|
||||
|
||||
@keyframes fade-in {
|
||||
from { opacity: 0; }
|
||||
to { opacity: 1; }
|
||||
}
|
||||
|
||||
.modal {
|
||||
background: var(--bg-primary);
|
||||
border: 1px solid var(--bg-tertiary);
|
||||
border-radius: 12px;
|
||||
width: 100%;
|
||||
max-height: 80vh;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
animation: slide-up 200ms ease;
|
||||
}
|
||||
|
||||
@keyframes slide-up {
|
||||
from {
|
||||
opacity: 0;
|
||||
transform: translateY(20px) scale(0.98);
|
||||
}
|
||||
to {
|
||||
opacity: 1;
|
||||
transform: translateY(0) scale(1);
|
||||
}
|
||||
}
|
||||
|
||||
.modal-header {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
padding: 16px 20px;
|
||||
border-bottom: 1px solid var(--bg-tertiary);
|
||||
}
|
||||
|
||||
.modal-header h2 {
|
||||
font-size: 18px;
|
||||
font-weight: 600;
|
||||
color: var(--text-primary);
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
.close-btn {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
width: 32px;
|
||||
height: 32px;
|
||||
background: transparent;
|
||||
border: none;
|
||||
border-radius: 6px;
|
||||
color: var(--text-muted);
|
||||
cursor: pointer;
|
||||
transition: all 150ms ease;
|
||||
}
|
||||
|
||||
.close-btn:hover {
|
||||
background: var(--bg-hover);
|
||||
color: var(--text-primary);
|
||||
}
|
||||
|
||||
.modal-content {
|
||||
flex: 1;
|
||||
overflow-y: auto;
|
||||
padding: 20px;
|
||||
}
|
||||
|
||||
.modal-footer {
|
||||
display: flex;
|
||||
justify-content: flex-start;
|
||||
padding: 16px 20px;
|
||||
border-top: 1px solid var(--bg-tertiary);
|
||||
}
|
||||
</style>
|
||||
@@ -5,7 +5,15 @@
|
||||
import HorizontalScrollRow from '../HorizontalScrollRow.svelte';
|
||||
import AlbumCard from '../AlbumCard.svelte';
|
||||
import TrackRow from '../TrackRow.svelte';
|
||||
import HomeSettingsModal from '../HomeSettingsModal.svelte';
|
||||
import { formatDuration, formatQuality, getQobuzImage } from '$lib/adapters/qobuzAdapters';
|
||||
import {
|
||||
subscribe as subscribeHomeSettings,
|
||||
getSettings,
|
||||
getGreetingText,
|
||||
type HomeSettings,
|
||||
type HomeSectionId
|
||||
} from '$lib/stores/homeSettingsStore';
|
||||
import type { QobuzAlbum, QobuzArtist, QobuzTrack, DisplayTrack } from '$lib/types';
|
||||
|
||||
interface TopArtistSeed {
|
||||
@@ -37,12 +45,39 @@
|
||||
}
|
||||
|
||||
interface Props {
|
||||
userName?: string;
|
||||
onAlbumClick?: (albumId: string) => void;
|
||||
onArtistClick?: (artistId: number) => void;
|
||||
onTrackPlay?: (track: DisplayTrack) => void;
|
||||
}
|
||||
|
||||
let { onAlbumClick, onArtistClick, onTrackPlay }: Props = $props();
|
||||
let { userName = 'User', onAlbumClick, onArtistClick, onTrackPlay }: Props = $props();
|
||||
|
||||
// Home settings state
|
||||
let homeSettings = $state<HomeSettings>(getSettings());
|
||||
let isSettingsModalOpen = $state(false);
|
||||
|
||||
// Computed greeting
|
||||
const greetingText = $derived(getGreetingText(userName));
|
||||
|
||||
// Subscribe to home settings changes
|
||||
$effect(() => {
|
||||
const unsubscribe = subscribeHomeSettings(() => {
|
||||
homeSettings = getSettings();
|
||||
});
|
||||
return unsubscribe;
|
||||
});
|
||||
|
||||
// Check if a section is visible
|
||||
function isSectionVisible(sectionId: HomeSectionId): boolean {
|
||||
const section = homeSettings.sections.find(s => s.id === sectionId);
|
||||
return section?.visible ?? true;
|
||||
}
|
||||
|
||||
// Get ordered visible sections
|
||||
const visibleSections = $derived(
|
||||
homeSettings.sections.filter(s => s.visible).map(s => s.id)
|
||||
);
|
||||
|
||||
const LIMITS = {
|
||||
recentAlbums: 12,
|
||||
@@ -300,6 +335,18 @@
|
||||
</script>
|
||||
|
||||
<div class="home-view">
|
||||
<!-- Header with greeting and settings -->
|
||||
<div class="home-header">
|
||||
{#if homeSettings.greeting.enabled}
|
||||
<h2 class="greeting">{greetingText}</h2>
|
||||
{:else}
|
||||
<div></div>
|
||||
{/if}
|
||||
<button class="settings-btn" onclick={() => isSettingsModalOpen = true} title="Customize Home">
|
||||
<img src="/home-gear.svg" alt="Settings" class="settings-icon" />
|
||||
</button>
|
||||
</div>
|
||||
|
||||
{#if isInitializing}
|
||||
<div class="home-state">
|
||||
<div class="state-icon loading">
|
||||
@@ -317,122 +364,125 @@
|
||||
<p>{error}</p>
|
||||
</div>
|
||||
{:else if hasContent}
|
||||
{#if newReleases.length > 0}
|
||||
<HorizontalScrollRow title="New Releases">
|
||||
{#snippet children()}
|
||||
{#each newReleases as album}
|
||||
<AlbumCard
|
||||
artwork={album.artwork}
|
||||
title={album.title}
|
||||
artist={album.artist}
|
||||
quality={album.quality}
|
||||
onclick={() => onAlbumClick?.(album.id)}
|
||||
/>
|
||||
{/each}
|
||||
<div class="spacer"></div>
|
||||
{/snippet}
|
||||
</HorizontalScrollRow>
|
||||
{/if}
|
||||
<!-- Render sections in user-defined order -->
|
||||
{#each visibleSections as sectionId (sectionId)}
|
||||
{#if sectionId === 'newReleases' && newReleases.length > 0}
|
||||
<HorizontalScrollRow title="New Releases">
|
||||
{#snippet children()}
|
||||
{#each newReleases as album}
|
||||
<AlbumCard
|
||||
artwork={album.artwork}
|
||||
title={album.title}
|
||||
artist={album.artist}
|
||||
quality={album.quality}
|
||||
onclick={() => onAlbumClick?.(album.id)}
|
||||
/>
|
||||
{/each}
|
||||
<div class="spacer"></div>
|
||||
{/snippet}
|
||||
</HorizontalScrollRow>
|
||||
{/if}
|
||||
|
||||
{#if pressAwards.length > 0}
|
||||
<HorizontalScrollRow title="Press Awards">
|
||||
{#snippet children()}
|
||||
{#each pressAwards as album}
|
||||
<AlbumCard
|
||||
artwork={album.artwork}
|
||||
title={album.title}
|
||||
artist={album.artist}
|
||||
quality={album.quality}
|
||||
onclick={() => onAlbumClick?.(album.id)}
|
||||
/>
|
||||
{/each}
|
||||
<div class="spacer"></div>
|
||||
{/snippet}
|
||||
</HorizontalScrollRow>
|
||||
{/if}
|
||||
{#if sectionId === 'pressAwards' && pressAwards.length > 0}
|
||||
<HorizontalScrollRow title="Press Awards">
|
||||
{#snippet children()}
|
||||
{#each pressAwards as album}
|
||||
<AlbumCard
|
||||
artwork={album.artwork}
|
||||
title={album.title}
|
||||
artist={album.artist}
|
||||
quality={album.quality}
|
||||
onclick={() => onAlbumClick?.(album.id)}
|
||||
/>
|
||||
{/each}
|
||||
<div class="spacer"></div>
|
||||
{/snippet}
|
||||
</HorizontalScrollRow>
|
||||
{/if}
|
||||
|
||||
{#if recentAlbums.length > 0}
|
||||
<HorizontalScrollRow title="Recently Played">
|
||||
{#snippet children()}
|
||||
{#each recentAlbums as album}
|
||||
<AlbumCard
|
||||
artwork={album.artwork}
|
||||
title={album.title}
|
||||
artist={album.artist}
|
||||
quality={album.quality}
|
||||
onclick={() => onAlbumClick?.(album.id)}
|
||||
/>
|
||||
{/each}
|
||||
<div class="spacer"></div>
|
||||
{/snippet}
|
||||
</HorizontalScrollRow>
|
||||
{/if}
|
||||
{#if sectionId === 'recentAlbums' && recentAlbums.length > 0}
|
||||
<HorizontalScrollRow title="Recently Played">
|
||||
{#snippet children()}
|
||||
{#each recentAlbums as album}
|
||||
<AlbumCard
|
||||
artwork={album.artwork}
|
||||
title={album.title}
|
||||
artist={album.artist}
|
||||
quality={album.quality}
|
||||
onclick={() => onAlbumClick?.(album.id)}
|
||||
/>
|
||||
{/each}
|
||||
<div class="spacer"></div>
|
||||
{/snippet}
|
||||
</HorizontalScrollRow>
|
||||
{/if}
|
||||
|
||||
{#if continueTracks.length > 0}
|
||||
<div class="section">
|
||||
<div class="section-header">
|
||||
<h2>Continue Listening</h2>
|
||||
{#if sectionId === 'continueTracks' && continueTracks.length > 0}
|
||||
<div class="section">
|
||||
<div class="section-header">
|
||||
<h2>Continue Listening</h2>
|
||||
</div>
|
||||
<div class="track-list">
|
||||
{#each continueTracks as track, index}
|
||||
<TrackRow
|
||||
number={index + 1}
|
||||
title={track.title}
|
||||
artist={track.artist}
|
||||
duration={track.duration}
|
||||
quality={getTrackQuality(track)}
|
||||
hideDownload={true}
|
||||
onPlay={() => onTrackPlay?.(track)}
|
||||
/>
|
||||
{/each}
|
||||
</div>
|
||||
</div>
|
||||
<div class="track-list">
|
||||
{#each continueTracks as track, index}
|
||||
<TrackRow
|
||||
number={index + 1}
|
||||
title={track.title}
|
||||
artist={track.artist}
|
||||
duration={track.duration}
|
||||
quality={getTrackQuality(track)}
|
||||
hideDownload={true}
|
||||
onPlay={() => onTrackPlay?.(track)}
|
||||
/>
|
||||
{/each}
|
||||
</div>
|
||||
</div>
|
||||
{/if}
|
||||
{/if}
|
||||
|
||||
{#if topArtists.length > 0}
|
||||
<HorizontalScrollRow title="Your Top Artists">
|
||||
{#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-placeholder">
|
||||
<User size={32} />
|
||||
</div>
|
||||
{:else}
|
||||
<img
|
||||
src={artist.image}
|
||||
alt={artist.name}
|
||||
class="artist-image"
|
||||
onerror={() => handleArtistImageError(artist.id)}
|
||||
/>
|
||||
{/if}
|
||||
<div class="artist-name">{artist.name}</div>
|
||||
{#if artist.playCount}
|
||||
<div class="artist-meta">{artist.playCount} plays</div>
|
||||
{/if}
|
||||
</button>
|
||||
{/each}
|
||||
<div class="spacer"></div>
|
||||
{/snippet}
|
||||
</HorizontalScrollRow>
|
||||
{/if}
|
||||
{#if sectionId === 'topArtists' && topArtists.length > 0}
|
||||
<HorizontalScrollRow title="Your Top Artists">
|
||||
{#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-placeholder">
|
||||
<User size={32} />
|
||||
</div>
|
||||
{:else}
|
||||
<img
|
||||
src={artist.image}
|
||||
alt={artist.name}
|
||||
class="artist-image"
|
||||
onerror={() => handleArtistImageError(artist.id)}
|
||||
/>
|
||||
{/if}
|
||||
<div class="artist-name">{artist.name}</div>
|
||||
{#if artist.playCount}
|
||||
<div class="artist-meta">{artist.playCount} plays</div>
|
||||
{/if}
|
||||
</button>
|
||||
{/each}
|
||||
<div class="spacer"></div>
|
||||
{/snippet}
|
||||
</HorizontalScrollRow>
|
||||
{/if}
|
||||
|
||||
{#if favoriteAlbums.length > 0}
|
||||
<HorizontalScrollRow title="More From Favorites">
|
||||
{#snippet children()}
|
||||
{#each favoriteAlbums as album}
|
||||
<AlbumCard
|
||||
artwork={album.artwork}
|
||||
title={album.title}
|
||||
artist={album.artist}
|
||||
quality={album.quality}
|
||||
onclick={() => onAlbumClick?.(album.id)}
|
||||
/>
|
||||
{/each}
|
||||
<div class="spacer"></div>
|
||||
{/snippet}
|
||||
</HorizontalScrollRow>
|
||||
{/if}
|
||||
{#if sectionId === 'favoriteAlbums' && favoriteAlbums.length > 0}
|
||||
<HorizontalScrollRow title="More From Favorites">
|
||||
{#snippet children()}
|
||||
{#each favoriteAlbums as album}
|
||||
<AlbumCard
|
||||
artwork={album.artwork}
|
||||
title={album.title}
|
||||
artist={album.artist}
|
||||
quality={album.quality}
|
||||
onclick={() => onAlbumClick?.(album.id)}
|
||||
/>
|
||||
{/each}
|
||||
<div class="spacer"></div>
|
||||
{/snippet}
|
||||
</HorizontalScrollRow>
|
||||
{/if}
|
||||
{/each}
|
||||
{:else}
|
||||
<div class="home-state">
|
||||
<div class="state-icon">
|
||||
@@ -442,6 +492,12 @@
|
||||
<p>Play music or add favorites to activate recommendations.</p>
|
||||
</div>
|
||||
{/if}
|
||||
|
||||
<!-- Settings Modal -->
|
||||
<HomeSettingsModal
|
||||
isOpen={isSettingsModalOpen}
|
||||
onClose={() => isSettingsModalOpen = false}
|
||||
/>
|
||||
</div>
|
||||
|
||||
<style>
|
||||
@@ -450,6 +506,45 @@
|
||||
padding-bottom: 24px;
|
||||
}
|
||||
|
||||
.home-header {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
margin-bottom: 24px;
|
||||
}
|
||||
|
||||
.greeting {
|
||||
font-size: 24px;
|
||||
font-weight: 600;
|
||||
color: var(--text-primary);
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
.settings-btn {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
width: 36px;
|
||||
height: 36px;
|
||||
background: transparent;
|
||||
border: none;
|
||||
border-radius: 8px;
|
||||
cursor: pointer;
|
||||
transition: all 150ms ease;
|
||||
opacity: 0.7;
|
||||
}
|
||||
|
||||
.settings-btn:hover {
|
||||
background: var(--bg-hover);
|
||||
opacity: 1;
|
||||
}
|
||||
|
||||
.settings-icon {
|
||||
width: 22px;
|
||||
height: 22px;
|
||||
filter: invert(1) opacity(0.8);
|
||||
}
|
||||
|
||||
.spacer {
|
||||
width: 60px;
|
||||
flex-shrink: 0;
|
||||
|
||||
@@ -0,0 +1,300 @@
|
||||
/**
|
||||
* Home Settings Store
|
||||
*
|
||||
* Manages Home view personalization settings with localStorage persistence.
|
||||
* Handles section ordering, visibility, and greeting customization.
|
||||
*/
|
||||
|
||||
// Section identifiers
|
||||
export type HomeSectionId =
|
||||
| 'newReleases'
|
||||
| 'pressAwards'
|
||||
| 'recentAlbums'
|
||||
| 'continueTracks'
|
||||
| 'topArtists'
|
||||
| 'favoriteAlbums';
|
||||
|
||||
export interface HomeSection {
|
||||
id: HomeSectionId;
|
||||
label: string;
|
||||
visible: boolean;
|
||||
source?: 'qobuz' | 'user'; // qobuz = editorial, user = personal data
|
||||
}
|
||||
|
||||
export interface HomeSettings {
|
||||
sections: HomeSection[];
|
||||
greeting: {
|
||||
enabled: boolean;
|
||||
customText: string | null; // null = use default time-based greeting
|
||||
};
|
||||
}
|
||||
|
||||
const STORAGE_KEY = 'qbz-home-settings';
|
||||
|
||||
// Default section order and visibility
|
||||
const DEFAULT_SECTIONS: HomeSection[] = [
|
||||
{ id: 'newReleases', label: 'New Releases', visible: true, source: 'qobuz' },
|
||||
{ id: 'pressAwards', label: 'Press Awards', visible: true, source: 'qobuz' },
|
||||
{ id: 'recentAlbums', label: 'Recently Played', visible: true, source: 'user' },
|
||||
{ id: 'continueTracks', label: 'Continue Listening', visible: true, source: 'user' },
|
||||
{ id: 'topArtists', label: 'Your Top Artists', visible: true, source: 'user' },
|
||||
{ id: 'favoriteAlbums', label: 'More From Favorites', visible: true, source: 'user' },
|
||||
];
|
||||
|
||||
const DEFAULT_SETTINGS: HomeSettings = {
|
||||
sections: DEFAULT_SECTIONS,
|
||||
greeting: {
|
||||
enabled: true,
|
||||
customText: null
|
||||
}
|
||||
};
|
||||
|
||||
// State
|
||||
let settings: HomeSettings = loadSettings();
|
||||
const listeners = new Set<() => void>();
|
||||
|
||||
function notifyListeners(): void {
|
||||
for (const listener of listeners) {
|
||||
listener();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Load settings from localStorage
|
||||
*/
|
||||
function loadSettings(): HomeSettings {
|
||||
try {
|
||||
const saved = localStorage.getItem(STORAGE_KEY);
|
||||
if (saved) {
|
||||
const parsed = JSON.parse(saved) as Partial<HomeSettings>;
|
||||
// Merge with defaults to handle new sections added later
|
||||
return mergeWithDefaults(parsed);
|
||||
}
|
||||
} catch (err) {
|
||||
console.error('Failed to load home settings:', err);
|
||||
}
|
||||
return { ...DEFAULT_SETTINGS, sections: [...DEFAULT_SECTIONS] };
|
||||
}
|
||||
|
||||
/**
|
||||
* Merge saved settings with defaults (handles new sections)
|
||||
*/
|
||||
function mergeWithDefaults(saved: Partial<HomeSettings>): HomeSettings {
|
||||
const result: HomeSettings = {
|
||||
sections: [],
|
||||
greeting: saved.greeting ?? DEFAULT_SETTINGS.greeting
|
||||
};
|
||||
|
||||
// Build section map from saved
|
||||
const savedSectionMap = new Map<HomeSectionId, HomeSection>();
|
||||
if (saved.sections) {
|
||||
for (const section of saved.sections) {
|
||||
savedSectionMap.set(section.id, section);
|
||||
}
|
||||
}
|
||||
|
||||
// Use saved order, adding any missing sections at the end
|
||||
const usedIds = new Set<HomeSectionId>();
|
||||
|
||||
if (saved.sections) {
|
||||
for (const section of saved.sections) {
|
||||
const defaultSection = DEFAULT_SECTIONS.find(s => s.id === section.id);
|
||||
if (defaultSection) {
|
||||
result.sections.push({
|
||||
id: section.id,
|
||||
label: defaultSection.label, // Always use current label
|
||||
visible: section.visible,
|
||||
source: defaultSection.source // Always use default source
|
||||
});
|
||||
usedIds.add(section.id);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Add any new sections that weren't in saved settings
|
||||
for (const defaultSection of DEFAULT_SECTIONS) {
|
||||
if (!usedIds.has(defaultSection.id)) {
|
||||
result.sections.push({ ...defaultSection });
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Save settings to localStorage
|
||||
*/
|
||||
function saveSettings(): void {
|
||||
try {
|
||||
localStorage.setItem(STORAGE_KEY, JSON.stringify(settings));
|
||||
} catch (err) {
|
||||
console.error('Failed to save home settings:', err);
|
||||
}
|
||||
}
|
||||
|
||||
// ============ Public API ============
|
||||
|
||||
/**
|
||||
* Subscribe to settings changes
|
||||
*/
|
||||
export function subscribe(listener: () => void): () => void {
|
||||
listeners.add(listener);
|
||||
listener(); // Immediately notify with current state
|
||||
return () => listeners.delete(listener);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get current settings
|
||||
*/
|
||||
export function getSettings(): HomeSettings {
|
||||
return settings;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get visible sections in order
|
||||
*/
|
||||
export function getVisibleSections(): HomeSection[] {
|
||||
return settings.sections.filter(s => s.visible);
|
||||
}
|
||||
|
||||
/**
|
||||
* Toggle section visibility
|
||||
*/
|
||||
export function toggleSectionVisibility(sectionId: HomeSectionId): void {
|
||||
const section = settings.sections.find(s => s.id === sectionId);
|
||||
if (section) {
|
||||
section.visible = !section.visible;
|
||||
saveSettings();
|
||||
notifyListeners();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set section visibility
|
||||
*/
|
||||
export function setSectionVisibility(sectionId: HomeSectionId, visible: boolean): void {
|
||||
const section = settings.sections.find(s => s.id === sectionId);
|
||||
if (section) {
|
||||
section.visible = visible;
|
||||
saveSettings();
|
||||
notifyListeners();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Move section up in order
|
||||
*/
|
||||
export function moveSectionUp(sectionId: HomeSectionId): void {
|
||||
const index = settings.sections.findIndex(s => s.id === sectionId);
|
||||
if (index > 0) {
|
||||
const temp = settings.sections[index];
|
||||
settings.sections[index] = settings.sections[index - 1];
|
||||
settings.sections[index - 1] = temp;
|
||||
saveSettings();
|
||||
notifyListeners();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Move section down in order
|
||||
*/
|
||||
export function moveSectionDown(sectionId: HomeSectionId): void {
|
||||
const index = settings.sections.findIndex(s => s.id === sectionId);
|
||||
if (index >= 0 && index < settings.sections.length - 1) {
|
||||
const temp = settings.sections[index];
|
||||
settings.sections[index] = settings.sections[index + 1];
|
||||
settings.sections[index + 1] = temp;
|
||||
saveSettings();
|
||||
notifyListeners();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Reorder sections by providing new order of IDs
|
||||
*/
|
||||
export function reorderSections(newOrder: HomeSectionId[]): void {
|
||||
const sectionMap = new Map(settings.sections.map(s => [s.id, s]));
|
||||
const reordered: HomeSection[] = [];
|
||||
|
||||
for (const id of newOrder) {
|
||||
const section = sectionMap.get(id);
|
||||
if (section) {
|
||||
reordered.push(section);
|
||||
}
|
||||
}
|
||||
|
||||
settings.sections = reordered;
|
||||
saveSettings();
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
/**
|
||||
* Toggle greeting visibility
|
||||
*/
|
||||
export function toggleGreeting(): void {
|
||||
settings.greeting.enabled = !settings.greeting.enabled;
|
||||
saveSettings();
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
/**
|
||||
* Set greeting enabled state
|
||||
*/
|
||||
export function setGreetingEnabled(enabled: boolean): void {
|
||||
settings.greeting.enabled = enabled;
|
||||
saveSettings();
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
/**
|
||||
* Set custom greeting text (null = use default time-based)
|
||||
*/
|
||||
export function setCustomGreeting(text: string | null): void {
|
||||
settings.greeting.customText = text && text.trim() ? text.trim() : null;
|
||||
saveSettings();
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get greeting text for display
|
||||
*/
|
||||
export function getGreetingText(userName: string): string {
|
||||
if (settings.greeting.customText) {
|
||||
return settings.greeting.customText.replace('{name}', getFirstName(userName));
|
||||
}
|
||||
return getTimeBasedGreeting(userName);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get time-based greeting
|
||||
*/
|
||||
function getTimeBasedGreeting(userName: string): string {
|
||||
const hour = new Date().getHours();
|
||||
const firstName = getFirstName(userName);
|
||||
|
||||
if (hour >= 5 && hour < 12) {
|
||||
return `Good morning, ${firstName}`;
|
||||
} else if (hour >= 12 && hour < 17) {
|
||||
return `Good afternoon, ${firstName}`;
|
||||
} else if (hour >= 17 && hour < 21) {
|
||||
return `Good evening, ${firstName}`;
|
||||
} else {
|
||||
return `Good night, ${firstName}`;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Extract first name from full name
|
||||
*/
|
||||
function getFirstName(fullName: string): string {
|
||||
return fullName.split(' ')[0] || fullName;
|
||||
}
|
||||
|
||||
/**
|
||||
* Reset to defaults
|
||||
*/
|
||||
export function resetToDefaults(): void {
|
||||
settings = { ...DEFAULT_SETTINGS, sections: DEFAULT_SECTIONS.map(s => ({ ...s })) };
|
||||
saveSettings();
|
||||
notifyListeners();
|
||||
}
|
||||
@@ -1037,6 +1037,7 @@
|
||||
<main class="main-content">
|
||||
{#if activeView === 'home'}
|
||||
<HomeView
|
||||
userName={userInfo?.userName}
|
||||
onAlbumClick={handleAlbumClick}
|
||||
onArtistClick={handleArtistClick}
|
||||
onTrackPlay={handleDisplayTrackPlay}
|
||||
|
||||
Reference in new issue
Block a user