feat(slint): dedicated For You view with artist sections

Replaces the ad-hoc For You (a single album set crammed into
HomeState.sections) with a dedicated, ordered ForYouView/ForYouState
so the tab can mix album, track, and artist carousels — closer to
Tauri's For You. Lazy-loaded once on first open.

Sections (all reuse existing cards, no new card components):
  - Release Watch (album Carousel) — get_release_watch.
  - Recently Played Tracks (SlimCarousel) — local play-history.
  - Recently Played Albums (album Carousel) — local play-history.
  - Your Top Artists (ArtistCarousel) — the user's favorite artists
    via get_favorites.
  - Artists to Follow (ArtistCarousel) — similar artists seeded from
    a few favorites via get_similar_artists, excluding ones already
    followed (Follow chip shown).

Plumbing:
  - crate::foryou controller (load/apply/artwork). Five ForYou
    artwork targets feed the dedicated models.
  - select_tab("forYou") clears HomeState.sections (the home-content
    `for` renders nothing) and the For You content comes from
    ForYouView; HomeView routes the For You tab to ForYouView and
    gains an open-artist callback (wired through AppShell).
  - ensure_for_you_loaded lazy-loads on tab open (pill, header
    dropdown, and back/forward history).
  - home.rs no longer builds a For You section set (removed the
    redundant release-watch/favorites fetch on every home load).

Still to come (next increments): Qobuz Mixes row, Radio Stations
(old card design), Spotlight hero, and the reco-DB sections (More
from library, Rediscover) — those need backend the MVP lacks or the
mix detail views.

cc
This commit is contained in:
vicrodh committed 2026-05-21 00:33:11 -06:00
1 parent 066890a7dd
commit 85ecf79a2d
9 files changed
+556 -113

No files matched your search

+45
View File
@@ -66,6 +66,16 @@ pub enum ArtworkTarget {
FavoriteArtist { index: usize },
/// A card in FavoritesState.playlists[index].
FavoritePlaylist { index: usize },
/// A card in ForYouState.release-watch.albums[index].
ForYouReleaseWatch { index: usize },
/// A card in ForYouState.recent-albums.albums[index].
ForYouRecentAlbum { index: usize },
/// A row in ForYouState.recent-tracks[index].
ForYouRecentTrack { index: usize },
/// A tile in ForYouState.top-artists[index].
ForYouTopArtist { index: usize },
/// A tile in ForYouState.artists-to-follow[index].
ForYouToFollow { index: usize },
}
/// An artwork download job: which card, and the image URL.
@@ -403,5 +413,40 @@ fn apply_artwork(
model.set_row_data(index, item);
}
}
ArtworkTarget::ForYouReleaseWatch { index } => {
let model = window.global::<crate::ForYouState>().get_release_watch().albums;
if let Some(mut item) = model.row_data(index) {
item.artwork = image;
model.set_row_data(index, item);
}
}
ArtworkTarget::ForYouRecentAlbum { index } => {
let model = window.global::<crate::ForYouState>().get_recent_albums().albums;
if let Some(mut item) = model.row_data(index) {
item.artwork = image;
model.set_row_data(index, item);
}
}
ArtworkTarget::ForYouRecentTrack { index } => {
let model = window.global::<crate::ForYouState>().get_recent_tracks();
if let Some(mut item) = model.row_data(index) {
item.artwork = image;
model.set_row_data(index, item);
}
}
ArtworkTarget::ForYouTopArtist { index } => {
let model = window.global::<crate::ForYouState>().get_top_artists();
if let Some(mut item) = model.row_data(index) {
item.artwork = image;
model.set_row_data(index, item);
}
}
ArtworkTarget::ForYouToFollow { index } => {
let model = window.global::<crate::ForYouState>().get_artists_to_follow();
if let Some(mut item) = model.row_data(index) {
item.artwork = image;
model.set_row_data(index, item);
}
}
}
}
+308
View File
@@ -0,0 +1,308 @@
//! Discover > For You controller.
//!
//! Loads the personalized For You sections the Slint MVP can source
//! today and pushes them into `ForYouState`. Each section reuses an
//! existing card component (album Carousel, SlimCarousel, artist
//! ArtistCarousel). Lazy: the tab loads once on first open.
//!
//! Backed sections: Release Watch (get_release_watch), Recently
//! Played Tracks / Albums (local play-history), Your Top Artists
//! (favorites), Artists to Follow (similar artists seeded from
//! favorites). The reco-DB sections (Qobuz mixes, more from library,
//! rediscover, spotlight, radio) are separate later increments.
use std::collections::HashSet;
use std::sync::Arc;
use qbz_app::shell::AppRuntime;
use qbz_core::FrontendAdapter;
use qbz_models::{Album, Artist};
use slint::{ComponentHandle, ModelRc, VecModel};
use crate::artwork::{ArtworkJob, ArtworkTarget};
use crate::{AlbumCardItem, AppWindow, DiscoverSection, ForYouState, SlimItem};
const ARTIST_SEEDS: usize = 4;
const SIMILAR_PER_SEED: u32 = 10;
const FOLLOW_MAX: usize = 18;
pub struct ForYouData {
pub release_watch: Vec<AlbumCard>,
pub recent_albums: Vec<AlbumCard>,
pub recent_tracks: Vec<TrackSlim>,
pub top_artists: Vec<ArtistSlim>,
pub artists_to_follow: Vec<ArtistSlim>,
}
#[derive(Clone)]
pub struct AlbumCard {
pub id: String,
pub title: String,
pub artist: String,
pub year: String,
pub quality_tier: String,
pub quality_label: String,
pub artwork_url: String,
}
#[derive(Clone)]
pub struct TrackSlim {
pub id: String,
pub title: String,
pub subtitle: String,
pub artwork_url: String,
}
#[derive(Clone)]
pub struct ArtistSlim {
pub id: String,
pub name: String,
pub artwork_url: String,
pub following: bool,
}
fn map_album(album: Album) -> AlbumCard {
let year = album
.release_date_original
.as_deref()
.and_then(|s| s.get(..4).map(|y| y.to_string()))
.unwrap_or_default();
let quality_tier = match album.maximum_bit_depth {
Some(d) if d >= 24 => "hires",
Some(_) => "cd",
None => "",
}
.to_string();
let quality_label = match (album.maximum_bit_depth, album.maximum_sampling_rate) {
(Some(bd), Some(sr)) => format!("{}-bit / {} kHz", bd, sr),
_ => String::new(),
};
AlbumCard {
id: album.id,
title: album.title,
artist: album.artist.name,
year,
quality_tier,
quality_label,
artwork_url: album.image.best().cloned().unwrap_or_default(),
}
}
fn map_artist(artist: Artist, following: bool) -> ArtistSlim {
ArtistSlim {
id: artist.id.to_string(),
name: artist.name,
artwork_url: artist
.image
.and_then(|img| img.best().cloned())
.unwrap_or_default(),
following,
}
}
pub async fn load_for_you<A>(runtime: &Arc<AppRuntime<A>>) -> ForYouData
where
A: FrontendAdapter + Send + Sync + 'static,
{
// Release Watch — new releases from followed artists.
let release_watch: Vec<AlbumCard> = match runtime
.core()
.get_release_watch("artists", 18, 0)
.await
{
Ok(page) => page.items.into_iter().map(map_album).collect(),
Err(_) => Vec::new(),
};
// Recently played — local play-history store.
let recent_albums: Vec<AlbumCard> = crate::recently::load_albums()
.into_iter()
.map(|a| AlbumCard {
id: a.id,
title: a.title,
artist: a.artist,
year: String::new(),
quality_tier: a.quality_tier,
quality_label: a.quality_label,
artwork_url: a.artwork_url,
})
.collect();
let recent_tracks: Vec<TrackSlim> = crate::recently::load()
.into_iter()
.take(24)
.map(|t| TrackSlim {
id: t.id,
title: t.title,
subtitle: t.subtitle,
artwork_url: t.artwork_url,
})
.collect();
// Your Top Artists — the user's favorite artists.
let fav_artists: Vec<Artist> = match runtime.core().get_favorites("artists", 50, 0).await {
Ok(value) => {
let items = value
.get("artists")
.and_then(|b| b.get("items"))
.cloned()
.unwrap_or(serde_json::Value::Null);
serde_json::from_value(items).unwrap_or_default()
}
Err(_) => Vec::new(),
};
let favorite_ids: HashSet<u64> = fav_artists.iter().map(|a| a.id).collect();
let top_artists: Vec<ArtistSlim> = fav_artists
.iter()
.take(18)
.cloned()
.map(|a| map_artist(a, true))
.collect();
// Artists to Follow — similar artists seeded from a few favorites,
// excluding ones already followed.
let mut to_follow: Vec<ArtistSlim> = Vec::new();
let mut seen: HashSet<u64> = favorite_ids.clone();
for seed in fav_artists.iter().take(ARTIST_SEEDS) {
if to_follow.len() >= FOLLOW_MAX {
break;
}
if let Ok(page) = runtime
.core()
.get_similar_artists(seed.id, SIMILAR_PER_SEED, 0)
.await
{
for artist in page.items {
if seen.insert(artist.id) {
to_follow.push(map_artist(artist, false));
if to_follow.len() >= FOLLOW_MAX {
break;
}
}
}
}
}
ForYouData {
release_watch,
recent_albums,
recent_tracks,
top_artists,
artists_to_follow: to_follow,
}
}
fn album_items(cards: &[AlbumCard]) -> Vec<AlbumCardItem> {
cards
.iter()
.map(|c| AlbumCardItem {
id: c.id.clone().into(),
title: c.title.clone().into(),
artist: c.artist.clone().into(),
genre: "".into(),
year: c.year.clone().into(),
quality_tier: c.quality_tier.clone().into(),
quality_label: c.quality_label.clone().into(),
ribbon: "".into(),
ribbon_kind: "".into(),
artwork_url: c.artwork_url.clone().into(),
artwork: slint::Image::default(),
})
.collect()
}
fn artist_items(artists: &[ArtistSlim]) -> Vec<SlimItem> {
artists
.iter()
.map(|a| SlimItem {
id: a.id.clone().into(),
title: a.name.clone().into(),
subtitle: "".into(),
rank: "".into(),
artwork_url: a.artwork_url.clone().into(),
artwork: slint::Image::default(),
following: a.following,
})
.collect()
}
fn section(title: &str, cards: &[AlbumCard]) -> DiscoverSection {
DiscoverSection {
title: title.into(),
albums: ModelRc::new(VecModel::from(album_items(cards))),
}
}
pub fn apply_for_you(window: &AppWindow, data: &ForYouData) {
let state = window.global::<ForYouState>();
state.set_release_watch(section("Release Watch", &data.release_watch));
state.set_recent_albums(section("Recently Played Albums", &data.recent_albums));
let tracks: Vec<SlimItem> = data
.recent_tracks
.iter()
.map(|t| SlimItem {
id: t.id.clone().into(),
title: t.title.clone().into(),
subtitle: t.subtitle.clone().into(),
rank: "".into(),
artwork_url: t.artwork_url.clone().into(),
artwork: slint::Image::default(),
following: false,
})
.collect();
state.set_recent_tracks(ModelRc::new(VecModel::from(tracks)));
state.set_top_artists(ModelRc::new(VecModel::from(artist_items(&data.top_artists))));
state.set_artists_to_follow(ModelRc::new(VecModel::from(artist_items(
&data.artists_to_follow,
))));
state.set_loading(false);
state.set_loaded(true);
}
pub fn reset_loading(window: &AppWindow) {
window.global::<ForYouState>().set_loading(true);
}
pub fn artwork_jobs(data: &ForYouData) -> Vec<ArtworkJob> {
let mut jobs = Vec::new();
for (i, c) in data.release_watch.iter().enumerate() {
if !c.artwork_url.is_empty() {
jobs.push(ArtworkJob {
url: c.artwork_url.clone(),
target: ArtworkTarget::ForYouReleaseWatch { index: i },
});
}
}
for (i, c) in data.recent_albums.iter().enumerate() {
if !c.artwork_url.is_empty() {
jobs.push(ArtworkJob {
url: c.artwork_url.clone(),
target: ArtworkTarget::ForYouRecentAlbum { index: i },
});
}
}
for (i, t) in data.recent_tracks.iter().enumerate() {
if !t.artwork_url.is_empty() {
jobs.push(ArtworkJob {
url: t.artwork_url.clone(),
target: ArtworkTarget::ForYouRecentTrack { index: i },
});
}
}
for (i, a) in data.top_artists.iter().enumerate() {
if !a.artwork_url.is_empty() {
jobs.push(ArtworkJob {
url: a.artwork_url.clone(),
target: ArtworkTarget::ForYouTopArtist { index: i },
});
}
}
for (i, a) in data.artists_to_follow.iter().enumerate() {
if !a.artwork_url.is_empty() {
jobs.push(ArtworkJob {
url: a.artwork_url.clone(),
target: ArtworkTarget::ForYouToFollow { index: i },
});
}
}
jobs
}
+15 -101
View File
@@ -11,7 +11,7 @@ use std::sync::Arc;
use qbz_app::shell::AppRuntime;
use qbz_core::FrontendAdapter;
use qbz_models::{
Album, AlbumAward, DiscoverAlbum, DiscoverAudioInfo, DiscoverContainer,
AlbumAward, DiscoverAlbum, DiscoverAudioInfo, DiscoverContainer,
};
use slint::{ComponentHandle, ModelRc, VecModel};
@@ -23,8 +23,6 @@ pub struct HomeData {
pub sections: Vec<SectionData>,
/// Editorial-only section set for the Editor's Picks tab.
pub editor_sections: Vec<SectionData>,
/// Personalized section set for the For You tab.
pub foryou_sections: Vec<SectionData>,
pub popular: Vec<SlimData>,
pub recent: Vec<SlimData>,
pub recent_albums: Vec<CardData>,
@@ -41,7 +39,6 @@ thread_local! {
struct TabSections {
home: Vec<SectionData>,
editor: Vec<SectionData>,
foryou: Vec<SectionData>,
}
#[derive(Clone)]
@@ -138,64 +135,9 @@ where
.map(|(index, album)| map_slim(index, album))
.collect();
// For You — personalized sections built from the data sources the
// Slint MVP has: Release Watch (followed-artist new releases),
// Favorite Albums (the user's hearted albums), and Recently
// Played Albums (local play-history). The deeper Tauri sections
// (Qobuz mixes, similar albums, rediscover library, essentials by
// genre, artist spotlight) need the reco-DB backend, which the
// Slint MVP does not have yet.
let mut foryou_sections = Vec::new();
if let Ok(page) = runtime.core().get_release_watch("artists", 18, 0).await {
let albums: Vec<CardData> = page.items.into_iter().map(map_full_album).collect();
if !albums.is_empty() {
foryou_sections.push(SectionData {
title: "Release Watch".to_string(),
albums,
});
}
}
if let Ok(value) = runtime.core().get_favorites("albums", 24, 0).await {
let items = value
.get("albums")
.and_then(|b| b.get("items"))
.cloned()
.unwrap_or(serde_json::Value::Null);
let albums: Vec<CardData> = serde_json::from_value::<Vec<Album>>(items)
.unwrap_or_default()
.into_iter()
.map(map_full_album)
.collect();
if !albums.is_empty() {
foryou_sections.push(SectionData {
title: "Favorite Albums".to_string(),
albums,
});
}
}
{
let recents: Vec<CardData> = crate::recently::load_albums()
.into_iter()
.map(|album| CardData {
id: album.id,
title: album.title,
artist: album.artist,
genre: String::new(),
year: String::new(),
quality_tier: album.quality_tier,
quality_label: album.quality_label,
ribbon: String::new(),
ribbon_kind: String::new(),
artwork_url: album.artwork_url,
})
.collect();
if !recents.is_empty() {
foryou_sections.push(SectionData {
title: "Recently Played Albums".to_string(),
albums: recents,
});
}
}
// For You is loaded separately + lazily by crate::foryou into its
// own dedicated view, so the home load no longer builds a For You
// section set here.
// Recently played comes from the local play-history store, not the
// discover index. Empty until the playback session records plays.
@@ -230,7 +172,6 @@ where
Ok(HomeData {
sections,
editor_sections,
foryou_sections,
popular,
recent,
recent_albums,
@@ -273,39 +214,6 @@ fn push_section_ref(
});
}
/// Map a full catalog `Album` (release-watch result) to a card. Unlike
/// `map_album` (which takes the discover-index `DiscoverAlbum`), this
/// reads the standard Album shape.
fn map_full_album(album: Album) -> CardData {
let year = album
.release_date_original
.as_deref()
.and_then(|s| s.get(..4).map(|y| y.to_string()))
.unwrap_or_default();
let quality_tier = match album.maximum_bit_depth {
Some(d) if d >= 24 => "hires",
Some(_) => "cd",
None => "",
}
.to_string();
let quality_label = match (album.maximum_bit_depth, album.maximum_sampling_rate) {
(Some(bd), Some(sr)) => format!("{}-bit / {} kHz", bd, sr),
_ => String::new(),
};
CardData {
id: album.id,
title: album.title,
artist: album.artist.name,
genre: album.genre.map(|g| g.name).unwrap_or_default(),
year,
quality_tier,
quality_label,
ribbon: String::new(),
ribbon_kind: String::new(),
artwork_url: album.image.best().cloned().unwrap_or_default(),
}
}
fn map_album(album: DiscoverAlbum) -> CardData {
let artist = album
.artists
@@ -480,16 +388,22 @@ pub fn section_artwork_jobs(sections: &[SectionData]) -> Vec<ArtworkJob> {
/// HomeState.sections, and returns the artwork jobs to re-fire. No
/// re-fetch — the sets were cached by the last apply_home.
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.
if tab == "forYou" {
state.set_sections(ModelRc::new(VecModel::from(Vec::<DiscoverSection>::new())));
return Vec::new();
}
TAB_SECTIONS.with(|cell| {
let cache = cell.borrow();
let set = match tab {
"editorPicks" => &cache.editor,
"forYou" => &cache.foryou,
_ => &cache.home,
};
let state = window.global::<HomeState>();
state.set_sections(ModelRc::new(VecModel::from(build_sections(set))));
state.set_active_tab(tab.into());
section_artwork_jobs(set)
})
}
@@ -499,12 +413,12 @@ pub fn select_tab(window: &AppWindow, tab: &str) -> Vec<ArtworkJob> {
pub fn apply_home(window: &AppWindow, data: HomeData) {
let sections: Vec<DiscoverSection> = build_sections(&data.sections);
// Cache all three tab section sets for instant tab switching.
// Cache the Home + Editor's Picks section sets for instant tab
// switching (For You has its own dedicated state/view).
TAB_SECTIONS.with(|cell| {
*cell.borrow_mut() = TabSections {
home: data.sections.clone(),
editor: data.editor_sections.clone(),
foryou: data.foryou_sections.clone(),
};
});
+57 -10
View File
@@ -23,6 +23,7 @@ mod commands;
mod custom_artwork;
mod discovery_dismiss;
mod favorites;
mod foryou;
mod genre_filter;
mod home;
mod label;
@@ -123,10 +124,13 @@ async fn reload_home(
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.
// 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" => &data.foryou_sections,
"forYou" => &empty,
_ => &data.sections,
};
let mut jobs = home::section_artwork_jobs(active_set);
@@ -177,6 +181,34 @@ fn update_nav_flags(window: &AppWindow) {
state.set_can_forward(nav::can_forward());
}
/// Lazy-load the Discover > For You sections the first time the tab is
/// opened. No-op once loaded (the data persists for the session).
fn ensure_for_you_loaded(
runtime: &Arc<AppRuntime<SlintAdapter>>,
weak: &slint::Weak<AppWindow>,
handle: &tokio::runtime::Handle,
image_cache: &artwork::ImageCache,
) {
let Some(w) = weak.upgrade() else {
return;
};
if w.global::<ForYouState>().get_loaded() {
return;
}
foryou::reset_loading(&w);
let runtime = runtime.clone();
let weak = weak.clone();
let image_cache = image_cache.clone();
handle.spawn(async move {
let data = foryou::load_for_you(&runtime).await;
let jobs = foryou::artwork_jobs(&data);
let _ = weak.upgrade_in_event_loop(move |w| {
foryou::apply_for_you(&w, &data);
});
artwork::spawn_loads(jobs, weak, image_cache);
});
}
/// Load an album and show the album view, then fetch its artwork. Shared
/// by the `open-album` callback and by history back/forward.
fn navigate_album(
@@ -404,13 +436,19 @@ fn apply_entry(
});
}
nav::NavEntry::Discover { tab } => {
let weak = weak.clone();
let image_cache = image_cache.clone();
let _ = weak.clone().upgrade_in_event_loop(move |w| {
w.global::<NavState>().set_view(ContentView::Home);
let jobs = home::select_tab(&w, &tab);
artwork::spawn_loads(jobs, weak.clone(), image_cache.clone());
});
let for_you = tab == "forYou";
{
let weak = weak.clone();
let image_cache = image_cache.clone();
let _ = weak.clone().upgrade_in_event_loop(move |w| {
w.global::<NavState>().set_view(ContentView::Home);
let jobs = home::select_tab(&w, &tab);
artwork::spawn_loads(jobs, weak.clone(), image_cache.clone());
});
}
if for_you {
ensure_for_you_loaded(runtime, weak, handle, image_cache);
}
}
nav::NavEntry::Settings => {
let _ = weak.upgrade_in_event_loop(|w| {
@@ -1772,9 +1810,12 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
}
// Discover tab switch (the in-view Home / Editor's Picks / For
// You pill). Swaps the cached section set + re-fires artwork.
// You pill). Swaps the cached section set + re-fires artwork; For
// You lazy-loads its dedicated sections on first open.
{
let runtime = app_runtime.clone();
let weak = window.as_weak();
let handle = tokio_rt.handle().clone();
let image_cache = image_cache.clone();
window
.global::<HomeActions>()
@@ -1786,6 +1827,9 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
let jobs = home::select_tab(&w, tab.as_str());
artwork::spawn_loads(jobs, weak.clone(), image_cache.clone());
update_nav_flags(&w);
if tab.as_str() == "forYou" {
ensure_for_you_loaded(&runtime, &weak, &handle, &image_cache);
}
}
});
}
@@ -1957,6 +2001,9 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
let jobs = home::select_tab(&w, &tab);
artwork::spawn_loads(jobs, weak.clone(), image_cache.clone());
update_nav_flags(&w);
if tab == "forYou" {
ensure_for_you_loaded(&runtime, &weak, &handle, &image_cache);
}
}
return;
}
+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, HomeActions, GenreFilterState, GenreFilterActions, AlbumState, ArtistState, NavState, SessionState, SettingsState, AlbumActions, ArtistActions, ArtworkActions, NowPlayingState, QueueState, SearchState, SearchActions, NetworkSidebarState, NetworkSidebarActions, MusicianState, MusicianActions, LabelState, LabelActions, LocationViewState, LocationViewActions, FavoritesState, FavoritesActions } from "state.slint";
export { HomeState, HomeActions, ForYouState, GenreFilterState, GenreFilterActions, AlbumState, ArtistState, NavState, SessionState, SettingsState, AlbumActions, ArtistActions, ArtworkActions, NowPlayingState, QueueState, SearchState, SearchActions, NetworkSidebarState, NetworkSidebarActions, MusicianState, MusicianActions, LabelState, LabelActions, LocationViewState, LocationViewActions, FavoritesState, FavoritesActions } 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`.
@@ -0,0 +1,88 @@
// 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.
//
// 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 { ForYouState } from "../state.slint";
import { Carousel } from "Carousel.slint";
import { SlimCarousel } from "SlimCarousel.slint";
import { ArtistCarousel } from "ArtistCarousel.slint";
import { LoadingSpinner } from "../primitives/LoadingSpinner.slint";
export component ForYouView inherits VerticalLayout {
callback open-album(string);
callback open-artist(string);
callback media-action(string, string, string);
callback play-track(string);
spacing: 40px;
alignment: start;
if ForYouState.loading
&& ForYouState.release-watch.albums.length == 0
&& ForYouState.top-artists.length == 0: HorizontalLayout {
alignment: center;
LoadingSpinner { size: 36px; }
}
// 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);
}
}
// 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);
}
}
// 3. Recently Played Albums.
if 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);
}
}
// 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);
}
media-action(kind, id, action) => {
root.media-action(kind, id, action);
}
}
// 5. 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);
}
media-action(kind, id, action) => {
root.media-action(kind, id, action);
}
}
}
+22 -1
View File
@@ -12,6 +12,7 @@ import { HomeState, HomeActions, GenreFilterState, NavState, ContentView } from
import { Carousel } from "Carousel.slint";
import { SlimCarousel } from "SlimCarousel.slint";
import { HomeSkeleton } from "HomeSkeleton.slint";
import { ForYouView } from "ForYouView.slint";
import { GenreFilterPopup } from "GenreFilterPopup.slint";
import { QbzIcon } from "../primitives/QbzIcon.slint";
import { NavButtons } from "../shell/NavButtons.slint";
@@ -141,6 +142,7 @@ component GearButton inherits Rectangle {
export component HomeView inherits Rectangle {
callback album-clicked(string);
callback open-artist(string);
callback media-action(string, string, string);
background: Theme.surface-main;
@@ -246,7 +248,9 @@ export component HomeView inherits Rectangle {
spacing: 40px;
alignment: start;
if HomeState.loading && HomeState.sections.length == 0: HomeSkeleton { }
if HomeState.active-tab != "forYou"
&& HomeState.loading
&& HomeState.sections.length == 0: HomeSkeleton { }
for section in HomeState.sections: Carousel {
section: section;
@@ -258,6 +262,23 @@ export component HomeView inherits Rectangle {
}
}
// For You renders its own ordered, heterogeneous
// sections from ForYouState.
if HomeState.active-tab == "forYou": ForYouView {
open-album(id) => {
root.album-clicked(id);
}
open-artist(id) => {
root.open-artist(id);
}
media-action(kind, id, action) => {
root.media-action(kind, id, action);
}
play-track(id) => {
root.media-action("track", id, "play");
}
}
// 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.
+3
View File
@@ -79,6 +79,9 @@ export component AppShell inherits Rectangle {
album-clicked(id) => {
root.open-album(id);
}
open-artist(id) => {
root.open-artist(id);
}
media-action(kind, id, action) => {
root.media-action(kind, id, action);
}
+17
View File
@@ -56,6 +56,23 @@ export global HomeActions {
callback select-tab(string);
}
// Discover > For You state. The For You tab has heterogeneous,
// ordered sections (album carousels, a track carousel, artist
// carousels), so it renders from its own state rather than the
// uniform HomeState.sections used by Home / Editor's Picks.
// Populated lazily by crate::foryou the first time the tab opens.
export global ForYouState {
in property <DiscoverSection> release-watch;
in property <DiscoverSection> recent-albums;
in property <[SlimItem]> recent-tracks: [];
in property <[SlimItem]> top-artists: [];
in property <[SlimItem]> artists-to-follow: [];
in property <bool> loading: false;
// True once a load has completed, so the tab does not refetch on
// every visit.
in-out property <bool> loaded: false;
}
// One genre in the Filter-by-genre popup's simple grid.
export struct GenreChip {
id: string,