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.
This commit is contained in:
vicrodh committed 2026-02-09 22:53:31 -06:00
1 parent 8270de2e5e
commit 3cd9b99153
1 file changed
+39
@@ -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<OfflineStatus>(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}
</ViewTransition>
{/if}
{#if showBackToTop}
<button class="back-to-top" onclick={scrollToTop} title="Back to top">
<ChevronUp size={20} />
</button>
{/if}
</div>
</ViewTransition>
@@ -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);
}
</style>