From ec61b2d50ae06183edc1ca1eb27ea9569b28632d Mon Sep 17 00:00:00 2001 From: Wojciech Kozlowski Date: Sun, 6 Oct 2024 16:49:31 +0200 Subject: [PATCH] Minor --- src/tui/app/machine/fetch_state.rs | 30 ++++++++++++++++++++++-------- 1 file changed, 22 insertions(+), 8 deletions(-) diff --git a/src/tui/app/machine/fetch_state.rs b/src/tui/app/machine/fetch_state.rs index dd8cbb2..563ace4 100644 --- a/src/tui/app/machine/fetch_state.rs +++ b/src/tui/app/machine/fetch_state.rs @@ -49,6 +49,14 @@ impl FetchState { } } + pub fn fetch(fetch_rx: MbApiReceiver) -> Self { + FetchState { + search_rx: None, + lookup_rx: None, + fetch_rx: Some(fetch_rx), + } + } + fn try_recv(&mut self) -> Result { try_recv_mb_api_receiver!(self.lookup_rx); try_recv_mb_api_receiver!(self.search_rx); @@ -79,10 +87,10 @@ impl AppMachine { return AppMachine::browse_state(inner).into(); } - let (fetch_tx, fetch_rx) = mpsc::channel::(); - let fetch = FetchState::search(fetch_rx); + let (search_tx, search_rx) = mpsc::channel::(); + let fetch = FetchState::search(search_rx); - match inner.musicbrainz.submit_background_job(fetch_tx, requests) { + match inner.musicbrainz.submit_background_job(search_tx, requests) { Ok(()) => AppMachine::fetch_state(inner, fetch).into(), Err(err) => AppMachine::error_state(inner, err.to_string()).into(), } @@ -98,7 +106,13 @@ impl AppMachine { }, Err(recv_err) => match recv_err { TryRecvError::Empty => AppMachine::fetch_state(inner, fetch).into(), - TryRecvError::Disconnected => Self::app_fetch_new(inner), + TryRecvError::Disconnected => { + if fetch.fetch_rx.is_some() { + AppMachine::browse_state(inner).into() + } else { + Self::app_fetch_new(inner) + } + } }, } } @@ -198,6 +212,10 @@ impl AppMachine { Self::search_albums_requests(artist_id, artist_mbid, slice::from_ref(album)) } + fn search_artist_request(meta: &ArtistMeta) -> VecDeque { + VecDeque::from([MbParams::search_artist(meta.clone())]) + } + fn search_albums_requests( artist: &ArtistId, arid: &MbArtistRef, @@ -213,10 +231,6 @@ impl AppMachine { .collect() } - fn search_artist_request(meta: &ArtistMeta) -> VecDeque { - VecDeque::from([MbParams::search_artist(meta.clone())]) - } - fn submit_lookup_artist_job( musicbrainz: &dyn IMbJobSender, result_sender: ResultSender,