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:
vicrodh committed 2026-01-11 00:40:23 -06:00
1 parent 6f8dc41a98
commit d86db5745e
7 files changed
+1059 -111

No files matched your search

+379
View File
@@ -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>
+157
View File
@@ -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>
+206 -111
View File
@@ -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;