fix(slint): artist view album covers + bio Read-more toggle

Artist release cards were rendered with empty artwork because no
artwork-pipeline target existed for ArtistState. Added
ArtworkTarget::ArtistRelease and an artist::artwork_jobs builder;
navigate_artist now spawns the cover-download jobs after applying the
page data, so every section grid fills in progressively.

Biography truncation: artist.rs precomputes a word-boundary bio_short
(360 chars), ArtistState exposes bio-short and bio-truncated, and
ArtistPageView shows the short variant with an inline Read more /
Read less toggle.

cc
This commit is contained in:
vicrodh committed 2026-05-19 21:12:01 -06:00
1 parent 6d8a2e1fff
commit e116438023
5 files changed
+92 -2

No files matched your search

+43
View File
@@ -12,6 +12,7 @@ use qbz_models::{PageArtistRelease, PageArtistResponse, PageArtistTrack};
use slint::{ComponentHandle, ModelRc, VecModel};
use crate::album::TrackData;
use crate::artwork::{ArtworkJob, ArtworkTarget};
use crate::home::CardData;
use crate::{AlbumCardItem, AlbumTrackItem, AppWindow, ArtistState, DiscoverSection};
@@ -19,6 +20,10 @@ use crate::{AlbumCardItem, AlbumTrackItem, AppWindow, ArtistState, DiscoverSecti
pub struct ArtistData {
pub name: String,
pub bio: String,
/// Word-boundary truncated bio used at rest; the Read-more toggle
/// swaps to `bio`. Equal to `bio` when the text fits in the cap.
pub bio_short: String,
pub bio_truncated: bool,
pub artwork_url: String,
pub top_tracks: Vec<TrackData>,
/// Releases grouped into titled sections (Albums, EPs & Singles, ...).
@@ -58,6 +63,8 @@ fn map_artist(page: PageArtistResponse) -> ArtistData {
.and_then(|b| b.content)
.map(|content| strip_html(&content))
.unwrap_or_default();
let bio_short = truncate_words(&bio, 360);
let bio_truncated = bio_short != bio;
let artwork_url = page
.images
@@ -92,12 +99,46 @@ fn map_artist(page: PageArtistResponse) -> ArtistData {
ArtistData {
name,
bio,
bio_short,
bio_truncated,
artwork_url,
top_tracks,
release_sections,
}
}
/// Truncate text at the last word boundary within `max` characters,
/// appending an ellipsis. Returns the text unchanged when it already
/// fits.
fn truncate_words(text: &str, max: usize) -> String {
if text.chars().count() <= max {
return text.to_string();
}
let truncated: String = text.chars().take(max).collect();
let cut = truncated.rfind(' ').unwrap_or(truncated.len());
format!("{}…", truncated[..cut].trim_end())
}
/// Build artwork download jobs for every release card so the cover grid
/// fills in once the images decode.
pub fn artwork_jobs(data: &ArtistData) -> Vec<ArtworkJob> {
let mut jobs = Vec::new();
for (section_idx, section) in data.release_sections.iter().enumerate() {
for (album_idx, card) in section.cards.iter().enumerate() {
if !card.artwork_url.is_empty() {
jobs.push(ArtworkJob {
target: ArtworkTarget::ArtistRelease {
section_idx,
album_idx,
},
url: card.artwork_url.clone(),
});
}
}
}
jobs
}
/// Human title for a Qobuz artist-page release group type.
fn release_section_title(release_type: &str) -> String {
match release_type {
@@ -228,6 +269,8 @@ pub fn apply_artist(window: &AppWindow, data: ArtistData) {
let state = window.global::<ArtistState>();
state.set_name(data.name.into());
state.set_bio(data.bio.into());
state.set_bio_short(data.bio_short.into());
state.set_bio_truncated(data.bio_truncated);
state.set_top_tracks(ModelRc::new(VecModel::from(top_tracks)));
state.set_release_sections(ModelRc::new(VecModel::from(release_sections)));
}
+18 -1
View File
@@ -12,7 +12,7 @@ use qbz_cache::ImageCacheService;
use slint::{ComponentHandle, Model};
use tokio::sync::Semaphore;
use crate::{AppWindow, HomeState, SearchState};
use crate::{AppWindow, ArtistState, HomeState, SearchState};
/// Cap on simultaneous artwork downloads.
const MAX_CONCURRENT: usize = 16;
@@ -49,6 +49,9 @@ pub enum ArtworkTarget {
SearchPlaylistCover { idx: usize, slot: usize },
/// The most-popular search hero (its kind is read from SearchState).
SearchMostPopular,
/// A release card in `ArtistState.release-sections[section_idx]
/// .albums[album_idx]`.
ArtistRelease { section_idx: usize, album_idx: usize },
}
/// An artwork download job: which card, and the image URL.
@@ -323,5 +326,19 @@ fn apply_artwork(
_ => {}
}
}
ArtworkTarget::ArtistRelease {
section_idx,
album_idx,
} => {
let sections = window.global::<ArtistState>().get_release_sections();
let Some(section) = sections.row_data(section_idx) else {
return;
};
let Some(mut item) = section.albums.row_data(album_idx) else {
return;
};
item.artwork = image;
section.albums.set_row_data(album_idx, item);
}
}
}
+2
View File
@@ -227,10 +227,12 @@ fn navigate_artist(
match artist::load_artist(&runtime, &artist_id).await {
Ok(data) => {
let artwork_url = data.artwork_url.clone();
let jobs = artist::artwork_jobs(&data);
let _ = weak.upgrade_in_event_loop(move |w| {
artist::apply_artist(&w, data);
w.global::<ArtistState>().set_loading(false);
});
artwork::spawn_loads(jobs, weak.clone(), image_cache.clone());
if !artwork_url.is_empty() {
if let Some((pixels, width, height)) =
artwork::fetch_and_decode(&artwork_url, &image_cache, 440).await
@@ -170,6 +170,9 @@ export component ArtistPageView inherits Rectangle {
callback open-album(string);
callback media-action(string, string, string);
// Read-more toggle for the biography.
property <bool> bio-expanded: false;
background: Theme.surface-main;
Flickable {
@@ -288,13 +291,34 @@ export component ArtistPageView inherits Rectangle {
}
// Biography — full content width, below the header block.
// Read-more toggle expands an inline word-boundary truncation.
if ArtistState.bio != "": Rectangle { height: 18px; }
if ArtistState.bio != "": Text {
text: ArtistState.bio;
text: root.bio-expanded ? ArtistState.bio : ArtistState.bio-short;
color: Theme.text-secondary;
font-size: Typography.body;
wrap: word-wrap;
}
if ArtistState.bio-truncated: Rectangle {
height: 24px;
width: read-more-text.preferred-width + 16px;
read-more-text := Text {
text: root.bio-expanded ? @tr("Read less") : @tr("Read more");
color: read-more-ta.has-hover
? Theme.text-primary
: Theme.accent;
font-size: 13px;
font-weight: Typography.medium;
vertical-alignment: center;
height: 100%;
}
read-more-ta := TouchArea {
mouse-cursor: pointer;
clicked => {
root.bio-expanded = !root.bio-expanded;
}
}
}
Rectangle { height: 36px; }
+4
View File
@@ -194,6 +194,10 @@ export global NavState {
export global ArtistState {
in property <string> name;
in property <string> bio;
// Truncated bio (word-boundary cut + ellipsis) for the at-rest view;
// the full bio in `bio` is shown when the Read-more toggle expands.
in property <string> bio-short;
in property <bool> bio-truncated: false;
in property <image> artwork;
// Artwork-derived tint for the header gradient.
in property <color> header-color: #181820;