fix(follow): reflect artist follow across every card surface
mark_artist_followed only updated the Search artist cards, so following
from (or affecting) For You / the Recommendations carousels left their
Follow chips stale. Flip `following` on all of them (Search results +
carousel, For You top-artists + artists-to-follow, reco rec-artists +
top-artists) so the chip hides ("auto") or flips to Following ("toggle")
wherever the artist appears.
cc
This commit is contained in:
1 file changed
+26
-14
+26
-14
@@ -16,8 +16,8 @@ use slint::{ComponentHandle, Model, ModelRc, VecModel};
|
||||
use crate::artwork::{ArtworkJob, ArtworkTarget};
|
||||
use crate::{
|
||||
AlbumCardItem, AppWindow, CortinillaRow as CortinillaRowItem,
|
||||
CortinillaSection as CortinillaSectionItem, SearchPlaylistItem, SearchState, SlimItem,
|
||||
TrackItem,
|
||||
CortinillaSection as CortinillaSectionItem, ExternalRecoState, ForYouState, SearchPlaylistItem,
|
||||
SearchState, SlimItem, TrackItem,
|
||||
};
|
||||
|
||||
thread_local! {
|
||||
@@ -1440,12 +1440,31 @@ pub fn reset_search(window: &AppWindow) {
|
||||
/// Mark an artist as followed in every `SearchState` list it appears in
|
||||
/// (results list + most-popular hero). Runs on the Slint event loop.
|
||||
pub fn mark_artist_followed(window: &AppWindow, artist_id: &str, following: bool) {
|
||||
// Flip the Follow chip on EVERY visible artist-card surface, so following
|
||||
// from any of them updates the others (Search, For You, the Recommendations
|
||||
// carousels). "auto"-mode chips hide once following; "toggle"-mode flip.
|
||||
let state = window.global::<SearchState>();
|
||||
if let Some(vm) = state
|
||||
.get_artists()
|
||||
.as_any()
|
||||
.downcast_ref::<VecModel<SlimItem>>()
|
||||
{
|
||||
set_slim_following(&state.get_artists(), artist_id, following);
|
||||
set_slim_following(&state.get_artists_carousel(), artist_id, following);
|
||||
if state.get_most_popular_kind() == "artist" {
|
||||
let mut mp = state.get_most_popular_artist();
|
||||
if mp.id == artist_id {
|
||||
mp.following = following;
|
||||
state.set_most_popular_artist(mp);
|
||||
}
|
||||
}
|
||||
let foryou = window.global::<ForYouState>();
|
||||
set_slim_following(&foryou.get_top_artists(), artist_id, following);
|
||||
set_slim_following(&foryou.get_artists_to_follow(), artist_id, following);
|
||||
let reco = window.global::<ExternalRecoState>();
|
||||
set_slim_following(&reco.get_rec_artists_common(), artist_id, following);
|
||||
set_slim_following(&reco.get_rec_artists_recent(), artist_id, following);
|
||||
set_slim_following(&reco.get_top_artists(), artist_id, following);
|
||||
}
|
||||
|
||||
/// Flip `following` on the row matching `artist_id` in a `[SlimItem]` model.
|
||||
fn set_slim_following(model: &ModelRc<SlimItem>, artist_id: &str, following: bool) {
|
||||
if let Some(vm) = model.as_any().downcast_ref::<VecModel<SlimItem>>() {
|
||||
for i in 0..vm.row_count() {
|
||||
if let Some(mut item) = vm.row_data(i) {
|
||||
if item.id == artist_id {
|
||||
@@ -1455,13 +1474,6 @@ pub fn mark_artist_followed(window: &AppWindow, artist_id: &str, following: bool
|
||||
}
|
||||
}
|
||||
}
|
||||
if state.get_most_popular_kind() == "artist" {
|
||||
let mut mp = state.get_most_popular_artist();
|
||||
if mp.id == artist_id {
|
||||
mp.following = following;
|
||||
state.set_most_popular_artist(mp);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// ==================== Load-more (pagination) ====================
|
||||
|
||||
Reference in new issue
Block a user