feat(slint/discover): prefs-driven render loop for Home and For You
Replace the fixed Discover layouts with the prefs-driven descriptor repeaters that read DiscoverState's ordered ENABLED section lists, so the configurator's visibility + reorder choices drive what renders. - HomeView.slint: drop `for section in HomeState.sections` + the 5 hardcoded typed blocks; render one repeater over the active tab's descriptor list (editor-sections when active-tab == "editorPicks", else home-sections). The single-root delegate dispatches on desc.id: generic album carousels bind the embedded desc.section; qobuzPlaylists / continueListening / recentlyPlayedAlbums / mostStreamed(slim) bind HomeState fields and keep their length gates + placeholders. `if forYou: ForYouView` stays a static sibling. - ForYouView.slint: replace the fixed if-sequence with a descriptor repeater over foryou-sections; each arm reads the typed ForYouState field by id and keeps its own length gate (qobuzMixes excepted — always rendered). The skeleton stays a static sibling. essentialsByGenre has no arm (Slice-2c-blocked; Rust drops it from the list). - home.rs: select_tab writes DiscoverState.active-tab (single source of truth, alongside the kept HomeState.active-tab pill bindings) and re-renders the active tab from the cache via the descriptor lists; apply_home pushes the descriptor lists once the cache is populated. - main.rs: the initial discover load fires album-section artwork via the descriptor-targeted jobs returned by select_tab (DiscoverSectionAlbum), spawned on the UI thread; slim-grid / recent-album / playlist covers still target the HomeState fields the fixed arms render. Build-time verifications to confirm (documented in the .slint comments): the for-over-ternary-model form compiles, and an empty delegate does not double the outer 40px spacing (Rust already drops data-empty album ids — policy b). cc
This commit is contained in:
4 files changed
+289
-264
No files matched your search
@@ -728,43 +728,28 @@ pub fn rerender_active_tab(window: &AppWindow, prefs: &DiscoverPrefs) -> Vec<Art
|
||||
jobs
|
||||
}
|
||||
|
||||
/// Switch the visible Discover tab. Reads the cached section set for
|
||||
/// `tab` ("home" | "editorPicks" | "forYou"), swaps it into
|
||||
/// HomeState.sections, and returns the artwork jobs to re-fire. No
|
||||
/// re-fetch — the sets were cached by the last apply_home.
|
||||
/// Switch the visible Discover tab ("home" | "editorPicks" | "forYou"). Writes
|
||||
/// the active tab into BOTH HomeState (Slice-3 pill bindings) and DiscoverState
|
||||
/// (the prefs-driven render loop + the configurator target — single source of
|
||||
/// truth), then re-renders the active tab from the cached section data via the
|
||||
/// descriptor lists. No re-fetch. For You renders from its own ForYouView /
|
||||
/// ForYouState; the Home/Editor descriptor lists are pushed empty for it.
|
||||
pub fn select_tab(window: &AppWindow, tab: &str) -> Vec<ArtworkJob> {
|
||||
let state = window.global::<HomeState>();
|
||||
state.set_active_tab(tab.into());
|
||||
// For You renders from its own dedicated ForYouView/ForYouState,
|
||||
// not HomeState.sections — clear the uniform section list so the
|
||||
// home-content `for` renders nothing for that tab.
|
||||
window.global::<HomeState>().set_active_tab(tab.into());
|
||||
window.global::<DiscoverState>().set_active_tab(tab.into());
|
||||
|
||||
if tab == "forYou" {
|
||||
state.set_sections(ModelRc::new(VecModel::from(Vec::<DiscoverSection>::new())));
|
||||
state.set_playlists(ModelRc::new(VecModel::from(Vec::<SearchPlaylistItem>::new())));
|
||||
// Push the For You descriptor list + drive Home/Editor empty, and clear
|
||||
// the legacy HomeState models so nothing lingers under the For You view.
|
||||
let prefs = crate::discover_prefs::prefs_snapshot();
|
||||
crate::discover_prefs::push_descriptors(window, &prefs);
|
||||
let hstate = window.global::<HomeState>();
|
||||
hstate.set_playlists(ModelRc::new(VecModel::from(Vec::<SearchPlaylistItem>::new())));
|
||||
return Vec::new();
|
||||
}
|
||||
TAB_SECTIONS.with(|cell| {
|
||||
let cache = cell.borrow();
|
||||
let set = match tab {
|
||||
"editorPicks" => &cache.editor,
|
||||
_ => &cache.home,
|
||||
};
|
||||
state.set_sections(ModelRc::new(VecModel::from(build_sections(set))));
|
||||
// Swap the Qobuz Playlists row for the active tab, and append its
|
||||
// single-cover artwork jobs onto the section jobs (one combined return
|
||||
// → the on_select_tab call sites' spawn_loads covers both with no
|
||||
// call-site change).
|
||||
let pls = match tab {
|
||||
"editorPicks" => &cache.editor_playlists,
|
||||
_ => &cache.home_playlists,
|
||||
};
|
||||
state.set_playlists(ModelRc::new(VecModel::from(
|
||||
pls.iter().map(playlist_to_item).collect::<Vec<_>>(),
|
||||
)));
|
||||
let mut jobs = section_artwork_jobs(set);
|
||||
jobs.extend(playlist_artwork_jobs(pls));
|
||||
jobs
|
||||
})
|
||||
|
||||
let prefs = crate::discover_prefs::prefs_snapshot();
|
||||
rerender_active_tab(window, &prefs)
|
||||
}
|
||||
|
||||
/// Convert worker-thread home data into Slint models and push them onto
|
||||
@@ -813,6 +798,13 @@ pub fn apply_home(window: &AppWindow, data: HomeData) {
|
||||
state.set_recent(ModelRc::new(VecModel::from(recent)));
|
||||
state.set_recent_albums(ModelRc::new(VecModel::from(recent_albums)));
|
||||
state.set_playlists(ModelRc::new(VecModel::from(home_playlists)));
|
||||
|
||||
// Push the prefs-driven descriptor lists now that the section cache is
|
||||
// populated, so the Home/Editor render loop reflects the fresh data (the
|
||||
// following select_tab re-pushes for the active tab; this keeps the lists
|
||||
// correct even if select_tab is not called).
|
||||
let prefs = crate::discover_prefs::prefs_snapshot();
|
||||
crate::discover_prefs::push_descriptors(window, &prefs);
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
|
||||
@@ -451,18 +451,14 @@ async fn reload_home(
|
||||
|
||||
match home::load_home(runtime, genre_ids).await {
|
||||
Ok(data) => {
|
||||
// Artwork for the active tab's section set (Section-targeted,
|
||||
// so it lands in HomeState.sections once select_tab swaps it
|
||||
// in below). Built before `data` is moved. For You renders
|
||||
// from its own view, so it has no discover-index section
|
||||
// set here.
|
||||
let empty: Vec<home::SectionData> = Vec::new();
|
||||
let active_set = match active_tab.as_str() {
|
||||
"editorPicks" => &data.editor_sections,
|
||||
"forYou" => &empty,
|
||||
_ => &data.sections,
|
||||
};
|
||||
let mut jobs = home::section_artwork_jobs(active_set);
|
||||
// Album-carousel covers are now fired by select_tab below: the
|
||||
// prefs-driven render loop draws Home/Editor album sections from the
|
||||
// DiscoverState descriptor lists, so their artwork is descriptor-
|
||||
// targeted (DiscoverSectionAlbum) and returned by select_tab once the
|
||||
// lists are built. Here we only prebuild the artwork for the models
|
||||
// that still bind HomeState fields (slim grids, recent albums,
|
||||
// playlists), which select_tab does not rebuild.
|
||||
let mut jobs: Vec<artwork::ArtworkJob> = Vec::new();
|
||||
// Home-only slim grids (their models are populated regardless
|
||||
// of the visible tab; harmless to prefetch).
|
||||
jobs.extend(data.popular.iter().enumerate().filter_map(|(idx, slim)| {
|
||||
@@ -509,11 +505,15 @@ async fn reload_home(
|
||||
let weak_for_artwork = weak.clone();
|
||||
let weak_for_local = weak.clone();
|
||||
let image_cache_local = image_cache.clone();
|
||||
let image_cache_sections = image_cache.clone();
|
||||
let _ = weak.upgrade_in_event_loop(move |w| {
|
||||
home::apply_home(&w, data);
|
||||
// apply_home shows the home set; swap to the requested
|
||||
// tab (no-op when it is "home").
|
||||
home::select_tab(&w, &active_tab);
|
||||
// apply_home caches the section sets + pushes the descriptor
|
||||
// lists; select_tab renders the requested tab from them and
|
||||
// returns the descriptor-targeted album-section artwork jobs
|
||||
// (DiscoverSectionAlbum) — spawn them here, on the UI thread.
|
||||
let section_jobs = home::select_tab(&w, &active_tab);
|
||||
artwork::spawn_loads(section_jobs, w.as_weak(), image_cache_sections.clone());
|
||||
w.global::<HomeState>().set_loading(false);
|
||||
});
|
||||
artwork::spawn_loads(jobs, weak_for_artwork, image_cache.clone());
|
||||
|
||||
Reference in new issue
Block a user