feat(slint): in-page search for the artist view

Mirrors Tauri's `.page-search` substring filter — Popular Tracks
(title + artist) and every release-section album (title) hide on
each keystroke when they don't match, restore when the query is
cleared.

UI:
  - Search row added between the artist header and Popular Tracks,
    always visible while artist data is present. Search icon +
    inline TextInput, surface-card background with a thin border
    that highlights on focus. Placeholder "Search this page…".

State:
  - New ArtistActions global with `callback search(string)`, re-
    exported through app.slint so main.rs can wire it.

Controller (artist.rs):
  - Thread-local FULL_TOP_TRACKS and FULL_RELEASE_SECTIONS cache the
    rendered models on the UI thread (same pattern as
    AlbumPageView's FULL_TRACKS), populated in apply_artist so the
    filter never round-trips to the backend.
  - filter_artist(window, query): trim+lowercase the query, then
    rebuild ArtistState.top_tracks and ArtistState.release_sections.
    Sections whose albums all filter out are dropped from the visible
    list, matching Tauri's behavior.

main.rs:
  - ArtistActions::on_search wired to artist::filter_artist (same
    shape as the existing AlbumActions::on_search wiring).

cc
This commit is contained in:
vicrodh committed 2026-05-20 11:27:11 -06:00
1 parent 6642b5ef13
commit 381ab04ef0
5 files changed
+145 -2

No files matched your search

+64
View File
@@ -429,6 +429,16 @@ fn card_to_item(card: CardData) -> AlbumCardItem {
}
}
// Full (unfiltered) rendered models cached on the UI thread so the
// in-page search can rebuild the visible models cheaply on every
// keystroke. Mirrors album::FULL_TRACKS.
thread_local! {
static FULL_TOP_TRACKS: std::cell::RefCell<Vec<AlbumTrackItem>> =
std::cell::RefCell::new(Vec::new());
static FULL_RELEASE_SECTIONS: std::cell::RefCell<Vec<DiscoverSection>> =
std::cell::RefCell::new(Vec::new());
}
/// Apply artist data to the `ArtistState` global. Runs on the Slint event loop.
pub fn apply_artist(window: &AppWindow, data: ArtistData) {
let top_tracks: Vec<AlbumTrackItem> = data
@@ -473,6 +483,15 @@ pub fn apply_artist(window: &AppWindow, data: ArtistData) {
})
.collect();
// Cache the full models on the UI thread so the in-page search
// can rebuild filtered views without re-fetching the artist.
FULL_TOP_TRACKS.with(|cell| {
*cell.borrow_mut() = top_tracks.clone();
});
FULL_RELEASE_SECTIONS.with(|cell| {
*cell.borrow_mut() = release_sections.clone();
});
let state = window.global::<ArtistState>();
state.set_name(data.name.into());
state.set_bio(data.bio.into());
@@ -485,6 +504,51 @@ pub fn apply_artist(window: &AppWindow, data: ArtistData) {
state.set_similar_artists(ModelRc::new(VecModel::from(similar_artists)));
}
/// Filter the visible Popular Tracks (title or artist substring) and
/// release-section albums (title substring) against `query`. An empty
/// query restores the full unfiltered view. Runs on the Slint event
/// loop; called by ArtistActions::on_search from main.rs.
pub fn filter_artist(window: &AppWindow, query: &str) {
let needle = query.trim().to_lowercase();
let filtered_tracks: Vec<AlbumTrackItem> = FULL_TOP_TRACKS.with(|cell| {
cell.borrow()
.iter()
.filter(|track| {
needle.is_empty()
|| track.title.as_str().to_lowercase().contains(&needle)
|| track.artist.as_str().to_lowercase().contains(&needle)
})
.cloned()
.collect()
});
let filtered_sections: Vec<DiscoverSection> = FULL_RELEASE_SECTIONS.with(|cell| {
cell.borrow()
.iter()
.filter_map(|section| {
let kept: Vec<AlbumCardItem> = section
.albums
.iter()
.filter(|album| {
needle.is_empty()
|| album.title.as_str().to_lowercase().contains(&needle)
})
.collect();
if kept.is_empty() {
return None;
}
Some(DiscoverSection {
title: section.title.clone(),
albums: ModelRc::new(VecModel::from(kept)),
})
})
.collect()
});
let state = window.global::<ArtistState>();
state.set_top_tracks(ModelRc::new(VecModel::from(filtered_tracks)));
state.set_release_sections(ModelRc::new(VecModel::from(filtered_sections)));
}
/// Clear artist state before loading a new artist.
pub fn reset_artist(window: &AppWindow) {
let state = window.global::<ArtistState>();
+13
View File
@@ -1190,6 +1190,19 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
});
}
// Artist in-page search — client-side filter over Popular Tracks
// and every release-section album.
{
let weak = window.as_weak();
window
.global::<ArtistActions>()
.on_search(move |query| {
if let Some(w) = weak.upgrade() {
artist::filter_artist(&w, query.as_str());
}
});
}
// Artist network sidebar — no persistence. Default open, user can
// close per-session, and reset_network_sidebar reopens it on every
// artist navigation. The toggle callback stays a no-op on the
+1 -1
View File
@@ -17,7 +17,7 @@ import { LoginScreen } from "login/LoginScreen.slint";
import { AppShell } from "shell/AppShell.slint";
// Re-export the state globals so the Rust layer can populate them.
export { HomeState, AlbumState, ArtistState, NavState, SessionState, SettingsState, AlbumActions, NowPlayingState, QueueState, SearchState, SearchActions, NetworkSidebarState, NetworkSidebarActions } from "state.slint";
export { HomeState, AlbumState, ArtistState, NavState, SessionState, SettingsState, AlbumActions, ArtistActions, NowPlayingState, QueueState, SearchState, SearchActions, NetworkSidebarState, NetworkSidebarActions } from "state.slint";
// Which top-level screen is shown. The app starts on `splash` while it
// restores a saved session, then resolves to `shell` or `login`.
@@ -10,6 +10,7 @@ import { Typography } from "../foundation/typography.slint";
import { Radius } from "../foundation/radius.slint";
import {
ArtistState,
ArtistActions,
AlbumTrackItem,
NavState,
ContentView,
@@ -467,7 +468,64 @@ export component ArtistPageView inherits Rectangle {
}
}
Rectangle { height: 36px; }
Rectangle { height: 24px; }
// --- In-page search ---------------------------------------------
// Single client-side substring filter — applied to Popular
// Tracks (title + artist) and to every release-section
// album title. Same pattern as Tauri's `.page-search` plus
// the AlbumActions.search wiring AlbumPageView uses for
// its track list.
if !ArtistState.loading || ArtistState.top-tracks.length > 0:
Rectangle {
height: 36px;
border-radius: Radius.sm;
background: Theme.surface-card;
border-width: 1px;
border-color: artist-search.has-focus
? Theme.border-subtle
: transparent;
HorizontalLayout {
padding-left: 12px;
padding-right: 12px;
spacing: 8px;
VerticalLayout {
alignment: center;
horizontal-stretch: 0;
QbzIcon {
source: @image-url("../assets/icons/search.svg");
width: 14px;
height: 14px;
tint: Theme.text-muted;
}
}
Rectangle {
horizontal-stretch: 1;
artist-search := TextInput {
width: 100%;
height: 100%;
color: Theme.text-primary;
font-size: Typography.body;
vertical-alignment: center;
single-line: true;
edited => {
ArtistActions.search(self.text);
}
}
Text {
visible: artist-search.text == "";
width: 100%;
height: 100%;
text: @tr("Search this page…");
color: Theme.text-muted;
font-size: Typography.body;
vertical-alignment: center;
}
}
}
}
Rectangle { height: 12px; }
if ArtistState.loading && ArtistState.top-tracks.length == 0: Rectangle {
height: 280px;
+8
View File
@@ -233,6 +233,14 @@ export global ArtistState {
in property <bool> loading: false;
}
// Artist-view actions wired to Rust callbacks.
export global ArtistActions {
// Filter the visible Popular Tracks and release-section albums by
// a query string (client-side substring match, mirrors the album
// track search in AlbumActions).
callback search(string);
}
// Artist network sidebar — Origin / Labels / Similar / Relationships /
// Discovery. The first three lists come from artist state already; this
// global covers the MusicBrainz-driven sections plus the open/closed