Files
qbz/crates/qbz-slint/src/location_view.rs
T
vicrodh cdb93341d0 feat(slint): ArtistsByLocationView (Port 3 complete — third click target)
Wires the Origin section's location link to the scene-discovery
view. Completes the three artist-network click targets (Musician,
Label, Location).

Slint:
  - ContentView gains `location`; NavEntry mirrors with the full
    `Location { mbid, area_id, area_name, country, genres, tags }`
    payload so back/forward replays the scene.
  - LocationViewState / LocationViewActions globals carry the scene
    header (label + genre summary) and a paginated artist grid
    (LocationArtistItem: qobuz id, name, genres line, image).
  - New `ui/location/ArtistsByLocationView.slint`: a scene header
    (map-pin + location + genre summary) over a wrapping round-
    portrait artist grid with load-more. open-artist routes the
    card click to the artist page.
  - AppShell routes ContentView.location; new map-pin.svg (Lucide).

Rust:
  - `crate::location_view` controller — load_scene, apply_scene,
    append_scene, reset_scene, artwork_jobs. Maps LocationCandidate
    rows to the grid (qobuz_name fallback to mb_name).
  - artwork::ArtworkTarget gains LocationArtist { index }.
  - The Origin metadata load now caches LocationParams (area +
    affinity seeds) in a cross-thread Mutex; reset_network_sidebar
    clears it so a stale click can't fire for the wrong artist.
    artist::location_params() exposes it to the click handler.
  - main.rs: navigate_location + apply_entry route +
    on_location_clicked (reads the cached params) +
    LocationViewActions open-artist / load-more.

Backend (prior commit) supplied discover_artists_by_location;
this commit is the Slint + wiring layer.

cc
2026-05-20 20:31:08 -06:00

135 lines
4.4 KiB
Rust

//! ArtistsByLocationView controller — runs the scene discovery for a
//! source artist's location and pushes the validated artist grid into
//! `LocationViewState`. Mirrors Tauri's ArtistsByLocationView.svelte
//! (minus the in-progress event stream, which the Slint port replaces
//! with a simple loading flag).
use std::sync::Arc;
use qbz_app::shell::AppRuntime;
use qbz_core::FrontendAdapter;
use slint::{ComponentHandle, Model, ModelRc, VecModel};
use crate::artist::LocationParams;
use crate::artwork::{ArtworkJob, ArtworkTarget};
use crate::{AppWindow, LocationArtistItem, LocationViewState};
/// Validation page size — how many MB candidates to validate against
/// Qobuz per call. Matches the Tauri view's LIMIT.
pub const PAGE_SIZE: usize = 30;
pub struct LocationData {
pub scene_label: String,
pub genre_summary: String,
pub artists: Vec<ArtistCard>,
pub total: usize,
}
#[derive(Clone)]
pub struct ArtistCard {
pub qobuz_id: String,
pub name: String,
pub genres_line: String,
pub image_url: String,
}
fn map_candidate(c: qbz_integrations::musicbrainz::LocationCandidate) -> ArtistCard {
ArtistCard {
qobuz_id: c.qobuz_id.map(|id| id.to_string()).unwrap_or_default(),
name: c.qobuz_name.unwrap_or(c.mb_name),
genres_line: c.genres.join(" · "),
image_url: c.qobuz_image.unwrap_or_default(),
}
}
/// Run the first page of scene discovery for `params`.
pub async fn load_scene<A>(
runtime: &Arc<AppRuntime<A>>,
params: &LocationParams,
offset: usize,
) -> Result<LocationData, String>
where
A: FrontendAdapter + Send + Sync + 'static,
{
let area_id = (!params.area_id.is_empty()).then_some(params.area_id.as_str());
let country = (!params.country.is_empty()).then_some(params.country.as_str());
let response = runtime
.core()
.discover_artists_by_location(
&params.mbid,
area_id,
&params.area_name,
country,
params.genres.clone(),
params.tags.clone(),
PAGE_SIZE,
offset,
)
.await
.map_err(|e| e.to_string())?;
let _ = response.next_offset; // offset is recomputed from row_count
Ok(LocationData {
scene_label: response.scene_label,
genre_summary: response.genre_summary,
artists: response.artists.into_iter().map(map_candidate).collect(),
total: response.total_candidates,
})
}
fn to_item(card: ArtistCard) -> LocationArtistItem {
LocationArtistItem {
qobuz_id: card.qobuz_id.into(),
name: card.name.into(),
genres_line: card.genres_line.into(),
image_url: card.image_url.into(),
image: slint::Image::default(),
}
}
pub fn apply_scene(window: &AppWindow, data: LocationData) {
let items: Vec<LocationArtistItem> = data.artists.into_iter().map(to_item).collect();
let state = window.global::<LocationViewState>();
state.set_scene_label(data.scene_label.into());
state.set_genre_summary(data.genre_summary.into());
state.set_artists(ModelRc::new(VecModel::from(items)));
state.set_total(data.total as i32);
state.set_loading(false);
}
pub fn append_scene(window: &AppWindow, artists: Vec<ArtistCard>, total: usize) {
let state = window.global::<LocationViewState>();
let model = state.get_artists();
let mut combined: Vec<LocationArtistItem> = (0..model.row_count())
.filter_map(|i| model.row_data(i))
.collect();
combined.extend(artists.into_iter().map(to_item));
state.set_artists(ModelRc::new(VecModel::from(combined)));
state.set_total(total as i32);
state.set_load_more_loading(false);
}
pub fn reset_scene(window: &AppWindow) {
let state = window.global::<LocationViewState>();
state.set_scene_label("".into());
state.set_genre_summary("".into());
state.set_artists(ModelRc::new(VecModel::from(Vec::<LocationArtistItem>::new())));
state.set_total(0);
state.set_loading(true);
state.set_load_more_loading(false);
}
/// Artwork jobs for the scene artist grid (the candidates' Qobuz
/// thumbnails).
pub fn artwork_jobs(data: &LocationData) -> Vec<ArtworkJob> {
data.artists
.iter()
.enumerate()
.filter(|(_, a)| !a.image_url.is_empty())
.map(|(i, a)| ArtworkJob {
url: a.image_url.clone(),
target: ArtworkTarget::LocationArtist { index: i },
})
.collect()
}