Integrate browse API into TUI MB daemon #230

Merged
wojtek merged 15 commits from 160---provide-a-keyboard-shortcut-to-pull-all-release-groups-of-an-artist into main 2024-10-06 15:32:46 +02:00
10 changed files with 85 additions and 83 deletions
Showing only changes of commit 46d38d9274 - Show all commits

View File

@ -288,7 +288,7 @@ mod tests {
use crate::tui::{ use crate::tui::{
app::{ app::{
machine::tests::{inner, music_hoard}, machine::tests::{inner, music_hoard},
Delta, IApp, IAppAccess, IAppInteractBrowse, MatchOption, MatchStateInfo, Delta, EntityMatches, IApp, IAppAccess, IAppInteractBrowse, MatchOption,
}, },
lib::interface::musicbrainz::{self, api::Entity, daemon::MockIMbJobSender}, lib::interface::musicbrainz::{self, api::Entity, daemon::MockIMbJobSender},
testmod::COLLECTION, testmod::COLLECTION,
@ -311,13 +311,13 @@ mod tests {
let artist = COLLECTION[3].meta.clone(); let artist = COLLECTION[3].meta.clone();
let matches: Vec<Entity<ArtistMeta>> = vec![]; let matches: Vec<Entity<ArtistMeta>> = vec![];
let fetch_result = MatchStateInfo::artist_search(artist.clone(), matches); let fetch_result = EntityMatches::artist_search(artist.clone(), matches);
fetch_tx.send(Ok(fetch_result.clone())).unwrap(); fetch_tx.send(Ok(fetch_result.clone())).unwrap();
assert_eq!(fetch.try_recv(), Err(TryRecvError::Empty)); assert_eq!(fetch.try_recv(), Err(TryRecvError::Empty));
let lookup = Entity::new(artist.clone()); let lookup = Entity::new(artist.clone());
let lookup_result = MatchStateInfo::artist_lookup(artist.clone(), lookup); let lookup_result = EntityMatches::artist_lookup(artist.clone(), lookup);
lookup_tx.send(Ok(lookup_result.clone())).unwrap(); lookup_tx.send(Ok(lookup_result.clone())).unwrap();
assert_eq!(fetch.try_recv(), Ok(Ok(lookup_result))); assert_eq!(fetch.try_recv(), Ok(Ok(lookup_result)));
@ -603,7 +603,7 @@ mod tests {
let artist = COLLECTION[3].meta.clone(); let artist = COLLECTION[3].meta.clone();
let artist_match = Entity::with_score(COLLECTION[2].meta.clone(), 80); let artist_match = Entity::with_score(COLLECTION[2].meta.clone(), 80);
let artist_match_info = let artist_match_info =
MatchStateInfo::artist_search(artist.clone(), vec![artist_match.clone()]); EntityMatches::artist_search(artist.clone(), vec![artist_match.clone()]);
let fetch_result = Ok(artist_match_info); let fetch_result = Ok(artist_match_info);
tx.send(fetch_result).unwrap(); tx.send(fetch_result).unwrap();
@ -619,8 +619,8 @@ mod tests {
MatchOption::CannotHaveMbid, MatchOption::CannotHaveMbid,
MatchOption::ManualInputMbid, MatchOption::ManualInputMbid,
]; ];
let expected = MatchStateInfo::artist_search(artist, match_options); let expected = EntityMatches::artist_search(artist, match_options);
assert_eq!(match_state.info, &expected); assert_eq!(match_state.matches, &expected);
} }
#[test] #[test]
@ -677,7 +677,7 @@ mod tests {
assert!(matches!(app, AppState::Fetch(_))); assert!(matches!(app, AppState::Fetch(_)));
let artist = COLLECTION[3].meta.clone(); let artist = COLLECTION[3].meta.clone();
let match_info = MatchStateInfo::artist_search::<Entity<ArtistMeta>>(artist, vec![]); let match_info = EntityMatches::artist_search::<Entity<ArtistMeta>>(artist, vec![]);
let fetch_result = Ok(match_info); let fetch_result = Ok(match_info);
tx.send(fetch_result).unwrap(); tx.send(fetch_result).unwrap();

View File

@ -8,8 +8,8 @@ use musichoard::collection::{
use crate::tui::app::{ use crate::tui::app::{
machine::{fetch_state::FetchState, input::Input, App, AppInner, AppMachine}, machine::{fetch_state::FetchState, input::Input, App, AppInner, AppMachine},
AlbumMatches, AppPublicState, AppState, ArtistMatches, Delta, IAppInteractMatch, MatchOption, AlbumMatches, AppPublicState, AppState, ArtistMatches, Delta, EntityMatches, IAppInteractMatch,
MatchStateInfo, MatchStatePublic, WidgetState, MatchOption, MatchStatePublic, WidgetState,
}; };
trait GetInfoMeta { trait GetInfoMeta {
@ -103,7 +103,7 @@ impl AlbumMatches {
} }
} }
impl MatchStateInfo { impl EntityMatches {
fn len(&self) -> usize { fn len(&self) -> usize {
match self { match self {
Self::Artist(a) => a.len(), Self::Artist(a) => a.len(),
@ -127,13 +127,13 @@ impl MatchStateInfo {
} }
pub struct MatchState { pub struct MatchState {
current: MatchStateInfo, current: EntityMatches,
state: WidgetState, state: WidgetState,
fetch: FetchState, fetch: FetchState,
} }
impl MatchState { impl MatchState {
pub fn new(mut current: MatchStateInfo, fetch: FetchState) -> Self { pub fn new(mut current: EntityMatches, fetch: FetchState) -> Self {
current.push_cannot_have_mbid(); current.push_cannot_have_mbid();
current.push_manual_input_mbid(); current.push_manual_input_mbid();
@ -158,11 +158,11 @@ impl AppMachine<MatchState> {
Err(err) => return AppMachine::error_state(self.inner, err.to_string()).into(), Err(err) => return AppMachine::error_state(self.inner, err.to_string()).into(),
}; };
match self.state.current { match self.state.current {
MatchStateInfo::Artist(artist_matches) => { EntityMatches::Artist(artist_matches) => {
let matching = &artist_matches.matching; let matching = &artist_matches.matching;
AppMachine::app_lookup_artist(self.inner, self.state.fetch, matching, mbid) AppMachine::app_lookup_artist(self.inner, self.state.fetch, matching, mbid)
} }
MatchStateInfo::Album(album_matches) => { EntityMatches::Album(album_matches) => {
let artist_id = &album_matches.artist; let artist_id = &album_matches.artist;
let matching = &album_matches.matching; let matching = &album_matches.matching;
AppMachine::app_lookup_album( AppMachine::app_lookup_album(
@ -191,7 +191,7 @@ impl From<AppMachine<MatchState>> for App {
impl<'a> From<&'a mut MatchState> for AppPublicState<'a> { impl<'a> From<&'a mut MatchState> for AppPublicState<'a> {
fn from(state: &'a mut MatchState) -> Self { fn from(state: &'a mut MatchState) -> Self {
AppState::Match(MatchStatePublic { AppState::Match(MatchStatePublic {
info: &state.current, matches: &state.current,
state: &mut state.state, state: &mut state.state,
}) })
} }
@ -225,14 +225,14 @@ impl IAppInteractMatch for AppMachine<MatchState> {
let mh = &mut self.inner.music_hoard; let mh = &mut self.inner.music_hoard;
let result = match self.state.current { let result = match self.state.current {
MatchStateInfo::Artist(ref mut matches) => { EntityMatches::Artist(ref mut matches) => {
let info: ArtistInfo = matches.matching.info.clone(); let info: ArtistInfo = matches.matching.info.clone();
match matches.list.extract_info(index, info) { match matches.list.extract_info(index, info) {
InfoOption::Info(info) => mh.set_artist_info(&matches.matching.id, info), InfoOption::Info(info) => mh.set_artist_info(&matches.matching.id, info),
InfoOption::NeedInput => return self.get_input(), InfoOption::NeedInput => return self.get_input(),
} }
} }
MatchStateInfo::Album(ref mut matches) => { EntityMatches::Album(ref mut matches) => {
let info: AlbumInfo = matches.matching.info.clone(); let info: AlbumInfo = matches.matching.info.clone();
match matches.list.extract_info(index, info) { match matches.list.extract_info(index, info) {
InfoOption::Info(info) => { InfoOption::Info(info) => {
@ -298,7 +298,7 @@ mod tests {
meta meta
} }
fn artist_match() -> MatchStateInfo { fn artist_match() -> EntityMatches {
let artist = artist_meta(); let artist = artist_meta();
let artist_1 = artist.clone(); let artist_1 = artist.clone();
@ -309,13 +309,13 @@ mod tests {
artist_match_2.disambiguation = Some(String::from("some disambiguation")); artist_match_2.disambiguation = Some(String::from("some disambiguation"));
let list = vec![artist_match_1.clone(), artist_match_2.clone()]; let list = vec![artist_match_1.clone(), artist_match_2.clone()];
MatchStateInfo::artist_search(artist, list) EntityMatches::artist_search(artist, list)
} }
fn artist_lookup() -> MatchStateInfo { fn artist_lookup() -> EntityMatches {
let artist = artist_meta(); let artist = artist_meta();
let lookup = Entity::new(artist.clone()); let lookup = Entity::new(artist.clone());
MatchStateInfo::artist_lookup(artist, lookup) EntityMatches::artist_lookup(artist, lookup)
} }
fn album_meta() -> AlbumMeta { fn album_meta() -> AlbumMeta {
@ -330,7 +330,7 @@ mod tests {
) )
} }
fn album_match() -> MatchStateInfo { fn album_match() -> EntityMatches {
let artist_id = ArtistId::new("Artist"); let artist_id = ArtistId::new("Artist");
let album = album_meta(); let album = album_meta();
@ -343,14 +343,14 @@ mod tests {
let album_match_2 = Entity::with_score(album_2, 100); let album_match_2 = Entity::with_score(album_2, 100);
let list = vec![album_match_1.clone(), album_match_2.clone()]; let list = vec![album_match_1.clone(), album_match_2.clone()];
MatchStateInfo::album_search(artist_id, album, list) EntityMatches::album_search(artist_id, album, list)
} }
fn album_lookup() -> MatchStateInfo { fn album_lookup() -> EntityMatches {
let artist_id = ArtistId::new("Artist"); let artist_id = ArtistId::new("Artist");
let album = album_meta(); let album = album_meta();
let lookup = Entity::new(album.clone()); let lookup = Entity::new(album.clone());
MatchStateInfo::album_lookup(artist_id, album, lookup) EntityMatches::album_lookup(artist_id, album, lookup)
} }
fn fetch_state() -> FetchState { fn fetch_state() -> FetchState {
@ -358,7 +358,7 @@ mod tests {
FetchState::new(rx) FetchState::new(rx)
} }
fn match_state(match_state_info: MatchStateInfo) -> MatchState { fn match_state(match_state_info: EntityMatches) -> MatchState {
MatchState::new(match_state_info, fetch_state()) MatchState::new(match_state_info, fetch_state())
} }
@ -379,11 +379,11 @@ mod tests {
let public = app.get(); let public = app.get();
let public_matches = public.state.unwrap_match(); let public_matches = public.state.unwrap_match();
assert_eq!(public_matches.info, &album_match); assert_eq!(public_matches.matches, &album_match);
assert_eq!(public_matches.state, &widget_state); assert_eq!(public_matches.state, &widget_state);
} }
fn match_state_flow(mut matches_info: MatchStateInfo, len: usize) { fn match_state_flow(mut matches_info: EntityMatches, len: usize) {
// tx must exist for rx to return Empty rather than Disconnected. // tx must exist for rx to return Empty rather than Disconnected.
let (_tx, rx) = mpsc::channel(); let (_tx, rx) = mpsc::channel();
let app_matches = MatchState::new(matches_info.clone(), FetchState::new(rx)); let app_matches = MatchState::new(matches_info.clone(), FetchState::new(rx));
@ -391,7 +391,7 @@ mod tests {
let mut music_hoard = music_hoard(vec![]); let mut music_hoard = music_hoard(vec![]);
let artist_id = ArtistId::new("Artist"); let artist_id = ArtistId::new("Artist");
match matches_info { match matches_info {
MatchStateInfo::Album(_) => { EntityMatches::Album(_) => {
let album_id = AlbumId::new("Album"); let album_id = AlbumId::new("Album");
let mut info = album_meta().info; let mut info = album_meta().info;
info.musicbrainz = MbRefOption::CannotHaveMbid; info.musicbrainz = MbRefOption::CannotHaveMbid;
@ -401,7 +401,7 @@ mod tests {
.times(1) .times(1)
.return_once(|_, _, _| Ok(())); .return_once(|_, _, _| Ok(()));
} }
MatchStateInfo::Artist(_) => { EntityMatches::Artist(_) => {
let mut info = artist_meta().info; let mut info = artist_meta().info;
info.musicbrainz = MbRefOption::CannotHaveMbid; info.musicbrainz = MbRefOption::CannotHaveMbid;
music_hoard music_hoard
@ -485,8 +485,8 @@ mod tests {
let mut music_hoard = music_hoard(vec![]); let mut music_hoard = music_hoard(vec![]);
match matches_info { match matches_info {
MatchStateInfo::Album(_) => panic!(), EntityMatches::Album(_) => panic!(),
MatchStateInfo::Artist(_) => { EntityMatches::Artist(_) => {
let meta = artist_meta(); let meta = artist_meta();
music_hoard music_hoard
.expect_set_artist_info() .expect_set_artist_info()
@ -509,8 +509,8 @@ mod tests {
let mut music_hoard = music_hoard(vec![]); let mut music_hoard = music_hoard(vec![]);
match matches_info { match matches_info {
MatchStateInfo::Artist(_) => panic!(), EntityMatches::Artist(_) => panic!(),
MatchStateInfo::Album(matches) => { EntityMatches::Album(matches) => {
let meta = album_meta(); let meta = album_meta();
music_hoard music_hoard
.expect_set_album_info() .expect_set_album_info()
@ -533,8 +533,8 @@ mod tests {
let mut music_hoard = music_hoard(vec![]); let mut music_hoard = music_hoard(vec![]);
match matches_info { match matches_info {
MatchStateInfo::Album(_) => panic!(), EntityMatches::Album(_) => panic!(),
MatchStateInfo::Artist(_) => { EntityMatches::Artist(_) => {
music_hoard.expect_set_artist_info().return_once(|_, _| { music_hoard.expect_set_artist_info().return_once(|_, _| {
Err(musichoard::Error::DatabaseError(String::from("error"))) Err(musichoard::Error::DatabaseError(String::from("error")))
}); });
@ -598,7 +598,7 @@ mod tests {
.return_once(|_, _| Ok(())); .return_once(|_, _| Ok(()));
let matches_vec: Vec<Entity<ArtistMeta>> = vec![]; let matches_vec: Vec<Entity<ArtistMeta>> = vec![];
let artist_match = MatchStateInfo::artist_search(artist.clone(), matches_vec); let artist_match = EntityMatches::artist_search(artist.clone(), matches_vec);
let matches = AppMachine::match_state( let matches = AppMachine::match_state(
inner_with_mb(music_hoard(vec![]), mb_job_sender), inner_with_mb(music_hoard(vec![]), mb_job_sender),
match_state(artist_match), match_state(artist_match),
@ -632,7 +632,7 @@ mod tests {
let matches_vec: Vec<Entity<AlbumMeta>> = vec![]; let matches_vec: Vec<Entity<AlbumMeta>> = vec![];
let album_match = let album_match =
MatchStateInfo::album_search(artist_id.clone(), album.clone(), matches_vec); EntityMatches::album_search(artist_id.clone(), album.clone(), matches_vec);
let matches = AppMachine::match_state( let matches = AppMachine::match_state(
inner_with_mb(music_hoard(vec![]), mb_job_sender), inner_with_mb(music_hoard(vec![]), mb_job_sender),
match_state(album_match), match_state(album_match),

View File

@ -225,7 +225,7 @@ mod tests {
}; };
use crate::tui::{ use crate::tui::{
app::{AppState, IApp, IAppInput, IAppInteractBrowse, InputEvent, MatchStateInfo}, app::{AppState, EntityMatches, IApp, IAppInput, IAppInteractBrowse, InputEvent},
lib::{ lib::{
interface::musicbrainz::{api::Entity, daemon::MockIMbJobSender}, interface::musicbrainz::{api::Entity, daemon::MockIMbJobSender},
MockIMusicHoard, MockIMusicHoard,
@ -520,7 +520,7 @@ mod tests {
let (_, rx) = mpsc::channel(); let (_, rx) = mpsc::channel();
let fetch = FetchState::new(rx); let fetch = FetchState::new(rx);
let artist = ArtistMeta::new(ArtistId::new("Artist")); let artist = ArtistMeta::new(ArtistId::new("Artist"));
let info = MatchStateInfo::artist_lookup(artist.clone(), Entity::new(artist.clone())); let info = EntityMatches::artist_lookup(artist.clone(), Entity::new(artist.clone()));
app = app =
AppMachine::match_state(app.unwrap_browse().inner, MatchState::new(info, fetch)).into(); AppMachine::match_state(app.unwrap_browse().inner, MatchState::new(info, fetch)).into();

View File

@ -240,18 +240,18 @@ pub struct AlbumMatches {
} }
#[derive(Clone, Debug, PartialEq, Eq)] #[derive(Clone, Debug, PartialEq, Eq)]
pub enum MatchStateInfo { pub enum EntityMatches {
Artist(ArtistMatches), Artist(ArtistMatches),
Album(AlbumMatches), Album(AlbumMatches),
} }
impl MatchStateInfo { impl EntityMatches {
pub fn artist_search<M: Into<MatchOption<ArtistMeta>>>( pub fn artist_search<M: Into<MatchOption<ArtistMeta>>>(
matching: ArtistMeta, matching: ArtistMeta,
list: Vec<M>, list: Vec<M>,
) -> Self { ) -> Self {
let list = list.into_iter().map(Into::into).collect(); let list = list.into_iter().map(Into::into).collect();
MatchStateInfo::Artist(ArtistMatches { matching, list }) EntityMatches::Artist(ArtistMatches { matching, list })
} }
pub fn album_search<M: Into<MatchOption<AlbumMeta>>>( pub fn album_search<M: Into<MatchOption<AlbumMeta>>>(
@ -260,7 +260,7 @@ impl MatchStateInfo {
list: Vec<M>, list: Vec<M>,
) -> Self { ) -> Self {
let list = list.into_iter().map(Into::into).collect(); let list = list.into_iter().map(Into::into).collect();
MatchStateInfo::Album(AlbumMatches { EntityMatches::Album(AlbumMatches {
artist, artist,
matching, matching,
list, list,
@ -269,7 +269,7 @@ impl MatchStateInfo {
pub fn artist_lookup<M: Into<MatchOption<ArtistMeta>>>(matching: ArtistMeta, item: M) -> Self { pub fn artist_lookup<M: Into<MatchOption<ArtistMeta>>>(matching: ArtistMeta, item: M) -> Self {
let list = vec![item.into()]; let list = vec![item.into()];
MatchStateInfo::Artist(ArtistMatches { matching, list }) EntityMatches::Artist(ArtistMatches { matching, list })
} }
pub fn album_lookup<M: Into<MatchOption<AlbumMeta>>>( pub fn album_lookup<M: Into<MatchOption<AlbumMeta>>>(
@ -278,7 +278,7 @@ impl MatchStateInfo {
item: M, item: M,
) -> Self { ) -> Self {
let list = vec![item.into()]; let list = vec![item.into()];
MatchStateInfo::Album(AlbumMatches { EntityMatches::Album(AlbumMatches {
artist, artist,
matching, matching,
list, list,
@ -287,7 +287,7 @@ impl MatchStateInfo {
} }
pub struct MatchStatePublic<'app> { pub struct MatchStatePublic<'app> {
pub info: &'app MatchStateInfo, pub matches: &'app EntityMatches,
pub state: &'app mut WidgetState, pub state: &'app mut WidgetState,
} }

View File

@ -1,7 +1,7 @@
use std::{collections::VecDeque, sync::mpsc, thread, time}; use std::{collections::VecDeque, sync::mpsc, thread, time};
use crate::tui::{ use crate::tui::{
app::MatchStateInfo, app::EntityMatches,
event::IFetchCompleteEventSender, event::IFetchCompleteEventSender,
lib::interface::musicbrainz::{ lib::interface::musicbrainz::{
api::{Error as ApiError, IMusicBrainz}, api::{Error as ApiError, IMusicBrainz},
@ -242,18 +242,18 @@ impl JobInstance {
MbParams::Lookup(lookup) => match lookup { MbParams::Lookup(lookup) => match lookup {
LookupParams::Artist(params) => musicbrainz LookupParams::Artist(params) => musicbrainz
.lookup_artist(&params.mbid) .lookup_artist(&params.mbid)
.map(|rv| MatchStateInfo::artist_lookup(params.artist, rv)), .map(|rv| EntityMatches::artist_lookup(params.artist, rv)),
LookupParams::ReleaseGroup(params) => musicbrainz LookupParams::ReleaseGroup(params) => musicbrainz
.lookup_release_group(&params.mbid) .lookup_release_group(&params.mbid)
.map(|rv| MatchStateInfo::album_lookup(params.artist_id, params.album, rv)), .map(|rv| EntityMatches::album_lookup(params.artist_id, params.album, rv)),
}, },
MbParams::Search(search) => match search { MbParams::Search(search) => match search {
SearchParams::Artist(params) => musicbrainz SearchParams::Artist(params) => musicbrainz
.search_artist(&params.artist) .search_artist(&params.artist)
.map(|rv| MatchStateInfo::artist_search(params.artist, rv)), .map(|rv| EntityMatches::artist_search(params.artist, rv)),
SearchParams::ReleaseGroup(params) => musicbrainz SearchParams::ReleaseGroup(params) => musicbrainz
.search_release_group(&params.artist_mbid, &params.album) .search_release_group(&params.artist_mbid, &params.album)
.map(|rv| MatchStateInfo::album_search(params.artist_id, params.album, rv)), .map(|rv| EntityMatches::album_search(params.artist_id, params.album, rv)),
}, },
}; };
self.return_result(event_sender, result) self.return_result(event_sender, result)
@ -262,7 +262,7 @@ impl JobInstance {
fn return_result( fn return_result(
&mut self, &mut self,
event_sender: &mut dyn IFetchCompleteEventSender, event_sender: &mut dyn IFetchCompleteEventSender,
result: Result<MatchStateInfo, ApiError>, result: Result<EntityMatches, ApiError>,
) -> Result<(), JobInstanceError> { ) -> Result<(), JobInstanceError> {
self.result_sender self.result_sender
.send(result) .send(result)
@ -575,7 +575,7 @@ mod tests {
assert_eq!(result, Ok(())); assert_eq!(result, Ok(()));
let result = result_receiver.try_recv().unwrap(); let result = result_receiver.try_recv().unwrap();
assert_eq!(result, Ok(MatchStateInfo::artist_lookup(artist, lookup))); assert_eq!(result, Ok(EntityMatches::artist_lookup(artist, lookup)));
} }
fn lookup_release_group_expectation( fn lookup_release_group_expectation(
@ -620,7 +620,7 @@ mod tests {
let artist_id = album_artist_id(); let artist_id = album_artist_id();
assert_eq!( assert_eq!(
result, result,
Ok(MatchStateInfo::album_lookup(artist_id, album, lookup)) Ok(EntityMatches::album_lookup(artist_id, album, lookup))
); );
} }
@ -661,7 +661,7 @@ mod tests {
assert_eq!(result, Ok(())); assert_eq!(result, Ok(()));
let result = result_receiver.try_recv().unwrap(); let result = result_receiver.try_recv().unwrap();
assert_eq!(result, Ok(MatchStateInfo::artist_search(artist, matches))); assert_eq!(result, Ok(EntityMatches::artist_search(artist, matches)));
} }
fn search_release_group_expectation( fn search_release_group_expectation(
@ -716,7 +716,7 @@ mod tests {
let result = result_receiver.try_recv().unwrap(); let result = result_receiver.try_recv().unwrap();
assert_eq!( assert_eq!(
result, result,
Ok(MatchStateInfo::album_search( Ok(EntityMatches::album_search(
artist_id.clone(), artist_id.clone(),
album_1, album_1,
matches_1 matches_1
@ -726,7 +726,7 @@ mod tests {
let result = result_receiver.try_recv().unwrap(); let result = result_receiver.try_recv().unwrap();
assert_eq!( assert_eq!(
result, result,
Ok(MatchStateInfo::album_search( Ok(EntityMatches::album_search(
artist_id.clone(), artist_id.clone(),
album_4, album_4,
matches_4 matches_4

View File

@ -6,7 +6,7 @@ use musichoard::collection::{
musicbrainz::Mbid, musicbrainz::Mbid,
}; };
use crate::tui::{app::MatchStateInfo, lib::interface::musicbrainz::api::Error as MbApiError}; use crate::tui::{app::EntityMatches, lib::interface::musicbrainz::api::Error as MbApiError};
#[cfg(test)] #[cfg(test)]
use mockall::automock; use mockall::automock;
@ -26,7 +26,7 @@ impl fmt::Display for Error {
} }
} }
pub type MbApiResult = Result<MatchStateInfo, MbApiError>; pub type MbApiResult = Result<EntityMatches, MbApiError>;
pub type ResultSender = mpsc::Sender<MbApiResult>; pub type ResultSender = mpsc::Sender<MbApiResult>;
#[cfg_attr(test, automock)] #[cfg_attr(test, automock)]

View File

@ -5,7 +5,7 @@ use musichoard::collection::{
track::{TrackFormat, TrackQuality}, track::{TrackFormat, TrackQuality},
}; };
use crate::tui::app::{MatchOption, MatchStateInfo}; use crate::tui::app::{EntityMatches, MatchOption};
pub struct UiDisplay; pub struct UiDisplay;
@ -119,10 +119,10 @@ impl UiDisplay {
) )
} }
pub fn display_matching_info(info: &MatchStateInfo) -> String { pub fn display_matching_info(info: &EntityMatches) -> String {
match info { match info {
MatchStateInfo::Artist(m) => UiDisplay::display_artist_matching(&m.matching), EntityMatches::Artist(m) => UiDisplay::display_artist_matching(&m.matching),
MatchStateInfo::Album(m) => UiDisplay::display_album_matching(&m.matching), EntityMatches::Album(m) => UiDisplay::display_album_matching(&m.matching),
} }
} }

View File

@ -2,7 +2,7 @@ use musichoard::collection::{album::AlbumMeta, artist::ArtistMeta};
use ratatui::widgets::{List, ListItem}; use ratatui::widgets::{List, ListItem};
use crate::tui::{ use crate::tui::{
app::{MatchOption, MatchStateInfo, WidgetState}, app::{EntityMatches, MatchOption, WidgetState},
ui::display::UiDisplay, ui::display::UiDisplay,
}; };
@ -13,10 +13,10 @@ pub struct MatchOverlay<'a, 'b> {
} }
impl<'a, 'b> MatchOverlay<'a, 'b> { impl<'a, 'b> MatchOverlay<'a, 'b> {
pub fn new(info: &'a MatchStateInfo, state: &'b mut WidgetState) -> Self { pub fn new(info: &'a EntityMatches, state: &'b mut WidgetState) -> Self {
match info { match info {
MatchStateInfo::Artist(m) => Self::artists(&m.matching, &m.list, state), EntityMatches::Artist(m) => Self::artists(&m.matching, &m.list, state),
MatchStateInfo::Album(m) => Self::albums(&m.matching, &m.list, state), EntityMatches::Album(m) => Self::albums(&m.matching, &m.list, state),
} }
} }

View File

@ -65,7 +65,7 @@ impl Minibuffer<'_> {
}, },
AppState::Match(public) => Minibuffer { AppState::Match(public) => Minibuffer {
paragraphs: vec![ paragraphs: vec![
Paragraph::new(UiDisplay::display_matching_info(public.info)), Paragraph::new(UiDisplay::display_matching_info(public.matches)),
Paragraph::new("ctrl+g: abort"), Paragraph::new("ctrl+g: abort"),
], ],
columns: 2, columns: 2,

View File

@ -18,7 +18,7 @@ use musichoard::collection::{album::Album, Collection};
use crate::tui::{ use crate::tui::{
app::{ app::{
AppPublicState, AppState, Category, IAppAccess, InputPublic, MatchStateInfo, Selection, AppPublicState, AppState, Category, EntityMatches, IAppAccess, InputPublic, Selection,
WidgetState, WidgetState,
}, },
ui::{ ui::{
@ -140,7 +140,7 @@ impl Ui {
UiWidget::render_overlay_widget("Fetching", fetch_text, area, false, frame) UiWidget::render_overlay_widget("Fetching", fetch_text, area, false, frame)
} }
fn render_match_overlay(info: &MatchStateInfo, state: &mut WidgetState, frame: &mut Frame) { fn render_match_overlay(info: &EntityMatches, state: &mut WidgetState, frame: &mut Frame) {
let area = OverlayBuilder::default().build(frame.area()); let area = OverlayBuilder::default().build(frame.area());
let st = MatchOverlay::new(info, state); let st = MatchOverlay::new(info, state);
UiWidget::render_overlay_list_widget(&st.matching, st.list, st.state, true, area, frame) UiWidget::render_overlay_list_widget(&st.matching, st.list, st.state, true, area, frame)
@ -182,7 +182,9 @@ impl IUi for Ui {
AppState::Info(()) => Self::render_info_overlay(collection, selection, frame), AppState::Info(()) => Self::render_info_overlay(collection, selection, frame),
AppState::Reload(()) => Self::render_reload_overlay(frame), AppState::Reload(()) => Self::render_reload_overlay(frame),
AppState::Fetch(()) => Self::render_fetch_overlay(frame), AppState::Fetch(()) => Self::render_fetch_overlay(frame),
AppState::Match(public) => Self::render_match_overlay(public.info, public.state, frame), AppState::Match(public) => {
Self::render_match_overlay(public.matches, public.state, frame)
}
AppState::Error(msg) => Self::render_error_overlay("Error", msg, frame), AppState::Error(msg) => Self::render_error_overlay("Error", msg, frame),
AppState::Critical(msg) => Self::render_error_overlay("Critical Error", msg, frame), AppState::Critical(msg) => Self::render_error_overlay("Critical Error", msg, frame),
_ => {} _ => {}
@ -226,7 +228,7 @@ mod tests {
AppState::Search(s) => AppState::Search(s), AppState::Search(s) => AppState::Search(s),
AppState::Fetch(()) => AppState::Fetch(()), AppState::Fetch(()) => AppState::Fetch(()),
AppState::Match(ref mut m) => AppState::Match(MatchStatePublic { AppState::Match(ref mut m) => AppState::Match(MatchStatePublic {
info: m.info, matches: m.matches,
state: m.state, state: m.state,
}), }),
AppState::Error(s) => AppState::Error(s), AppState::Error(s) => AppState::Error(s),
@ -329,22 +331,22 @@ mod tests {
ArtistMeta::new(ArtistId::new("an artist")) ArtistMeta::new(ArtistId::new("an artist"))
} }
fn artist_matches() -> MatchStateInfo { fn artist_matches() -> EntityMatches {
let artist = artist_meta(); let artist = artist_meta();
let artist_match = Entity::with_score(artist.clone(), 80); let artist_match = Entity::with_score(artist.clone(), 80);
let list = vec![artist_match.clone(), artist_match.clone()]; let list = vec![artist_match.clone(), artist_match.clone()];
let mut info = MatchStateInfo::artist_search(artist, list); let mut info = EntityMatches::artist_search(artist, list);
info.push_cannot_have_mbid(); info.push_cannot_have_mbid();
info.push_manual_input_mbid(); info.push_manual_input_mbid();
info info
} }
fn artist_lookup() -> MatchStateInfo { fn artist_lookup() -> EntityMatches {
let artist = artist_meta(); let artist = artist_meta();
let artist_lookup = Entity::new(artist.clone()); let artist_lookup = Entity::new(artist.clone());
let mut info = MatchStateInfo::artist_lookup(artist, artist_lookup); let mut info = EntityMatches::artist_lookup(artist, artist_lookup);
info.push_cannot_have_mbid(); info.push_cannot_have_mbid();
info.push_manual_input_mbid(); info.push_manual_input_mbid();
info info
@ -366,24 +368,24 @@ mod tests {
) )
} }
fn album_matches() -> MatchStateInfo { fn album_matches() -> EntityMatches {
let artist_id = album_artist_id(); let artist_id = album_artist_id();
let album = album_meta(); let album = album_meta();
let album_match = Entity::with_score(album.clone(), 80); let album_match = Entity::with_score(album.clone(), 80);
let list = vec![album_match.clone(), album_match.clone()]; let list = vec![album_match.clone(), album_match.clone()];
let mut info = MatchStateInfo::album_search(artist_id, album, list); let mut info = EntityMatches::album_search(artist_id, album, list);
info.push_cannot_have_mbid(); info.push_cannot_have_mbid();
info.push_manual_input_mbid(); info.push_manual_input_mbid();
info info
} }
fn album_lookup() -> MatchStateInfo { fn album_lookup() -> EntityMatches {
let artist_id = album_artist_id(); let artist_id = album_artist_id();
let album = album_meta(); let album = album_meta();
let album_lookup = Entity::new(album.clone()); let album_lookup = Entity::new(album.clone());
let mut info = MatchStateInfo::album_lookup(artist_id, album, album_lookup); let mut info = EntityMatches::album_lookup(artist_id, album, album_lookup);
info.push_cannot_have_mbid(); info.push_cannot_have_mbid();
info.push_manual_input_mbid(); info.push_manual_input_mbid();
info info
@ -403,13 +405,13 @@ mod tests {
album_lookup(), album_lookup(),
]; ];
for info in match_state_infos.iter() { for matches in match_state_infos.iter() {
let mut widget_state = WidgetState::default().with_selected(Some(0)); let mut widget_state = WidgetState::default().with_selected(Some(0));
let mut app = AppPublic { let mut app = AppPublic {
inner: public_inner(collection, &mut selection), inner: public_inner(collection, &mut selection),
state: AppState::Match(MatchStatePublic { state: AppState::Match(MatchStatePublic {
info, matches,
state: &mut widget_state, state: &mut widget_state,
}), }),
input: None, input: None,