Make fetch also fetch artist MBID if it is missing #201
@ -257,8 +257,11 @@ mod tests {
|
||||
|
||||
let public_matches = public.state.unwrap_matches();
|
||||
|
||||
assert_eq!(public_matches.matching, Some(&album_1));
|
||||
assert_eq!(public_matches.matches, Some(matches_1.as_slice()));
|
||||
assert_eq!(public_matches.matches.as_ref().unwrap().matching, &album_1);
|
||||
assert_eq!(
|
||||
public_matches.matches.as_ref().unwrap().list,
|
||||
matches_1.as_slice()
|
||||
);
|
||||
|
||||
let mut app = app.unwrap_matches().select();
|
||||
|
||||
@ -267,8 +270,11 @@ mod tests {
|
||||
|
||||
let public_matches = public.state.unwrap_matches();
|
||||
|
||||
assert_eq!(public_matches.matching, Some(&album_4));
|
||||
assert_eq!(public_matches.matches, Some(matches_4.as_slice()));
|
||||
assert_eq!(public_matches.matches.as_ref().unwrap().matching, &album_4);
|
||||
assert_eq!(
|
||||
public_matches.matches.as_ref().unwrap().list,
|
||||
matches_4.as_slice()
|
||||
);
|
||||
|
||||
let app = app.unwrap_matches().select();
|
||||
app.unwrap_browse();
|
||||
|
@ -5,7 +5,8 @@ use musichoard::collection::album::Album;
|
||||
use crate::tui::{
|
||||
app::{
|
||||
machine::{App, AppInner, AppMachine},
|
||||
AppPublic, AppPublicMatches, AppState, IAppInteractMatches, WidgetState,
|
||||
AppPublic, AppPublicAlbumMatches, AppPublicMatches, AppState, IAppInteractMatches,
|
||||
WidgetState,
|
||||
},
|
||||
lib::interface::musicbrainz::Match,
|
||||
};
|
||||
@ -52,18 +53,14 @@ impl From<AppMachine<AppMatches>> for App {
|
||||
|
||||
impl<'a> From<&'a mut AppMachine<AppMatches>> for AppPublic<'a> {
|
||||
fn from(machine: &'a mut AppMachine<AppMatches>) -> Self {
|
||||
let (matching, matches) = match machine.state.index {
|
||||
Some(index) => (
|
||||
Some(&machine.state.matches_info_vec[index].matching),
|
||||
Some(machine.state.matches_info_vec[index].matches.as_slice()),
|
||||
),
|
||||
None => (None, None),
|
||||
};
|
||||
let matches = machine.state.index.map(|index| AppPublicAlbumMatches {
|
||||
matching: &machine.state.matches_info_vec[index].matching,
|
||||
list: machine.state.matches_info_vec[index].matches.as_slice(),
|
||||
});
|
||||
|
||||
AppPublic {
|
||||
inner: (&mut machine.inner).into(),
|
||||
state: AppState::Matches(AppPublicMatches {
|
||||
matching,
|
||||
matches,
|
||||
state: &mut machine.state.state,
|
||||
}),
|
||||
@ -199,7 +196,6 @@ mod tests {
|
||||
let public = app.get();
|
||||
let public_matches = public.state.unwrap_matches();
|
||||
|
||||
assert_eq!(public_matches.matching, None);
|
||||
assert_eq!(public_matches.matches, None);
|
||||
assert_eq!(public_matches.state, &widget_state);
|
||||
}
|
||||
@ -220,10 +216,13 @@ mod tests {
|
||||
let public = app.get();
|
||||
let public_matches = public.state.unwrap_matches();
|
||||
|
||||
assert_eq!(public_matches.matching, Some(&matches_info_vec[0].matching));
|
||||
assert_eq!(
|
||||
public_matches.matches,
|
||||
Some(matches_info_vec[0].matches.as_slice())
|
||||
public_matches.matches.as_ref().unwrap().matching,
|
||||
&matches_info_vec[0].matching
|
||||
);
|
||||
assert_eq!(
|
||||
public_matches.matches.as_ref().unwrap().list,
|
||||
matches_info_vec[0].matches.as_slice()
|
||||
);
|
||||
assert_eq!(public_matches.state, &widget_state);
|
||||
}
|
||||
|
@ -129,9 +129,14 @@ pub struct AppPublicInner<'app> {
|
||||
pub selection: &'app mut Selection,
|
||||
}
|
||||
|
||||
#[derive(Debug, PartialEq, Eq)]
|
||||
pub struct AppPublicAlbumMatches<'app> {
|
||||
pub matching: &'app Album,
|
||||
pub list: &'app [Match<Album>],
|
||||
}
|
||||
|
||||
pub struct AppPublicMatches<'app> {
|
||||
pub matching: Option<&'app Album>,
|
||||
pub matches: Option<&'app [Match<Album>]>,
|
||||
pub matches: Option<AppPublicAlbumMatches<'app>>,
|
||||
pub state: &'app mut WidgetState,
|
||||
}
|
||||
|
||||
|
@ -59,7 +59,9 @@ impl Minibuffer<'_> {
|
||||
},
|
||||
AppState::Matches(public) => Minibuffer {
|
||||
paragraphs: vec![
|
||||
Paragraph::new(UiDisplay::display_matching_info(public.matching)),
|
||||
Paragraph::new(UiDisplay::display_matching_info(
|
||||
public.matches.as_ref().map(|m| m.matching),
|
||||
)),
|
||||
Paragraph::new("q: abort"),
|
||||
],
|
||||
columns: 2,
|
||||
|
@ -15,7 +15,6 @@ use musichoard::collection::{album::Album, Collection};
|
||||
|
||||
use crate::tui::{
|
||||
app::{AppPublicState, AppState, Category, IAppAccess, Selection, WidgetState},
|
||||
lib::interface::musicbrainz::Match,
|
||||
ui::{
|
||||
browse::{
|
||||
AlbumArea, AlbumState, ArtistArea, ArtistState, FrameArea, TrackArea, TrackState,
|
||||
@ -31,6 +30,8 @@ use crate::tui::{
|
||||
},
|
||||
};
|
||||
|
||||
use super::app::AppPublicAlbumMatches;
|
||||
|
||||
pub trait IUi {
|
||||
fn render<APP: IAppAccess>(app: &mut APP, frame: &mut Frame);
|
||||
}
|
||||
@ -133,14 +134,17 @@ impl Ui {
|
||||
}
|
||||
|
||||
fn render_matches_overlay(
|
||||
matching: Option<&Album>,
|
||||
matches: Option<&[Match<Album>]>,
|
||||
matches: Option<AppPublicAlbumMatches>,
|
||||
state: &mut WidgetState,
|
||||
frame: &mut Frame,
|
||||
) {
|
||||
let area = OverlayBuilder::default().build(frame.size());
|
||||
let (matching, list) = match matches {
|
||||
Some(m) => (Some(m.matching), Some(m.list)),
|
||||
None => (None, None),
|
||||
};
|
||||
let matching_string = UiDisplay::display_matching_info(matching);
|
||||
let st = AlbumMatchesState::new(matches.unwrap_or_default(), state);
|
||||
let st = AlbumMatchesState::new(list.unwrap_or_default(), state);
|
||||
UiWidget::render_overlay_list_widget(&matching_string, st.list, st.state, true, area, frame)
|
||||
}
|
||||
|
||||
@ -167,7 +171,7 @@ impl IUi for Ui {
|
||||
match state {
|
||||
AppState::Info(_) => Self::render_info_overlay(collection, selection, frame),
|
||||
AppState::Matches(public) => {
|
||||
Self::render_matches_overlay(public.matching, public.matches, public.state, frame)
|
||||
Self::render_matches_overlay(public.matches, public.state, frame)
|
||||
}
|
||||
AppState::Reload(_) => Self::render_reload_overlay(frame),
|
||||
AppState::Error(msg) => Self::render_error_overlay("Error", msg, frame),
|
||||
@ -185,7 +189,8 @@ mod tests {
|
||||
};
|
||||
|
||||
use crate::tui::{
|
||||
app::{AppPublic, AppPublicInner, AppPublicMatches, Delta},
|
||||
app::{AppPublic, AppPublicAlbumMatches, AppPublicInner, AppPublicMatches, Delta},
|
||||
lib::interface::musicbrainz::Match,
|
||||
testmod::COLLECTION,
|
||||
tests::terminal,
|
||||
};
|
||||
@ -206,8 +211,10 @@ mod tests {
|
||||
AppState::Reload(()) => AppState::Reload(()),
|
||||
AppState::Search(s) => AppState::Search(s),
|
||||
AppState::Matches(ref mut m) => AppState::Matches(AppPublicMatches {
|
||||
matching: m.matching,
|
||||
matches: m.matches,
|
||||
matches: m.matches.as_ref().map(|matches| AppPublicAlbumMatches {
|
||||
matching: matches.matching,
|
||||
list: matches.list,
|
||||
}),
|
||||
state: m.state,
|
||||
}),
|
||||
AppState::Error(s) => AppState::Error(s),
|
||||
@ -256,8 +263,10 @@ mod tests {
|
||||
widget_state.list.select(Some(0));
|
||||
|
||||
app.state = AppState::Matches(AppPublicMatches {
|
||||
matching: Some(&album),
|
||||
matches: Some(&album_matches),
|
||||
matches: Some(AppPublicAlbumMatches {
|
||||
matching: &album,
|
||||
list: &album_matches,
|
||||
}),
|
||||
state: &mut widget_state,
|
||||
});
|
||||
terminal.draw(|frame| Ui::render(&mut app, frame)).unwrap();
|
||||
@ -265,7 +274,6 @@ mod tests {
|
||||
let mut widget_state = WidgetState::default();
|
||||
|
||||
app.state = AppState::Matches(AppPublicMatches {
|
||||
matching: None,
|
||||
matches: None,
|
||||
state: &mut widget_state,
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user