feat(slint): MB relationships section in the network sidebar
Wires the third MB-driven section: Members & Former, Member Of, and
Collaborators, mirroring Tauri's RELATIONSHIPS block.
Controller (`crates/qbz-slint/src/artist.rs`):
- load_mb_relationships(runtime, mbid) — calls QbzCore's
musicbrainz_get_artist_relationships, then maps each section
independently with group_relations.
- group_relations dedupes by mbid combining roles, preserves first-
seen order, and computes the per-row role + tooltip:
* role = first attribute, or the section default ("Band Member"
/ "Band" / "Collaborator") when MB has no attributes.
* tooltip = roles joined with ", " plus the period in parens
("Vocalist, Guitarist (1965 - 1969)"); falls back to just the
period or to the name.
- format_period mirrors Tauri's `{begin || '?'} - {end || 'present'}`
when at least one of the two is set, otherwise empty.
main.rs:
- The MB enrichment task now chains: resolve + metadata first, then
relationships with the resolved mbid. Both loading flags flip
together so the sidebar shows a single "Loading…" line per section
while the calls run.
ArtistPageView.slint:
- RELATIONSHIPS section, gated by mb-available + (loading || has-
data). Three sub-groups, each with a secondary label
("Members & Former" / "Member Of" / "Collaborators"), shown only
when their list is non-empty.
- Members and Collaborators use the User icon, Member Of uses the
Music icon (matches Tauri's Lucide imports).
- Each row reuses SidebarLink, emits NetworkSidebarActions.musician-
clicked(name, role) — logged-only until MusicianPage lands.
cc
This commit is contained in:
3 files changed
+286
-4
No files matched your search
@@ -19,7 +19,7 @@ use crate::artwork::{ArtworkJob, ArtworkTarget};
|
|||||||
use crate::home::CardData;
|
use crate::home::CardData;
|
||||||
use crate::{
|
use crate::{
|
||||||
AlbumCardItem, AlbumTrackItem, AppWindow, ArtistState, DiscoverSection, LabelEntry,
|
AlbumCardItem, AlbumTrackItem, AppWindow, ArtistState, DiscoverSection, LabelEntry,
|
||||||
MbOriginData, NetworkSidebarState, SimilarEntry,
|
MbOriginData, MbRelationship, MbRelationshipsData, NetworkSidebarState, SimilarEntry,
|
||||||
};
|
};
|
||||||
|
|
||||||
/// Plain, `Send` artist data produced on the worker thread.
|
/// Plain, `Send` artist data produced on the worker thread.
|
||||||
@@ -671,6 +671,174 @@ pub fn apply_mb_unavailable(window: &AppWindow) {
|
|||||||
state.set_discovery_loading(false);
|
state.set_discovery_loading(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ----- MB relationships -------------------------------------------------
|
||||||
|
|
||||||
|
/// Plain, `Send` mapped relationships ready to push into Slint. Members
|
||||||
|
/// here are the still-active ones (ended members already moved to
|
||||||
|
/// past_members on the qbz-core side, and Tauri's sidebar renders only
|
||||||
|
/// members — see groupedMembers in ArtistDetailView).
|
||||||
|
pub struct MbRelationshipsRowData {
|
||||||
|
pub members: Vec<MbRelationshipRow>,
|
||||||
|
pub groups: Vec<MbRelationshipRow>,
|
||||||
|
pub collaborators: Vec<MbRelationshipRow>,
|
||||||
|
pub has_data: bool,
|
||||||
|
}
|
||||||
|
|
||||||
|
pub struct MbRelationshipRow {
|
||||||
|
pub mbid: String,
|
||||||
|
pub name: String,
|
||||||
|
/// Primary role for the musician-click callback. Defaults to "Band
|
||||||
|
/// Member" / "Band" / "Collaborator" by section when MB has no
|
||||||
|
/// attributes for the relation.
|
||||||
|
pub role: String,
|
||||||
|
/// Tooltip — roles joined with ", " plus the period in parens when
|
||||||
|
/// present. Falls back to the period string or the name.
|
||||||
|
pub tooltip: String,
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Fetch MB relationships for `mbid` and map into the Slint-friendly
|
||||||
|
/// row shape. Groups members by mbid combining their roles, mirroring
|
||||||
|
/// Tauri's `groupMembersByMbid` plus the per-section role defaults.
|
||||||
|
pub async fn load_mb_relationships<A>(
|
||||||
|
runtime: &Arc<AppRuntime<A>>,
|
||||||
|
mbid: &str,
|
||||||
|
) -> Result<MbRelationshipsRowData, String>
|
||||||
|
where
|
||||||
|
A: FrontendAdapter + Send + Sync + 'static,
|
||||||
|
{
|
||||||
|
let relations = runtime
|
||||||
|
.core()
|
||||||
|
.musicbrainz_get_artist_relationships(mbid)
|
||||||
|
.await
|
||||||
|
.map_err(|e| e.to_string())?;
|
||||||
|
Ok(map_relationships(relations))
|
||||||
|
}
|
||||||
|
|
||||||
|
fn map_relationships(
|
||||||
|
rels: qbz_integrations::musicbrainz::ArtistRelationships,
|
||||||
|
) -> MbRelationshipsRowData {
|
||||||
|
let members = group_relations(rels.members, "Band Member");
|
||||||
|
let groups = group_relations(rels.groups, "Band");
|
||||||
|
let collaborators = group_relations(rels.collaborators, "Collaborator");
|
||||||
|
let has_data =
|
||||||
|
!members.is_empty() || !groups.is_empty() || !collaborators.is_empty();
|
||||||
|
MbRelationshipsRowData {
|
||||||
|
members,
|
||||||
|
groups,
|
||||||
|
collaborators,
|
||||||
|
has_data,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn group_relations(
|
||||||
|
rels: Vec<qbz_integrations::musicbrainz::RelatedArtist>,
|
||||||
|
default_role: &str,
|
||||||
|
) -> Vec<MbRelationshipRow> {
|
||||||
|
use std::collections::HashMap;
|
||||||
|
struct Pending {
|
||||||
|
name: String,
|
||||||
|
roles: Vec<String>,
|
||||||
|
begin: Option<String>,
|
||||||
|
end: Option<String>,
|
||||||
|
}
|
||||||
|
let mut by_mbid: HashMap<String, Pending> = HashMap::new();
|
||||||
|
let mut order: Vec<String> = Vec::new();
|
||||||
|
for r in rels {
|
||||||
|
let begin = r.period.as_ref().and_then(|p| p.begin.clone());
|
||||||
|
let end = r.period.as_ref().and_then(|p| p.end.clone());
|
||||||
|
match by_mbid.get_mut(&r.mbid) {
|
||||||
|
Some(existing) => {
|
||||||
|
if let Some(role) = r.role.clone() {
|
||||||
|
if !existing.roles.iter().any(|rr| rr == &role) {
|
||||||
|
existing.roles.push(role);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
None => {
|
||||||
|
order.push(r.mbid.clone());
|
||||||
|
let mut roles = Vec::new();
|
||||||
|
if let Some(role) = r.role.clone() {
|
||||||
|
roles.push(role);
|
||||||
|
}
|
||||||
|
by_mbid.insert(
|
||||||
|
r.mbid.clone(),
|
||||||
|
Pending {
|
||||||
|
name: r.name,
|
||||||
|
roles,
|
||||||
|
begin,
|
||||||
|
end,
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
order
|
||||||
|
.into_iter()
|
||||||
|
.filter_map(|mbid| by_mbid.remove(&mbid).map(|p| (mbid, p)))
|
||||||
|
.map(|(mbid, p)| {
|
||||||
|
let period = format_period(p.begin.as_deref(), p.end.as_deref());
|
||||||
|
let tooltip = if !p.roles.is_empty() {
|
||||||
|
let roles_joined = p.roles.join(", ");
|
||||||
|
if period.is_empty() {
|
||||||
|
roles_joined
|
||||||
|
} else {
|
||||||
|
format!("{} ({})", roles_joined, period)
|
||||||
|
}
|
||||||
|
} else if !period.is_empty() {
|
||||||
|
period.clone()
|
||||||
|
} else {
|
||||||
|
p.name.clone()
|
||||||
|
};
|
||||||
|
let role = p
|
||||||
|
.roles
|
||||||
|
.first()
|
||||||
|
.cloned()
|
||||||
|
.unwrap_or_else(|| default_role.to_string());
|
||||||
|
MbRelationshipRow {
|
||||||
|
mbid,
|
||||||
|
name: p.name,
|
||||||
|
role,
|
||||||
|
tooltip,
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.collect()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn format_period(begin: Option<&str>, end: Option<&str>) -> String {
|
||||||
|
if begin.is_some() || end.is_some() {
|
||||||
|
let b = begin.unwrap_or("?");
|
||||||
|
let e = end.unwrap_or("present");
|
||||||
|
format!("{} - {}", b, e)
|
||||||
|
} else {
|
||||||
|
String::new()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Apply MB relationships to NetworkSidebarState. Runs on the Slint
|
||||||
|
/// event loop.
|
||||||
|
pub fn apply_mb_relationships(window: &AppWindow, data: MbRelationshipsRowData) {
|
||||||
|
let to_slint = |rows: Vec<MbRelationshipRow>| -> ModelRc<MbRelationship> {
|
||||||
|
ModelRc::new(VecModel::from(
|
||||||
|
rows.into_iter()
|
||||||
|
.map(|r| MbRelationship {
|
||||||
|
mbid: r.mbid.into(),
|
||||||
|
name: r.name.into(),
|
||||||
|
role: r.role.into(),
|
||||||
|
tooltip: r.tooltip.into(),
|
||||||
|
})
|
||||||
|
.collect::<Vec<_>>(),
|
||||||
|
))
|
||||||
|
};
|
||||||
|
let state = window.global::<NetworkSidebarState>();
|
||||||
|
state.set_relationships(MbRelationshipsData {
|
||||||
|
members: to_slint(data.members),
|
||||||
|
groups: to_slint(data.groups),
|
||||||
|
collaborators: to_slint(data.collaborators),
|
||||||
|
has_data: data.has_data,
|
||||||
|
});
|
||||||
|
state.set_relationships_loading(false);
|
||||||
|
}
|
||||||
|
|
||||||
/// Format a MusicBrainz partial date into a short human string —
|
/// Format a MusicBrainz partial date into a short human string —
|
||||||
/// "1990", "May 1990", or "May 14, 1990" — matching Tauri's
|
/// "1990", "May 1990", or "May 14, 1990" — matching Tauri's
|
||||||
/// formatMbDate_v2 output when the locale is en-US.
|
/// formatMbDate_v2 output when the locale is en-US.
|
||||||
|
|||||||
@@ -238,19 +238,39 @@ fn navigate_artist(
|
|||||||
artwork::spawn_loads(jobs, weak.clone(), image_cache.clone());
|
artwork::spawn_loads(jobs, weak.clone(), image_cache.clone());
|
||||||
|
|
||||||
// Network sidebar — kick the MB enrichment off in
|
// Network sidebar — kick the MB enrichment off in
|
||||||
// parallel with artwork. Origin section shows a loading
|
// parallel with artwork. Origin shows a loading state
|
||||||
// state until the MB resolve + metadata calls return.
|
// until the resolve + metadata calls return; on success
|
||||||
|
// the resolved mbid is used to fetch relationships in a
|
||||||
|
// second round-trip (the V2 cache, when wired, will
|
||||||
|
// make this single-shot for repeat visits).
|
||||||
let runtime_mb = runtime.clone();
|
let runtime_mb = runtime.clone();
|
||||||
let weak_mb = weak.clone();
|
let weak_mb = weak.clone();
|
||||||
tokio::spawn(async move {
|
tokio::spawn(async move {
|
||||||
let _ = weak_mb.upgrade_in_event_loop(|w| {
|
let _ = weak_mb.upgrade_in_event_loop(|w| {
|
||||||
w.global::<NetworkSidebarState>().set_origin_loading(true);
|
let state = w.global::<NetworkSidebarState>();
|
||||||
|
state.set_origin_loading(true);
|
||||||
|
state.set_relationships_loading(true);
|
||||||
});
|
});
|
||||||
match artist::load_mb_metadata(&runtime_mb, &artist_name).await {
|
match artist::load_mb_metadata(&runtime_mb, &artist_name).await {
|
||||||
Ok(Some(meta)) => {
|
Ok(Some(meta)) => {
|
||||||
|
let mbid = meta.mbid.clone();
|
||||||
let _ = weak_mb.upgrade_in_event_loop(move |w| {
|
let _ = weak_mb.upgrade_in_event_loop(move |w| {
|
||||||
artist::apply_mb_metadata(&w, meta);
|
artist::apply_mb_metadata(&w, meta);
|
||||||
});
|
});
|
||||||
|
match artist::load_mb_relationships(&runtime_mb, &mbid).await {
|
||||||
|
Ok(data) => {
|
||||||
|
let _ = weak_mb.upgrade_in_event_loop(move |w| {
|
||||||
|
artist::apply_mb_relationships(&w, data);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
Err(e) => {
|
||||||
|
log::warn!("[qbz-slint] MB relationships failed: {e}");
|
||||||
|
let _ = weak_mb.upgrade_in_event_loop(|w| {
|
||||||
|
w.global::<NetworkSidebarState>()
|
||||||
|
.set_relationships_loading(false);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Ok(None) => {
|
Ok(None) => {
|
||||||
let _ = weak_mb.upgrade_in_event_loop(|w| {
|
let _ = weak_mb.upgrade_in_event_loop(|w| {
|
||||||
|
|||||||
@@ -887,6 +887,100 @@ export component ArtistPageView inherits Rectangle {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// --- Relationships (MB) --------------------------
|
||||||
|
// Section is gated by mb-available so a
|
||||||
|
// disabled MB or unmatched artist hides it.
|
||||||
|
if NetworkSidebarState.mb-available
|
||||||
|
&& (NetworkSidebarState.relationships-loading
|
||||||
|
|| NetworkSidebarState.relationships.has-data):
|
||||||
|
VerticalLayout {
|
||||||
|
padding-left: 14px;
|
||||||
|
padding-right: 14px;
|
||||||
|
padding-top: 12px;
|
||||||
|
padding-bottom: 6px;
|
||||||
|
spacing: 6px;
|
||||||
|
|
||||||
|
Text {
|
||||||
|
text: @tr("RELATIONSHIPS");
|
||||||
|
color: Theme.text-muted;
|
||||||
|
font-size: 11px;
|
||||||
|
font-weight: Typography.semibold;
|
||||||
|
letter-spacing: 0.5px;
|
||||||
|
}
|
||||||
|
|
||||||
|
if NetworkSidebarState.relationships-loading: Text {
|
||||||
|
text: @tr("Loading…");
|
||||||
|
color: Theme.text-muted;
|
||||||
|
font-size: 12px;
|
||||||
|
}
|
||||||
|
|
||||||
|
if !NetworkSidebarState.relationships-loading
|
||||||
|
&& NetworkSidebarState.relationships.members.length > 0:
|
||||||
|
VerticalLayout {
|
||||||
|
spacing: 2px;
|
||||||
|
padding-top: 2px;
|
||||||
|
Text {
|
||||||
|
text: @tr("Members & Former");
|
||||||
|
color: Theme.text-muted;
|
||||||
|
font-size: 11px;
|
||||||
|
}
|
||||||
|
for member in NetworkSidebarState.relationships.members:
|
||||||
|
SidebarLink {
|
||||||
|
label: member.name;
|
||||||
|
icon: @image-url("../assets/icons/user.svg");
|
||||||
|
tooltip: member.tooltip;
|
||||||
|
clicked => {
|
||||||
|
NetworkSidebarActions.musician-clicked(
|
||||||
|
member.name, member.role);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if !NetworkSidebarState.relationships-loading
|
||||||
|
&& NetworkSidebarState.relationships.groups.length > 0:
|
||||||
|
VerticalLayout {
|
||||||
|
spacing: 2px;
|
||||||
|
padding-top: 2px;
|
||||||
|
Text {
|
||||||
|
text: @tr("Member Of");
|
||||||
|
color: Theme.text-muted;
|
||||||
|
font-size: 11px;
|
||||||
|
}
|
||||||
|
for group in NetworkSidebarState.relationships.groups:
|
||||||
|
SidebarLink {
|
||||||
|
label: group.name;
|
||||||
|
icon: @image-url("../assets/icons/music.svg");
|
||||||
|
tooltip: group.tooltip;
|
||||||
|
clicked => {
|
||||||
|
NetworkSidebarActions.musician-clicked(
|
||||||
|
group.name, group.role);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if !NetworkSidebarState.relationships-loading
|
||||||
|
&& NetworkSidebarState.relationships.collaborators.length > 0:
|
||||||
|
VerticalLayout {
|
||||||
|
spacing: 2px;
|
||||||
|
padding-top: 2px;
|
||||||
|
Text {
|
||||||
|
text: @tr("Collaborators");
|
||||||
|
color: Theme.text-muted;
|
||||||
|
font-size: 11px;
|
||||||
|
}
|
||||||
|
for collab in NetworkSidebarState.relationships.collaborators:
|
||||||
|
SidebarLink {
|
||||||
|
label: collab.name;
|
||||||
|
icon: @image-url("../assets/icons/user.svg");
|
||||||
|
tooltip: collab.tooltip;
|
||||||
|
clicked => {
|
||||||
|
NetworkSidebarActions.musician-clicked(
|
||||||
|
collab.name, collab.role);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user