feat: move back-to-top to global layout level

Replaced the per-view back-to-top in PlaylistDetailView with a
global one in +page.svelte. Uses capture-phase scroll listener
on .main-content to track scroll from any child view. Appears
after 800px scroll on any view. Resets on view change.
This commit is contained in:
vicrodh committed 2026-02-09 23:08:40 -06:00
1 parent 170b6408f7
commit 7b5a7d963d
2 files changed
+63 -38

No files matched your search

@@ -257,7 +257,6 @@
let trackListEl: HTMLDivElement | null = $state(null);
let trackListScrollTop = $state(0); // scroll position relative to track list top
let trackListViewHeight = $state(800); // visible height of scroll container
let containerScrollTop = $state(0); // raw scroll position of .playlist-detail
// Offline mode state
let offlineStatus = $state<OfflineStatus>(getOfflineStatus());
@@ -1328,7 +1327,6 @@
// Handle scroll from the parent .playlist-detail container
function handlePlaylistScroll(e: Event) {
const container = e.target as HTMLElement;
containerScrollTop = container.scrollTop;
// Save scroll position for navigation restoration
saveScrollPosition('playlist', container.scrollTop);
// Update virtual scroll state relative to the track list position
@@ -1339,12 +1337,6 @@
}
}
function scrollToTop() {
scrollContainer?.scrollTo({ top: 0, behavior: 'smooth' });
}
const showBackToTop = $derived(containerScrollTop > 600 && displayTracks.length > 100);
const sortOptions: { field: SortField; label: string }[] = [
{ field: 'default', label: 'Default' },
{ field: 'title', label: 'Title' },
@@ -2224,11 +2216,6 @@
</ViewTransition>
{/if}
{#if showBackToTop}
<button class="back-to-top" onclick={scrollToTop} title="Back to top">
<ChevronUp size={20} />
</button>
{/if}
</div>
</ViewTransition>
@@ -2985,29 +2972,5 @@
height: 64px;
}
/* Back to top floating button */
.back-to-top {
position: fixed;
bottom: 114px; /* 104px player + 10px gap */
right: 24px;
width: 40px;
height: 40px;
border-radius: 50%;
background: var(--bg-secondary);
border: 1px solid var(--alpha-12);
color: var(--text-secondary);
cursor: pointer;
display: flex;
align-items: center;
justify-content: center;
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
transition: opacity 200ms ease, background 150ms ease, color 150ms ease;
z-index: 10;
}
.back-to-top:hover {
background: var(--bg-tertiary);
color: var(--text-primary);
}
</style>
+63 -1
View File
@@ -1,5 +1,6 @@
<script lang="ts">
import { onMount, onDestroy, tick } from 'svelte';
import { ChevronUp } from 'lucide-svelte';
import { invoke, convertFileSrc } from '@tauri-apps/api/core';
import { listen, emitTo, type UnlistenFn } from '@tauri-apps/api/event';
import { writeText } from '@tauri-apps/plugin-clipboard-manager';
@@ -383,6 +384,36 @@
let pendingWhatsNewRelease = $state<ReleaseInfo | null>(null);
let pendingUpdateRelease = $state<ReleaseInfo | null>(null);
// Global back-to-top button
let mainContentEl: HTMLElement | null = $state(null);
let globalScrollTop = $state(0);
let activeScrollTarget: HTMLElement | null = null;
const showGlobalBackToTop = $derived(globalScrollTop > 800);
$effect(() => {
if (!mainContentEl) return;
const handler = (e: Event) => {
const target = e.target as HTMLElement;
if (target !== mainContentEl) {
globalScrollTop = target.scrollTop;
activeScrollTarget = target;
}
};
mainContentEl.addEventListener('scroll', handler, true);
return () => mainContentEl!.removeEventListener('scroll', handler, true);
});
// Reset scroll state on view change
$effect(() => {
void activeView;
globalScrollTop = 0;
activeScrollTarget = null;
});
function globalScrollToTop() {
activeScrollTarget?.scrollTo({ top: 0, behavior: 'smooth' });
}
// Album, Artist and Label data are fetched, so kept local
let selectedAlbum = $state<AlbumDetail | null>(null);
let selectedArtist = $state<ArtistDetail | null>(null);
@@ -3038,7 +3069,7 @@
<!-- Content Area (main + lyrics sidebar) -->
<div class="content-area">
<!-- Main Content -->
<main class="main-content">
<main class="main-content" bind:this={mainContentEl}>
{#if activeView === 'home'}
{#if offlineStatus.isOffline}
<OfflinePlaceholder
@@ -3367,6 +3398,12 @@
{/if}
</main>
{#if showGlobalBackToTop}
<button class="back-to-top-global" onclick={globalScrollToTop} title="Back to top">
<ChevronUp size={20} />
</button>
{/if}
<!-- Lyrics Sidebar -->
{#if lyricsSidebarVisible}
<LyricsSidebar
@@ -3747,4 +3784,29 @@
background: var(--bg-hover);
}
/* Global back-to-top button */
.back-to-top-global {
position: fixed;
bottom: 114px; /* 104px player + 10px gap */
right: 24px;
width: 40px;
height: 40px;
border-radius: 50%;
background: var(--bg-secondary);
border: 1px solid var(--alpha-12);
color: var(--text-secondary);
cursor: pointer;
display: flex;
align-items: center;
justify-content: center;
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
transition: background 150ms ease, color 150ms ease;
z-index: 50;
}
.back-to-top-global:hover {
background: var(--bg-tertiary);
color: var(--text-primary);
}
</style>