From 07aa9908e86deef4bcfbea6dd161c716b5652247 Mon Sep 17 00:00:00 2001 From: Connor Johnstone Date: Tue, 31 Mar 2026 13:18:18 -0400 Subject: [PATCH] added the scroll bar --- frontend/src/pages/library.rs | 57 +++++++++++++++++++++++++++++++-- frontend/src/pages/playlists.rs | 2 +- frontend/style.css | 34 ++++++++++++++++++++ src/routes/artists.rs | 6 +++- 4 files changed, 95 insertions(+), 4 deletions(-) diff --git a/frontend/src/pages/library.rs b/frontend/src/pages/library.rs index 113a920..eee107b 100644 --- a/frontend/src/pages/library.rs +++ b/frontend/src/pages/library.rs @@ -1,3 +1,6 @@ +use std::collections::{HashMap, HashSet}; + +use wasm_bindgen::JsCast; use yew::prelude::*; use yew_router::prelude::*; @@ -17,7 +20,7 @@ pub fn library_page() -> Html { let artists = artists.clone(); let error = error.clone(); wasm_bindgen_futures::spawn_local(async move { - match api::list_artists(200, 0).await { + match api::list_artists(0, 0).await { Ok(a) => artists.set(Some(a)), Err(e) => error.set(Some(e.0)), } @@ -40,6 +43,33 @@ pub fn library_page() -> Html { return html! {

{ "Loading..." }

}; }; + // Pre-compute which artist IDs are first in their letter group (for anchor IDs) + let mut seen_letters = HashSet::new(); + let first_of_letter: HashMap = artists + .iter() + .filter_map(|a| { + let first = a.name.chars().next().unwrap_or('#').to_ascii_uppercase(); + let letter = if first.is_ascii_alphabetic() { + first + } else { + '#' + }; + if seen_letters.insert(letter) { + Some((a.id, letter)) + } else { + None + } + }) + .collect(); + let active_letters: HashSet = first_of_letter.values().copied().collect(); + + // Build scroll track letter data + let letters: Vec = "#ABCDEFGHIJKLMNOPQRSTUVWXYZ".chars().collect(); + let scroll_track_items: Vec<(String, bool)> = letters + .iter() + .map(|&c| (c.to_string(), active_letters.contains(&c))) + .collect(); + html! {