feat(slint/discover): favoriteAlbums row in For You

Add the missing For You "Favorite Albums" carousel (Tauri's
favoriteAlbums), the user's favorited albums capped at 18 in favorite
order, self-hiding when empty. Reuses the album fav-fetch already done in
albums_branch — no new endpoint.

- state.slint: ForYouState.favorite-albums: DiscoverSection.
- foryou.rs: build_favorite_albums (cap 18, unfiltered) + apply_favorite_albums
  (mirrors apply_rediscover); wired into albums_branch right after fav_albums
  resolves, painting in the same layer as rediscover/radio.
- artwork.rs: ForYouFavoriteAlbum { index } variant + apply arm.
- ForYouView.slint: mount the Carousel after Your Top Artists, before More
  From Your Library, gated on favorite-albums.albums.length > 0.

Titled "Favorite Albums" (not Tauri's literal "More From Your Library")
to avoid the label collision with similarAlbums.

cc
This commit is contained in:
vicrodh committed 2026-06-15 12:56:33 -06:00
1 parent 6d06a8aa83
commit 613a3f009b
4 files changed
+40

No files matched your search

+9
View File
@@ -129,6 +129,8 @@ pub enum ArtworkTarget {
ForYouMoreFromLibrary { index: usize }, ForYouMoreFromLibrary { index: usize },
/// A card in ForYouState.rediscover.albums[index]. /// A card in ForYouState.rediscover.albums[index].
ForYouRediscover { index: usize }, ForYouRediscover { index: usize },
/// A card in ForYouState.favorite-albums.albums[index].
ForYouFavoriteAlbum { index: usize },
/// The Spotlight artist portrait. /// The Spotlight artist portrait.
ForYouSpotlightArtist, ForYouSpotlightArtist,
/// A card in ForYouState.spotlight-albums[index]. /// A card in ForYouState.spotlight-albums[index].
@@ -1022,6 +1024,13 @@ fn apply_artwork(
model.set_row_data(index, item); model.set_row_data(index, item);
} }
} }
ArtworkTarget::ForYouFavoriteAlbum { index } => {
let model = window.global::<crate::ForYouState>().get_favorite_albums().albums;
if let Some(mut item) = model.row_data(index) {
item.artwork = image;
model.set_row_data(index, item);
}
}
ArtworkTarget::ForYouSpotlightArtist => { ArtworkTarget::ForYouSpotlightArtist => {
window window
.global::<crate::ForYouState>() .global::<crate::ForYouState>()
+18
View File
@@ -395,6 +395,13 @@ fn build_rediscover(fav_albums: &[Album], recent_ids: &HashSet<String>) -> Vec<A
.collect() .collect()
} }
/// Favorite Albums — the user's favorited albums, capped at 18, in favorite
/// order (matches Tauri's home-resolved favoriteAlbums sliced 18; unfiltered,
/// unlike Rediscover).
fn build_favorite_albums(fav_albums: &[Album]) -> Vec<AlbumCard> {
fav_albums.iter().take(18).cloned().map(map_album).collect()
}
/// Radio Stations — album-seeded tiles from recent + favorite albums, /// Radio Stations — album-seeded tiles from recent + favorite albums,
/// deduped, capped at 12. /// deduped, capped at 12.
fn build_radio( fn build_radio(
@@ -628,6 +635,16 @@ fn apply_rediscover(weak: &slint::Weak<AppWindow>, cache: &ImageCache, cards: Ve
crate::artwork::spawn_loads(jobs, weak.clone(), cache.clone()); crate::artwork::spawn_loads(jobs, weak.clone(), cache.clone());
} }
fn apply_favorite_albums(weak: &slint::Weak<AppWindow>, cache: &ImageCache, cards: Vec<AlbumCard>) {
let jobs = album_jobs(&cards, |i| ArtworkTarget::ForYouFavoriteAlbum { index: i });
let w = weak.clone();
let _ = w.upgrade_in_event_loop(move |w| {
w.global::<ForYouState>()
.set_favorite_albums(section("Favorite Albums", &cards));
});
crate::artwork::spawn_loads(jobs, weak.clone(), cache.clone());
}
fn apply_more_from_library( fn apply_more_from_library(
weak: &slint::Weak<AppWindow>, weak: &slint::Weak<AppWindow>,
cache: &ImageCache, cache: &ImageCache,
@@ -787,6 +804,7 @@ pub fn spawn_for_you<A>(
let recent_ids = recent_ids.clone(); let recent_ids = recent_ids.clone();
Box::pin(async move { Box::pin(async move {
let fav_albums = fetch_fav_albums(&runtime).await; let fav_albums = fetch_fav_albums(&runtime).await;
apply_favorite_albums(&weak, &cache, build_favorite_albums(&fav_albums));
apply_rediscover(&weak, &cache, build_rediscover(&fav_albums, &recent_ids)); apply_rediscover(&weak, &cache, build_rediscover(&fav_albums, &recent_ids));
apply_radio(&weak, &cache, build_radio(&recent_album_list, &fav_albums)); apply_radio(&weak, &cache, build_radio(&recent_album_list, &fav_albums));
@@ -134,6 +134,17 @@ export component ForYouView inherits VerticalLayout {
} }
} }
// 6. Favorite Albums.
if 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);
}
}
// 5. More From Your Library. // 5. More From Your Library.
if ForYouState.more-from-library.albums.length > 0: Carousel { if ForYouState.more-from-library.albums.length > 0: Carousel {
section: ForYouState.more-from-library; section: ForYouState.more-from-library;
+2
View File
@@ -159,6 +159,8 @@ export global ForYouState {
in property <DiscoverSection> release-watch; in property <DiscoverSection> release-watch;
in property <[RadioStationItem]> radio-stations: []; in property <[RadioStationItem]> radio-stations: [];
in property <DiscoverSection> recent-albums; in property <DiscoverSection> recent-albums;
// Favorite Albums — the user's favorited albums (For You #6).
in property <DiscoverSection> favorite-albums;
in property <[SlimItem]> recent-tracks: []; in property <[SlimItem]> recent-tracks: [];
in property <[SlimItem]> top-artists: []; in property <[SlimItem]> top-artists: [];
in property <[SlimItem]> artists-to-follow: []; in property <[SlimItem]> artists-to-follow: [];