From 3cd9b99153a4137d30905c05cb672723060e8244 Mon Sep 17 00:00:00 2001 From: vicrodh <103399283+vicrodh@users.noreply.github.com> Date: Mon, 9 Feb 2026 22:53:31 -0600 Subject: [PATCH] feat(playlist): add back-to-top button for large playlists Floating button appears after scrolling 600px on playlists with 100+ tracks. Smooth scrolls back to top. Positioned bottom-right with sticky positioning inside the scroll container. --- .../views/PlaylistDetailView.svelte | 39 +++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/src/lib/components/views/PlaylistDetailView.svelte b/src/lib/components/views/PlaylistDetailView.svelte index dcec74725..e69d4f75d 100644 --- a/src/lib/components/views/PlaylistDetailView.svelte +++ b/src/lib/components/views/PlaylistDetailView.svelte @@ -257,6 +257,7 @@ 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(getOfflineStatus()); @@ -1327,6 +1328,7 @@ // 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 @@ -1337,6 +1339,12 @@ } } + 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' }, @@ -2210,6 +2218,12 @@ {/if} {/if} + + {#if showBackToTop} + + {/if} @@ -2962,5 +2976,30 @@ display: block; } + /* Back to top floating button */ + .back-to-top { + position: sticky; + bottom: 24px; + float: right; + margin-right: 8px; + 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); + }