feat(artist): restyle jump nav

This commit is contained in:
vicrodh committed 2026-01-12 00:50:25 -06:00
1 parent 0e682e9ca6
commit 95bae2e036
1 file changed
+95 -49
@@ -87,11 +87,15 @@
let similarArtists = $state<QobuzArtist[]>([]); let similarArtists = $state<QobuzArtist[]>([]);
let similarArtistsLoading = $state(false); let similarArtistsLoading = $state(false);
let similarArtistImageErrors = $state<Set<number>>(new Set()); let similarArtistImageErrors = $state<Set<number>>(new Set());
let artistDetailEl = $state<HTMLDivElement | null>(null);
let aboutSection = $state<HTMLDivElement | null>(null);
let topTracksSection = $state<HTMLDivElement | null>(null); let topTracksSection = $state<HTMLDivElement | null>(null);
let discographySection = $state<HTMLDivElement | null>(null); let discographySection = $state<HTMLDivElement | null>(null);
let epsSinglesSection = $state<HTMLDivElement | null>(null); let epsSinglesSection = $state<HTMLDivElement | null>(null);
let compilationsSection = $state<HTMLDivElement | null>(null); let compilationsSection = $state<HTMLDivElement | null>(null);
let playlistsSection = $state<HTMLDivElement | null>(null); let playlistsSection = $state<HTMLDivElement | null>(null);
let activeJumpSection = $state('about');
let jumpObserver: IntersectionObserver | null = null;
interface SimilarArtistsPage { interface SimilarArtistsPage {
items: QobuzArtist[]; items: QobuzArtist[];
@@ -110,6 +114,7 @@
topTracks = []; topTracks = [];
similarArtists = []; similarArtists = [];
similarArtistImageErrors = new Set(); similarArtistImageErrors = new Set();
activeJumpSection = 'about';
loadTopTracks(); loadTopTracks();
loadSimilarArtists(); loadSimilarArtists();
@@ -273,16 +278,69 @@
let hasEpsSingles = $derived(artist.epsSingles.length > 0); let hasEpsSingles = $derived(artist.epsSingles.length > 0);
let hasCompilations = $derived(artist.compilations.length > 0); let hasCompilations = $derived(artist.compilations.length > 0);
let hasPlaylists = $derived(artist.playlists.length > 0); let hasPlaylists = $derived(artist.playlists.length > 0);
let showJumpNav = $derived( let jumpSections = $derived.by(() => [
[hasTopTracks, true, hasEpsSingles, hasCompilations, hasPlaylists].filter(Boolean).length > 1 { id: 'about', label: 'About', el: aboutSection, visible: true },
); { id: 'popular', label: 'Popular Tracks', el: topTracksSection, visible: hasTopTracks },
{ id: 'discography', label: 'Discography', el: discographySection, visible: true },
{ id: 'eps', label: 'EPs & Singles', el: epsSinglesSection, visible: hasEpsSingles },
{ id: 'compilations', label: 'Compilations', el: compilationsSection, visible: hasCompilations },
{ id: 'playlists', label: 'Playlists', el: playlistsSection, visible: hasPlaylists },
].filter(section => section.visible));
function scrollToSection(target: HTMLDivElement | null) { let showJumpNav = $derived(jumpSections.length > 1);
function scrollToSection(target: HTMLDivElement | null, id: string) {
activeJumpSection = id;
target?.scrollIntoView({ behavior: 'smooth', block: 'start' }); target?.scrollIntoView({ behavior: 'smooth', block: 'start' });
} }
$effect(() => {
if (!artistDetailEl) return;
if (jumpObserver) {
jumpObserver.disconnect();
jumpObserver = null;
}
if (jumpSections.length === 0) return;
const sectionByElement = new Map<HTMLDivElement, string>();
for (const section of jumpSections) {
if (section.el) {
sectionByElement.set(section.el, section.id);
}
}
const targets = [...sectionByElement.keys()];
if (targets.length === 0) return;
jumpObserver = new IntersectionObserver(
(entries) => {
const visible = entries.filter(entry => entry.isIntersecting);
if (visible.length === 0) return;
visible.sort((a, b) => b.intersectionRatio - a.intersectionRatio);
const targetId = sectionByElement.get(visible[0].target as HTMLDivElement);
if (targetId) {
activeJumpSection = targetId;
}
},
{
root: artistDetailEl,
rootMargin: '-20% 0px -60% 0px',
threshold: [0, 0.2, 0.5, 1]
}
);
targets.forEach(target => jumpObserver?.observe(target));
return () => {
jumpObserver?.disconnect();
jumpObserver = null;
};
});
</script> </script>
<div class="artist-detail"> <div class="artist-detail" bind:this={artistDetailEl}>
<!-- Back Navigation --> <!-- Back Navigation -->
<button class="back-btn" onclick={onBack}> <button class="back-btn" onclick={onBack}>
<ArrowLeft size={16} /> <ArrowLeft size={16} />
@@ -290,7 +348,7 @@
</button> </button>
<!-- Artist Header --> <!-- Artist Header -->
<div class="artist-header"> <div class="artist-header section-anchor" bind:this={aboutSection}>
<!-- Artist Image --> <!-- Artist Image -->
<div class="artist-image-container"> <div class="artist-image-container">
{#if imageError || !artist.image} {#if imageError || !artist.image}
@@ -388,30 +446,16 @@
{#if showJumpNav} {#if showJumpNav}
<div class="jump-nav"> <div class="jump-nav">
<div class="jump-label">Jump to</div> <div class="jump-label">Jump to</div>
<div class="jump-buttons"> <div class="jump-links">
{#if hasTopTracks} {#each jumpSections as section}
<button class="jump-btn" onclick={() => scrollToSection(topTracksSection)}> <button
Popular Tracks class="jump-link"
class:active={activeJumpSection === section.id}
onclick={() => scrollToSection(section.el, section.id)}
>
{section.label}
</button> </button>
{/if} {/each}
<button class="jump-btn" onclick={() => scrollToSection(discographySection)}>
Discography
</button>
{#if hasEpsSingles}
<button class="jump-btn" onclick={() => scrollToSection(epsSinglesSection)}>
EPs & Singles
</button>
{/if}
{#if hasCompilations}
<button class="jump-btn" onclick={() => scrollToSection(compilationsSection)}>
Compilations
</button>
{/if}
{#if hasPlaylists}
<button class="jump-btn" onclick={() => scrollToSection(playlistsSection)}>
Playlists
</button>
{/if}
</div> </div>
</div> </div>
{/if} {/if}
@@ -758,17 +802,16 @@
.jump-nav { .jump-nav {
position: sticky; position: sticky;
top: 8px; top: 0;
z-index: 4; z-index: 4;
display: flex; display: flex;
flex-wrap: wrap; flex-wrap: wrap;
align-items: center; align-items: center;
gap: 10px; gap: 10px;
padding: 10px 12px; padding: 12px 24px;
border-radius: 12px; background-color: var(--bg-primary);
background-color: var(--bg-secondary); border-bottom: 1px solid var(--bg-tertiary);
border: 1px solid var(--bg-tertiary); margin: 0 -24px 16px;
margin-bottom: 16px;
} }
.jump-label { .jump-label {
@@ -778,27 +821,30 @@
letter-spacing: 0.08em; letter-spacing: 0.08em;
} }
.jump-buttons { .jump-links {
display: flex; display: flex;
flex-wrap: wrap; flex-wrap: wrap;
gap: 8px; gap: 14px;
} }
.jump-btn { .jump-link {
padding: 6px 12px; padding: 4px 0;
border-radius: 999px; border: none;
border: 1px solid var(--bg-tertiary); background: none;
background-color: transparent; color: var(--text-muted);
color: var(--text-secondary); font-size: 13px;
font-size: 12px;
cursor: pointer; cursor: pointer;
transition: background-color 150ms ease, color 150ms ease, border-color 150ms ease; border-bottom: 2px solid transparent;
transition: color 150ms ease, border-color 150ms ease;
} }
.jump-btn:hover { .jump-link:hover {
background-color: var(--bg-tertiary); color: var(--text-secondary);
border-color: var(--bg-tertiary); }
.jump-link.active {
color: var(--text-primary); color: var(--text-primary);
border-bottom-color: var(--accent-primary);
} }
.similar-artists { .similar-artists {
@@ -872,7 +918,7 @@
} }
.section-anchor { .section-anchor {
scroll-margin-top: 120px; scroll-margin-top: 140px;
} }
.section-title { .section-title {