Integrate browse API into TUI MB daemon #230
@ -288,7 +288,7 @@ mod tests {
|
||||
use crate::tui::{
|
||||
app::{
|
||||
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},
|
||||
testmod::COLLECTION,
|
||||
@ -311,13 +311,13 @@ mod tests {
|
||||
let artist = COLLECTION[3].meta.clone();
|
||||
|
||||
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();
|
||||
|
||||
assert_eq!(fetch.try_recv(), Err(TryRecvError::Empty));
|
||||
|
||||
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();
|
||||
|
||||
assert_eq!(fetch.try_recv(), Ok(Ok(lookup_result)));
|
||||
@ -603,7 +603,7 @@ mod tests {
|
||||
let artist = COLLECTION[3].meta.clone();
|
||||
let artist_match = Entity::with_score(COLLECTION[2].meta.clone(), 80);
|
||||
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);
|
||||
tx.send(fetch_result).unwrap();
|
||||
|
||||
@ -619,8 +619,8 @@ mod tests {
|
||||
MatchOption::CannotHaveMbid,
|
||||
MatchOption::ManualInputMbid,
|
||||
];
|
||||
let expected = MatchStateInfo::artist_search(artist, match_options);
|
||||
assert_eq!(match_state.info, &expected);
|
||||
let expected = EntityMatches::artist_search(artist, match_options);
|
||||
assert_eq!(match_state.matches, &expected);
|
||||
}
|
||||
|
||||
#[test]
|
||||
@ -677,7 +677,7 @@ mod tests {
|
||||
assert!(matches!(app, AppState::Fetch(_)));
|
||||
|
||||
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);
|
||||
tx.send(fetch_result).unwrap();
|
||||
|
||||
|
@ -8,8 +8,8 @@ use musichoard::collection::{
|
||||
|
||||
use crate::tui::app::{
|
||||
machine::{fetch_state::FetchState, input::Input, App, AppInner, AppMachine},
|
||||
AlbumMatches, AppPublicState, AppState, ArtistMatches, Delta, IAppInteractMatch, MatchOption,
|
||||
MatchStateInfo, MatchStatePublic, WidgetState,
|
||||
AlbumMatches, AppPublicState, AppState, ArtistMatches, Delta, EntityMatches, IAppInteractMatch,
|
||||
MatchOption, MatchStatePublic, WidgetState,
|
||||
};
|
||||
|
||||
trait GetInfoMeta {
|
||||
@ -103,7 +103,7 @@ impl AlbumMatches {
|
||||
}
|
||||
}
|
||||
|
||||
impl MatchStateInfo {
|
||||
impl EntityMatches {
|
||||
fn len(&self) -> usize {
|
||||
match self {
|
||||
Self::Artist(a) => a.len(),
|
||||
@ -127,13 +127,13 @@ impl MatchStateInfo {
|
||||
}
|
||||
|
||||
pub struct MatchState {
|
||||
current: MatchStateInfo,
|
||||
current: EntityMatches,
|
||||
state: WidgetState,
|
||||
fetch: FetchState,
|
||||
}
|
||||
|
||||
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_manual_input_mbid();
|
||||
|
||||
@ -158,11 +158,11 @@ impl AppMachine<MatchState> {
|
||||
Err(err) => return AppMachine::error_state(self.inner, err.to_string()).into(),
|
||||
};
|
||||
match self.state.current {
|
||||
MatchStateInfo::Artist(artist_matches) => {
|
||||
EntityMatches::Artist(artist_matches) => {
|
||||
let matching = &artist_matches.matching;
|
||||
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 matching = &album_matches.matching;
|
||||
AppMachine::app_lookup_album(
|
||||
@ -191,7 +191,7 @@ impl From<AppMachine<MatchState>> for App {
|
||||
impl<'a> From<&'a mut MatchState> for AppPublicState<'a> {
|
||||
fn from(state: &'a mut MatchState) -> Self {
|
||||
AppState::Match(MatchStatePublic {
|
||||
info: &state.current,
|
||||
matches: &state.current,
|
||||
state: &mut state.state,
|
||||
})
|
||||
}
|
||||
@ -225,14 +225,14 @@ impl IAppInteractMatch for AppMachine<MatchState> {
|
||||
|
||||
let mh = &mut self.inner.music_hoard;
|
||||
let result = match self.state.current {
|
||||
MatchStateInfo::Artist(ref mut matches) => {
|
||||
EntityMatches::Artist(ref mut matches) => {
|
||||
let info: ArtistInfo = matches.matching.info.clone();
|
||||
match matches.list.extract_info(index, info) {
|
||||
InfoOption::Info(info) => mh.set_artist_info(&matches.matching.id, info),
|
||||
InfoOption::NeedInput => return self.get_input(),
|
||||
}
|
||||
}
|
||||
MatchStateInfo::Album(ref mut matches) => {
|
||||
EntityMatches::Album(ref mut matches) => {
|
||||
let info: AlbumInfo = matches.matching.info.clone();
|
||||
match matches.list.extract_info(index, info) {
|
||||
InfoOption::Info(info) => {
|
||||
@ -298,7 +298,7 @@ mod tests {
|
||||
meta
|
||||
}
|
||||
|
||||
fn artist_match() -> MatchStateInfo {
|
||||
fn artist_match() -> EntityMatches {
|
||||
let artist = artist_meta();
|
||||
|
||||
let artist_1 = artist.clone();
|
||||
@ -309,13 +309,13 @@ mod tests {
|
||||
artist_match_2.disambiguation = Some(String::from("some disambiguation"));
|
||||
|
||||
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 lookup = Entity::new(artist.clone());
|
||||
MatchStateInfo::artist_lookup(artist, lookup)
|
||||
EntityMatches::artist_lookup(artist, lookup)
|
||||
}
|
||||
|
||||
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 album = album_meta();
|
||||
|
||||
@ -343,14 +343,14 @@ mod tests {
|
||||
let album_match_2 = Entity::with_score(album_2, 100);
|
||||
|
||||
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 album = album_meta();
|
||||
let lookup = Entity::new(album.clone());
|
||||
MatchStateInfo::album_lookup(artist_id, album, lookup)
|
||||
EntityMatches::album_lookup(artist_id, album, lookup)
|
||||
}
|
||||
|
||||
fn fetch_state() -> FetchState {
|
||||
@ -358,7 +358,7 @@ mod tests {
|
||||
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())
|
||||
}
|
||||
|
||||
@ -379,11 +379,11 @@ mod tests {
|
||||
let public = app.get();
|
||||
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);
|
||||
}
|
||||
|
||||
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.
|
||||
let (_tx, rx) = mpsc::channel();
|
||||
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 artist_id = ArtistId::new("Artist");
|
||||
match matches_info {
|
||||
MatchStateInfo::Album(_) => {
|
||||
EntityMatches::Album(_) => {
|
||||
let album_id = AlbumId::new("Album");
|
||||
let mut info = album_meta().info;
|
||||
info.musicbrainz = MbRefOption::CannotHaveMbid;
|
||||
@ -401,7 +401,7 @@ mod tests {
|
||||
.times(1)
|
||||
.return_once(|_, _, _| Ok(()));
|
||||
}
|
||||
MatchStateInfo::Artist(_) => {
|
||||
EntityMatches::Artist(_) => {
|
||||
let mut info = artist_meta().info;
|
||||
info.musicbrainz = MbRefOption::CannotHaveMbid;
|
||||
music_hoard
|
||||
@ -485,8 +485,8 @@ mod tests {
|
||||
|
||||
let mut music_hoard = music_hoard(vec![]);
|
||||
match matches_info {
|
||||
MatchStateInfo::Album(_) => panic!(),
|
||||
MatchStateInfo::Artist(_) => {
|
||||
EntityMatches::Album(_) => panic!(),
|
||||
EntityMatches::Artist(_) => {
|
||||
let meta = artist_meta();
|
||||
music_hoard
|
||||
.expect_set_artist_info()
|
||||
@ -509,8 +509,8 @@ mod tests {
|
||||
|
||||
let mut music_hoard = music_hoard(vec![]);
|
||||
match matches_info {
|
||||
MatchStateInfo::Artist(_) => panic!(),
|
||||
MatchStateInfo::Album(matches) => {
|
||||
EntityMatches::Artist(_) => panic!(),
|
||||
EntityMatches::Album(matches) => {
|
||||
let meta = album_meta();
|
||||
music_hoard
|
||||
.expect_set_album_info()
|
||||
@ -533,8 +533,8 @@ mod tests {
|
||||
|
||||
let mut music_hoard = music_hoard(vec![]);
|
||||
match matches_info {
|
||||
MatchStateInfo::Album(_) => panic!(),
|
||||
MatchStateInfo::Artist(_) => {
|
||||
EntityMatches::Album(_) => panic!(),
|
||||
EntityMatches::Artist(_) => {
|
||||
music_hoard.expect_set_artist_info().return_once(|_, _| {
|
||||
Err(musichoard::Error::DatabaseError(String::from("error")))
|
||||
});
|
||||
@ -598,7 +598,7 @@ mod tests {
|
||||
.return_once(|_, _| Ok(()));
|
||||
|
||||
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(
|
||||
inner_with_mb(music_hoard(vec![]), mb_job_sender),
|
||||
match_state(artist_match),
|
||||
@ -632,7 +632,7 @@ mod tests {
|
||||
|
||||
let matches_vec: Vec<Entity<AlbumMeta>> = vec![];
|
||||
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(
|
||||
inner_with_mb(music_hoard(vec![]), mb_job_sender),
|
||||
match_state(album_match),
|
||||
|
@ -225,7 +225,7 @@ mod tests {
|
||||
};
|
||||
|
||||
use crate::tui::{
|
||||
app::{AppState, IApp, IAppInput, IAppInteractBrowse, InputEvent, MatchStateInfo},
|
||||
app::{AppState, EntityMatches, IApp, IAppInput, IAppInteractBrowse, InputEvent},
|
||||
lib::{
|
||||
interface::musicbrainz::{api::Entity, daemon::MockIMbJobSender},
|
||||
MockIMusicHoard,
|
||||
@ -520,7 +520,7 @@ mod tests {
|
||||
let (_, rx) = mpsc::channel();
|
||||
let fetch = FetchState::new(rx);
|
||||
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 =
|
||||
AppMachine::match_state(app.unwrap_browse().inner, MatchState::new(info, fetch)).into();
|
||||
|
||||
|
@ -240,18 +240,18 @@ pub struct AlbumMatches {
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, Eq)]
|
||||
pub enum MatchStateInfo {
|
||||
pub enum EntityMatches {
|
||||
Artist(ArtistMatches),
|
||||
Album(AlbumMatches),
|
||||
}
|
||||
|
||||
impl MatchStateInfo {
|
||||
impl EntityMatches {
|
||||
pub fn artist_search<M: Into<MatchOption<ArtistMeta>>>(
|
||||
matching: ArtistMeta,
|
||||
list: Vec<M>,
|
||||
) -> Self {
|
||||
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>>>(
|
||||
@ -260,7 +260,7 @@ impl MatchStateInfo {
|
||||
list: Vec<M>,
|
||||
) -> Self {
|
||||
let list = list.into_iter().map(Into::into).collect();
|
||||
MatchStateInfo::Album(AlbumMatches {
|
||||
EntityMatches::Album(AlbumMatches {
|
||||
artist,
|
||||
matching,
|
||||
list,
|
||||
@ -269,7 +269,7 @@ impl MatchStateInfo {
|
||||
|
||||
pub fn artist_lookup<M: Into<MatchOption<ArtistMeta>>>(matching: ArtistMeta, item: M) -> Self {
|
||||
let list = vec![item.into()];
|
||||
MatchStateInfo::Artist(ArtistMatches { matching, list })
|
||||
EntityMatches::Artist(ArtistMatches { matching, list })
|
||||
}
|
||||
|
||||
pub fn album_lookup<M: Into<MatchOption<AlbumMeta>>>(
|
||||
@ -278,7 +278,7 @@ impl MatchStateInfo {
|
||||
item: M,
|
||||
) -> Self {
|
||||
let list = vec![item.into()];
|
||||
MatchStateInfo::Album(AlbumMatches {
|
||||
EntityMatches::Album(AlbumMatches {
|
||||
artist,
|
||||
matching,
|
||||
list,
|
||||
@ -287,7 +287,7 @@ impl MatchStateInfo {
|
||||
}
|
||||
|
||||
pub struct MatchStatePublic<'app> {
|
||||
pub info: &'app MatchStateInfo,
|
||||
pub matches: &'app EntityMatches,
|
||||
pub state: &'app mut WidgetState,
|
||||
}
|
||||
|
||||
|
22
src/tui/lib/external/musicbrainz/daemon/mod.rs
vendored
22
src/tui/lib/external/musicbrainz/daemon/mod.rs
vendored
@ -1,7 +1,7 @@
|
||||
use std::{collections::VecDeque, sync::mpsc, thread, time};
|
||||
|
||||
use crate::tui::{
|
||||
app::MatchStateInfo,
|
||||
app::EntityMatches,
|
||||
event::IFetchCompleteEventSender,
|
||||
lib::interface::musicbrainz::{
|
||||
api::{Error as ApiError, IMusicBrainz},
|
||||
@ -242,18 +242,18 @@ impl JobInstance {
|
||||
MbParams::Lookup(lookup) => match lookup {
|
||||
LookupParams::Artist(params) => musicbrainz
|
||||
.lookup_artist(¶ms.mbid)
|
||||
.map(|rv| MatchStateInfo::artist_lookup(params.artist, rv)),
|
||||
.map(|rv| EntityMatches::artist_lookup(params.artist, rv)),
|
||||
LookupParams::ReleaseGroup(params) => musicbrainz
|
||||
.lookup_release_group(¶ms.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 {
|
||||
SearchParams::Artist(params) => musicbrainz
|
||||
.search_artist(¶ms.artist)
|
||||
.map(|rv| MatchStateInfo::artist_search(params.artist, rv)),
|
||||
.map(|rv| EntityMatches::artist_search(params.artist, rv)),
|
||||
SearchParams::ReleaseGroup(params) => musicbrainz
|
||||
.search_release_group(¶ms.artist_mbid, ¶ms.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)
|
||||
@ -262,7 +262,7 @@ impl JobInstance {
|
||||
fn return_result(
|
||||
&mut self,
|
||||
event_sender: &mut dyn IFetchCompleteEventSender,
|
||||
result: Result<MatchStateInfo, ApiError>,
|
||||
result: Result<EntityMatches, ApiError>,
|
||||
) -> Result<(), JobInstanceError> {
|
||||
self.result_sender
|
||||
.send(result)
|
||||
@ -575,7 +575,7 @@ mod tests {
|
||||
assert_eq!(result, Ok(()));
|
||||
|
||||
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(
|
||||
@ -620,7 +620,7 @@ mod tests {
|
||||
let artist_id = album_artist_id();
|
||||
assert_eq!(
|
||||
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(()));
|
||||
|
||||
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(
|
||||
@ -716,7 +716,7 @@ mod tests {
|
||||
let result = result_receiver.try_recv().unwrap();
|
||||
assert_eq!(
|
||||
result,
|
||||
Ok(MatchStateInfo::album_search(
|
||||
Ok(EntityMatches::album_search(
|
||||
artist_id.clone(),
|
||||
album_1,
|
||||
matches_1
|
||||
@ -726,7 +726,7 @@ mod tests {
|
||||
let result = result_receiver.try_recv().unwrap();
|
||||
assert_eq!(
|
||||
result,
|
||||
Ok(MatchStateInfo::album_search(
|
||||
Ok(EntityMatches::album_search(
|
||||
artist_id.clone(),
|
||||
album_4,
|
||||
matches_4
|
||||
|
@ -6,7 +6,7 @@ use musichoard::collection::{
|
||||
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)]
|
||||
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>;
|
||||
|
||||
#[cfg_attr(test, automock)]
|
||||
|
@ -5,7 +5,7 @@ use musichoard::collection::{
|
||||
track::{TrackFormat, TrackQuality},
|
||||
};
|
||||
|
||||
use crate::tui::app::{MatchOption, MatchStateInfo};
|
||||
use crate::tui::app::{EntityMatches, MatchOption};
|
||||
|
||||
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 {
|
||||
MatchStateInfo::Artist(m) => UiDisplay::display_artist_matching(&m.matching),
|
||||
MatchStateInfo::Album(m) => UiDisplay::display_album_matching(&m.matching),
|
||||
EntityMatches::Artist(m) => UiDisplay::display_artist_matching(&m.matching),
|
||||
EntityMatches::Album(m) => UiDisplay::display_album_matching(&m.matching),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -2,7 +2,7 @@ use musichoard::collection::{album::AlbumMeta, artist::ArtistMeta};
|
||||
use ratatui::widgets::{List, ListItem};
|
||||
|
||||
use crate::tui::{
|
||||
app::{MatchOption, MatchStateInfo, WidgetState},
|
||||
app::{EntityMatches, MatchOption, WidgetState},
|
||||
ui::display::UiDisplay,
|
||||
};
|
||||
|
||||
@ -13,10 +13,10 @@ pub struct 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 {
|
||||
MatchStateInfo::Artist(m) => Self::artists(&m.matching, &m.list, state),
|
||||
MatchStateInfo::Album(m) => Self::albums(&m.matching, &m.list, state),
|
||||
EntityMatches::Artist(m) => Self::artists(&m.matching, &m.list, state),
|
||||
EntityMatches::Album(m) => Self::albums(&m.matching, &m.list, state),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -65,7 +65,7 @@ impl Minibuffer<'_> {
|
||||
},
|
||||
AppState::Match(public) => Minibuffer {
|
||||
paragraphs: vec![
|
||||
Paragraph::new(UiDisplay::display_matching_info(public.info)),
|
||||
Paragraph::new(UiDisplay::display_matching_info(public.matches)),
|
||||
Paragraph::new("ctrl+g: abort"),
|
||||
],
|
||||
columns: 2,
|
||||
|
@ -18,7 +18,7 @@ use musichoard::collection::{album::Album, Collection};
|
||||
|
||||
use crate::tui::{
|
||||
app::{
|
||||
AppPublicState, AppState, Category, IAppAccess, InputPublic, MatchStateInfo, Selection,
|
||||
AppPublicState, AppState, Category, EntityMatches, IAppAccess, InputPublic, Selection,
|
||||
WidgetState,
|
||||
},
|
||||
ui::{
|
||||
@ -140,7 +140,7 @@ impl Ui {
|
||||
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 st = MatchOverlay::new(info, state);
|
||||
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::Reload(()) => Self::render_reload_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::Critical(msg) => Self::render_error_overlay("Critical Error", msg, frame),
|
||||
_ => {}
|
||||
@ -226,7 +228,7 @@ mod tests {
|
||||
AppState::Search(s) => AppState::Search(s),
|
||||
AppState::Fetch(()) => AppState::Fetch(()),
|
||||
AppState::Match(ref mut m) => AppState::Match(MatchStatePublic {
|
||||
info: m.info,
|
||||
matches: m.matches,
|
||||
state: m.state,
|
||||
}),
|
||||
AppState::Error(s) => AppState::Error(s),
|
||||
@ -329,22 +331,22 @@ mod tests {
|
||||
ArtistMeta::new(ArtistId::new("an artist"))
|
||||
}
|
||||
|
||||
fn artist_matches() -> MatchStateInfo {
|
||||
fn artist_matches() -> EntityMatches {
|
||||
let artist = artist_meta();
|
||||
let artist_match = Entity::with_score(artist.clone(), 80);
|
||||
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_manual_input_mbid();
|
||||
info
|
||||
}
|
||||
|
||||
fn artist_lookup() -> MatchStateInfo {
|
||||
fn artist_lookup() -> EntityMatches {
|
||||
let artist = artist_meta();
|
||||
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_manual_input_mbid();
|
||||
info
|
||||
@ -366,24 +368,24 @@ mod tests {
|
||||
)
|
||||
}
|
||||
|
||||
fn album_matches() -> MatchStateInfo {
|
||||
fn album_matches() -> EntityMatches {
|
||||
let artist_id = album_artist_id();
|
||||
let album = album_meta();
|
||||
let album_match = Entity::with_score(album.clone(), 80);
|
||||
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_manual_input_mbid();
|
||||
info
|
||||
}
|
||||
|
||||
fn album_lookup() -> MatchStateInfo {
|
||||
fn album_lookup() -> EntityMatches {
|
||||
let artist_id = album_artist_id();
|
||||
let album = album_meta();
|
||||
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_manual_input_mbid();
|
||||
info
|
||||
@ -403,13 +405,13 @@ mod tests {
|
||||
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 app = AppPublic {
|
||||
inner: public_inner(collection, &mut selection),
|
||||
state: AppState::Match(MatchStatePublic {
|
||||
info,
|
||||
matches,
|
||||
state: &mut widget_state,
|
||||
}),
|
||||
input: None,
|
||||
|
Loading…
Reference in New Issue
Block a user