diff --git a/crates/qbz-slint/src/home.rs b/crates/qbz-slint/src/home.rs index 113f4a852..532bbeadc 100644 --- a/crates/qbz-slint/src/home.rs +++ b/crates/qbz-slint/src/home.rs @@ -728,43 +728,28 @@ pub fn rerender_active_tab(window: &AppWindow, prefs: &DiscoverPrefs) -> Vec Vec { - let state = window.global::(); - 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::().set_active_tab(tab.into()); + window.global::().set_active_tab(tab.into()); + if tab == "forYou" { - state.set_sections(ModelRc::new(VecModel::from(Vec::::new()))); - state.set_playlists(ModelRc::new(VecModel::from(Vec::::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::(); + hstate.set_playlists(ModelRc::new(VecModel::from(Vec::::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::>(), - ))); - 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)] diff --git a/crates/qbz-slint/src/main.rs b/crates/qbz-slint/src/main.rs index 9b34f6761..1e667e78a 100644 --- a/crates/qbz-slint/src/main.rs +++ b/crates/qbz-slint/src/main.rs @@ -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 = 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 = 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::().set_loading(false); }); artwork::spawn_loads(jobs, weak_for_artwork, image_cache.clone()); diff --git a/crates/qbz-slint/ui/discover/ForYouView.slint b/crates/qbz-slint/ui/discover/ForYouView.slint index 51c0f8ea6..346440775 100644 --- a/crates/qbz-slint/ui/discover/ForYouView.slint +++ b/crates/qbz-slint/ui/discover/ForYouView.slint @@ -1,16 +1,23 @@ -// Discover > For You — dedicated, ordered layout for the For You tab. -// Unlike Home / Editor's Picks (uniform album carousels from -// HomeState.sections), For You mixes album carousels, a track -// carousel, and artist carousels, so it renders from ForYouState. -// Sections hide themselves when empty. +// Discover > For You — ordered, heterogeneous layout for the For You tab. +// Unlike Home / Editor's Picks (uniform album carousels), For You mixes album +// carousels, a track carousel, artist carousels, radio tiles, Qobuz Mixes, and +// the Spotlight, so each row is a different component. +// +// Slice 5: the order + visibility are driven by the prefs configurator. Rust +// pushes DiscoverState.foryou-sections (the ordered ENABLED descriptor ids); a +// single repeater iterates them and an if-chain delegate mounts the right +// component, reading the matching ForYouState field by id. Each arm keeps its +// own data `length > 0` self-hide gate (qobuzMixes excepted — always rendered). +// +// essentialsByGenre is Slice-2c-blocked (no ForYouState.essentials field yet); +// Rust drops it from the descriptor list, so there is intentionally no arm for +// it here. It returns automatically once Slice 2c adds the field + an arm. // // Reuses the shared cards/carousels — no new card components here. -// Qobuz Mixes, Radio Stations, Spotlight, and the reco-DB sections -// (More from library, Rediscover) are later increments. import { Theme } from "../foundation/semantic-colors.slint"; import { Typography } from "../foundation/typography.slint"; -import { ForYouState, RadioStationItem } from "../state.slint"; +import { ForYouState, RadioStationItem, DiscoverState } from "../state.slint"; import { Carousel } from "Carousel.slint"; import { SlimCarousel } from "SlimCarousel.slint"; import { ArtistCarousel } from "ArtistCarousel.slint"; @@ -30,11 +37,8 @@ export component ForYouView inherits VerticalLayout { callback open-mix(string); // Progressive load: while the first lazy load is in flight, show the - // skeleton Home uses (the Qobuz Mixes tiles stay — they're static). It - // hides as soon as ANY content paints — the recently-played sections - // render first (local, instant), the rest fill in via each section's own - // `if length > 0` gate. The page-level `loading` latch only keeps the - // skeleton up while every backing section is still empty. + // skeleton Home uses (the Qobuz Mixes tiles stay — they're static). It hides + // as soon as ANY content paints. Static, order-independent (top while empty). property show-skeleton: ForYouState.loading && ForYouState.release-watch.albums.length == 0 @@ -45,156 +49,165 @@ export component ForYouView inherits VerticalLayout { spacing: 40px; alignment: start; - // 0. Qobuz Mixes (static navigation tiles). - QobuzMixesRow { - open-mix(which) => { - root.open-mix(which); - } - } - if root.show-skeleton: HomeSkeleton { } - // 1. Release Watch. - if ForYouState.release-watch.albums.length > 0: Carousel { - section: ForYouState.release-watch; - album-clicked(id) => { - root.open-album(id); - } - media-action(kind, id, action) => { - root.media-action(kind, id, action); - } - } + // Prefs-driven loop. DiscoverState.foryou-sections = enabled ids in pref + // order (recomputed in Rust). Delegate = single-root VerticalLayout whose + // inner if-chain mounts the right component + binds the matching global; + // exactly one inner `if` matches per descriptor id, so each row resolves to + // one visible child (or none, when its data is empty and it self-hides). + for desc in DiscoverState.foryou-sections: VerticalLayout { + spacing: 0px; - // 1b. Radio Stations — album-seeded radio tiles. - if ForYouState.radio-stations.length > 0: VerticalLayout { - spacing: 12px; - Text { - text: @tr("Radio Stations"); - color: Theme.text-primary; - font-size: 18px; - font-weight: Typography.semibold; + // qobuzMixes — static navigation tiles, ALWAYS rendered (no data gate). + if desc.id == "qobuzMixes": QobuzMixesRow { + open-mix(which) => { + root.open-mix(which); + } } - Rectangle { - height: 234px; - clip: true; - radio-flick := Flickable { - width: 100%; - height: parent.height; - viewport-width: ForYouState.radio-stations.length * (200px + 32px); - viewport-height: self.height; - HorizontalLayout { - spacing: 32px; - alignment: start; - for st in ForYouState.radio-stations: RadioCard { - seed-title: st.title; - seed-subtitle: st.artist; - label: "RADIO"; - artwork: st.artwork; - clicked => { - root.start-radio-album(st.album-id); - } - play => { - root.start-radio-album(st.album-id); + + // releaseWatch — album carousel. + if desc.id == "releaseWatch" && ForYouState.release-watch.albums.length > 0: Carousel { + section: ForYouState.release-watch; + album-clicked(id) => { + root.open-album(id); + } + media-action(kind, id, action) => { + root.media-action(kind, id, action); + } + } + + // radioStations — album-seeded radio tiles (bespoke Flickable body). + if desc.id == "radioStations" && ForYouState.radio-stations.length > 0: VerticalLayout { + spacing: 12px; + Text { + text: @tr("Radio Stations"); + color: Theme.text-primary; + font-size: 18px; + font-weight: Typography.semibold; + } + Rectangle { + height: 234px; + clip: true; + radio-flick := Flickable { + width: 100%; + height: parent.height; + viewport-width: ForYouState.radio-stations.length * (200px + 32px); + viewport-height: self.height; + HorizontalLayout { + spacing: 32px; + alignment: start; + for st in ForYouState.radio-stations: RadioCard { + seed-title: st.title; + seed-subtitle: st.artist; + label: "RADIO"; + artwork: st.artwork; + clicked => { + root.start-radio-album(st.album-id); + } + play => { + root.start-radio-album(st.album-id); + } } } } } } - } - // 2. Recently Played Tracks. - if ForYouState.recent-tracks.length > 0: SlimCarousel { - title: @tr("Recently Played Tracks"); - items: ForYouState.recent-tracks; - item-clicked(id) => { - root.play-track(id); + // continueListening — recently-played tracks slim carousel. + if desc.id == "continueListening" && ForYouState.recent-tracks.length > 0: SlimCarousel { + title: @tr("Recently Played Tracks"); + items: ForYouState.recent-tracks; + item-clicked(id) => { + root.play-track(id); + } } - } - // 3. Recently Played Albums. - if ForYouState.recent-albums.albums.length > 0: Carousel { - section: ForYouState.recent-albums; - album-clicked(id) => { - root.open-album(id); + // recentlyPlayedAlbums — album carousel. + if desc.id == "recentlyPlayedAlbums" && ForYouState.recent-albums.albums.length > 0: Carousel { + section: ForYouState.recent-albums; + album-clicked(id) => { + root.open-album(id); + } + media-action(kind, id, action) => { + root.media-action(kind, id, action); + } } - media-action(kind, id, action) => { - root.media-action(kind, id, action); - } - } - // 4. Your Top Artists. - if ForYouState.top-artists.length > 0: ArtistCarousel { - title: @tr("Your Top Artists"); - artists: ForYouState.top-artists; - artist-clicked(id) => { - root.open-artist(id); + // topArtists — artist carousel. + if desc.id == "topArtists" && ForYouState.top-artists.length > 0: ArtistCarousel { + title: @tr("Your Top Artists"); + artists: ForYouState.top-artists; + artist-clicked(id) => { + root.open-artist(id); + } + media-action(kind, id, action) => { + root.media-action(kind, id, action); + } } - media-action(kind, id, action) => { - root.media-action(kind, id, action); - } - } - // 6. Favorite Albums. - if ForYouState.favorite-albums.albums.length > 0: Carousel { - section: ForYouState.favorite-albums; - album-clicked(id) => { - root.open-album(id); + // favoriteAlbums — album carousel. + if desc.id == "favoriteAlbums" && ForYouState.favorite-albums.albums.length > 0: Carousel { + section: ForYouState.favorite-albums; + album-clicked(id) => { + root.open-album(id); + } + media-action(kind, id, action) => { + root.media-action(kind, id, action); + } } - media-action(kind, id, action) => { - root.media-action(kind, id, action); - } - } - // 5. More From Your Library. - if ForYouState.more-from-library.albums.length > 0: Carousel { - section: ForYouState.more-from-library; - album-clicked(id) => { - root.open-album(id); + // similarAlbums — "More From Your Library" album carousel. + if desc.id == "similarAlbums" && ForYouState.more-from-library.albums.length > 0: Carousel { + section: ForYouState.more-from-library; + album-clicked(id) => { + root.open-album(id); + } + media-action(kind, id, action) => { + root.media-action(kind, id, action); + } } - media-action(kind, id, action) => { - root.media-action(kind, id, action); - } - } - // 6. Rediscover Your Library. - if ForYouState.rediscover.albums.length > 0: Carousel { - section: ForYouState.rediscover; - album-clicked(id) => { - root.open-album(id); + // rediscoverLibrary — album carousel. + if desc.id == "rediscoverLibrary" && ForYouState.rediscover.albums.length > 0: Carousel { + section: ForYouState.rediscover; + album-clicked(id) => { + root.open-album(id); + } + media-action(kind, id, action) => { + root.media-action(kind, id, action); + } } - media-action(kind, id, action) => { - root.media-action(kind, id, action); - } - } - // 6. Artists to Follow. - if ForYouState.artists-to-follow.length > 0: ArtistCarousel { - title: @tr("Artists to Follow"); - artists: ForYouState.artists-to-follow; - artist-clicked(id) => { - root.open-artist(id); + // artistsToFollow — artist carousel. + if desc.id == "artistsToFollow" && ForYouState.artists-to-follow.length > 0: ArtistCarousel { + title: @tr("Artists to Follow"); + artists: ForYouState.artists-to-follow; + artist-clicked(id) => { + root.open-artist(id); + } + media-action(kind, id, action) => { + root.media-action(kind, id, action); + } } - media-action(kind, id, action) => { - root.media-action(kind, id, action); - } - } - // 6. Spotlight. - if ForYouState.spotlight-visible: Spotlight { - open-artist(id) => { - root.open-artist(id); - } - open-album(id) => { - root.open-album(id); - } - play-top-tracks(id) => { - root.play-top-tracks(id); - } - start-radio(id) => { - root.start-radio(id); - } - media-action(kind, id, action) => { - root.media-action(kind, id, action); + // artistSpotlight — the Spotlight panel. + if desc.id == "artistSpotlight" && ForYouState.spotlight-visible: Spotlight { + open-artist(id) => { + root.open-artist(id); + } + open-album(id) => { + root.open-album(id); + } + play-top-tracks(id) => { + root.play-top-tracks(id); + } + start-radio(id) => { + root.start-radio(id); + } + media-action(kind, id, action) => { + root.media-action(kind, id, action); + } } } } diff --git a/crates/qbz-slint/ui/discover/HomeView.slint b/crates/qbz-slint/ui/discover/HomeView.slint index a160296bb..f9f2c0558 100644 --- a/crates/qbz-slint/ui/discover/HomeView.slint +++ b/crates/qbz-slint/ui/discover/HomeView.slint @@ -8,7 +8,7 @@ import { Theme } from "../foundation/semantic-colors.slint"; import { Typography } from "../foundation/typography.slint"; -import { HomeState, HomeActions, GenreFilterState, GenreFilterActions, NavState, ContentView } from "../state.slint"; +import { HomeState, HomeActions, DiscoverState, DiscoverActions, GenreFilterState, GenreFilterActions, NavState, ContentView } from "../state.slint"; import { Carousel } from "Carousel.slint"; import { SlimCarousel } from "SlimCarousel.slint"; import { PlaylistCarousel } from "PlaylistCarousel.slint"; @@ -273,40 +273,110 @@ export component HomeView inherits Rectangle { spacing: 40px; alignment: start; - if HomeState.active-tab != "forYou" + // Loading skeleton: shown while a discover load is in flight and + // the active tab's descriptor list is still empty (For You has + // its own skeleton inside ForYouView). + if DiscoverState.active-tab != "forYou" && HomeState.loading - && HomeState.sections.length == 0: HomeSkeleton { } + && DiscoverState.home-sections.length == 0 + && DiscoverState.editor-sections.length == 0: HomeSkeleton { } - for section in HomeState.sections: Carousel { - section: section; - show-view-all: section.endpoint != ""; - album-clicked(id) => { - root.album-clicked(id); - } - media-action(kind, id, action) => { - root.media-action(kind, id, action); - } - view-all-clicked => { - root.discover-view-all(section.endpoint, section.title); - } - } + // Prefs-driven render loop (Slice 5). Rust pushes the ordered + // ENABLED descriptor list for the active tab (home-sections / + // editor-sections); the For You tab's lists are pushed empty so + // this repeater renders nothing for it (the unconditional- + // repeater form — content is controlled purely via the model, + // avoiding an `if cond: for ...`). The delegate is a single-root + // VerticalLayout whose inner if-chain mounts the right component + // and binds the matching data; exactly one arm matches per id. + for desc in (DiscoverState.active-tab == "editorPicks" + ? DiscoverState.editor-sections + : DiscoverState.home-sections): VerticalLayout { + spacing: 0px; - // Qobuz Playlists row — shown on Home + Editor's Picks - // (never For You). body=open, overlay=play (1:1 Tauri). - if HomeState.active-tab != "forYou" - && HomeState.playlists.length > 0: PlaylistCarousel { - title: @tr("Qobuz Playlists"); - playlists: HomeState.playlists; - body-opens: true; - show-view-all: false; - media-action(kind, id, action) => { - root.media-action(kind, id, action); + // Generic album carousels (data embedded in desc.section by + // Rust): newReleases / pressAwards / idealDiscography / + // editorPicks / qobuzissimes, plus mostStreamed when it + // renders as an album carousel (Editor's Picks). + if desc.id == "newReleases" + || desc.id == "pressAwards" + || desc.id == "idealDiscography" + || desc.id == "editorPicks" + || desc.id == "qobuzissimes" + || (desc.id == "mostStreamed" && desc.kind == "albumCarousel"): Carousel { + section: desc.section; + show-view-all: desc.section.endpoint != ""; + album-clicked(id) => { + root.album-clicked(id); + } + media-action(kind, id, action) => { + root.media-action(kind, id, action); + } + view-all-clicked => { + root.discover-view-all(desc.section.endpoint, desc.section.title); + } + } + + // Qobuz Playlists row — body=open, overlay=play (1:1 Tauri). + if desc.id == "qobuzPlaylists" && HomeState.playlists.length > 0: PlaylistCarousel { + title: @tr("Qobuz Playlists"); + playlists: HomeState.playlists; + body-opens: true; + show-view-all: false; + media-action(kind, id, action) => { + root.media-action(kind, id, action); + } + } + + // Recently Played Albums — carousel when it has data, else a + // placeholder (always present on Home, 1:1 Tauri). + if desc.id == "recentlyPlayedAlbums" && HomeState.recent-albums.length > 0: Carousel { + section: { + title: @tr("Recently Played Albums"), + albums: HomeState.recent-albums, + }; + album-clicked(id) => { + root.album-clicked(id); + } + media-action(kind, id, action) => { + root.media-action(kind, id, action); + } + } + if desc.id == "recentlyPlayedAlbums" && HomeState.recent-albums.length == 0: RecentPlaceholder { + title: @tr("Recently Played Albums"); + hint: @tr("Albums you play will appear here."); + } + + // Recently Played Tracks — slim carousel when it has data, + // else a placeholder (continueListening id). + if desc.id == "continueListening" && HomeState.recent.length > 0: SlimCarousel { + title: @tr("Recently Played Tracks"); + items: HomeState.recent; + item-clicked(id) => { + root.media-action("track", id, "play"); + } + } + if desc.id == "continueListening" && HomeState.recent.length == 0: RecentPlaceholder { + title: @tr("Recently Played Tracks"); + hint: @tr("Tracks you play will appear here."); + } + + // Most Streamed on Home renders as the Popular slim grid + // (kind == "slimGrid"); on Editor's Picks it is the album + // carousel handled by the generic arm above. + if desc.id == "mostStreamed" && desc.kind == "slimGrid" + && HomeState.popular.length > 0: SlimCarousel { + title: @tr("Popular albums"); + items: HomeState.popular; + item-clicked(id) => { + root.album-clicked(id); + } } } // For You renders its own ordered, heterogeneous // sections from ForYouState. - if HomeState.active-tab == "forYou": ForYouView { + if DiscoverState.active-tab == "forYou": ForYouView { open-album(id) => { root.album-clicked(id); } @@ -332,56 +402,6 @@ export component HomeView inherits Rectangle { root.media-action("mix", which, "open"); } } - - // The Recently Played + Popular sections below belong - // to the Home tab only; Editor's Picks / For You show - // just their own cached section set above. - - // Recently Played Albums — always present; shows a - // placeholder until the play history has data. - if HomeState.active-tab == "home" - && HomeState.recent-albums.length > 0: Carousel { - section: { - title: @tr("Recently Played Albums"), - albums: HomeState.recent-albums, - }; - album-clicked(id) => { - root.album-clicked(id); - } - media-action(kind, id, action) => { - root.media-action(kind, id, action); - } - } - if HomeState.active-tab == "home" - && HomeState.recent-albums.length == 0: RecentPlaceholder { - title: @tr("Recently Played Albums"); - hint: @tr("Albums you play will appear here."); - } - - // Recently Played Tracks — paginated 4x3 carousel - // (12 per page, up to two pages). - if HomeState.active-tab == "home" - && HomeState.recent.length > 0: SlimCarousel { - title: @tr("Recently Played Tracks"); - items: HomeState.recent; - item-clicked(id) => { - root.media-action("track", id, "play"); - } - } - if HomeState.active-tab == "home" - && HomeState.recent.length == 0: RecentPlaceholder { - title: @tr("Recently Played Tracks"); - hint: @tr("Tracks you play will appear here."); - } - - if HomeState.active-tab == "home" - && HomeState.popular.length > 0: SlimCarousel { - title: @tr("Popular albums"); - items: HomeState.popular; - item-clicked(id) => { - root.album-clicked(id); - } - } } } // Shared scrollbar in the right gutter (homologated cross-view).