Terminal interface to find, download, and stream movies, TV shows, and live TV using local media players.
fix(tui): harden paging theme and cache state
Samir Hossains69cea60fc80d
diff --git a/src/tui/action.rs b/src/tui/action.rsindex ebc9638..e26cc67 100644--- a/src/tui/action.rs+++ b/src/tui/action.rs@@ -29,9 +29,10 @@ pub enum Action {SearchSuccess {context: crate::providers::models::RequestContext,query: String,+ page: usize,payload: serde_json::Value,},- SearchFailure(crate::providers::models::RequestContext, String),+ SearchFailure(crate::providers::models::RequestContext, usize, String),FetchHomepage {tab_id: String,page: usize,@@ -111,6 +112,7 @@ pub enum Action {SetStatus(String),Refresh,ClearCache,+ CacheCleared(Result<(), String>),LaunchPlayback(crate::tui::state::PlayerKind,crate::providers::models::PlaybackSource,diff --git a/src/tui/app/navigation.rs b/src/tui/app/navigation.rsindex c4f6cdb..f93d2b5 100644--- a/src/tui/app/navigation.rs+++ b/src/tui/app/navigation.rs@@ -455,7 +455,6 @@ impl App {}).ok();} else {- self.state.current_page = next_page;let query = self.state.search_query.clone();let client = self.client.clone();let fourk_client = self.fourk_client.clone();@@ -483,12 +482,15 @@ impl App {.send(Action::SearchSuccess {context,query,+ page: next_page,payload: res,}).ok();}Err(e) => {- sender.send(Action::SearchFailure(context, e)).ok();+ sender+ .send(Action::SearchFailure(context, next_page, e))+ .ok();}}});diff --git a/src/tui/app/requests.rs b/src/tui/app/requests.rsindex 7799167..2c1b90f 100644--- a/src/tui/app/requests.rs+++ b/src/tui/app/requests.rs@@ -304,14 +304,16 @@ impl App {Action::SearchSuccess {context,query,+ page,payload,} => {if !self.context_is_current(context) || query != self.state.search_query.trim() {return None;}+ self.state.current_page = page;self.state.search_error = None;self.state.is_loading = false;- if self.state.current_page <= 1 {+ if page <= 1 {self.state.search_results.clear();}let subjects_opt = payload@@ -469,7 +471,7 @@ impl App {},150,);- if self.state.current_page <= 1 {+ if page <= 1 {if let Some(res) = self.state.search_results.first() {self.state.search_list_state.select(Some(0));self.action_sender@@ -481,10 +483,13 @@ impl App {}}- Action::SearchFailure(context, err) => {+ Action::SearchFailure(context, page, err) => {if !self.context_is_current(context) {return None;}+ if page > 1 && self.state.current_page >= page {+ self.state.current_page = page - 1;+ }log::error!("search failed (provider {}): {err}",context.provider.cache_key()diff --git a/src/tui/app/run.rs b/src/tui/app/run.rsindex c449702..0c98925 100644--- a/src/tui/app/run.rs+++ b/src/tui/app/run.rs@@ -118,6 +118,7 @@ impl App {| Action::ToggleHelp| Action::Refresh| Action::ClearCache+ | Action::CacheCleared(..)| Action::ToggleThemePopup| Action::SelectTheme(..)| Action::SetStatus(..)diff --git a/src/tui/app/search.rs b/src/tui/app/search.rsindex 05d59bb..da3d708 100644--- a/src/tui/app/search.rs+++ b/src/tui/app/search.rs@@ -208,6 +208,7 @@ impl App {force_refresh: bool,context: RequestContext,) {+ let page = 1;let sender = self.action_sender.clone();let client = self.client.clone();let fourk_client = self.fourk_client.clone();@@ -226,6 +227,7 @@ impl App {.send(Action::SearchSuccess {context,query: query.clone(),+ page,payload: cached,}).ok();@@ -240,7 +242,7 @@ impl App {&dhakaflix_client,context.provider,&query,- 1,+ page,).await;match result {@@ -255,12 +257,15 @@ impl App {.send(Action::SearchSuccess {context,query,+ page,payload: res,}).ok();}Err(error) => {- sender.send(Action::SearchFailure(context, error)).ok();+ sender+ .send(Action::SearchFailure(context, page, error))+ .ok();}}});diff --git a/src/tui/app/system.rs b/src/tui/app/system.rsindex 9305c4e..41a5f6a 100644--- a/src/tui/app/system.rs+++ b/src/tui/app/system.rs@@ -185,7 +185,17 @@ impl App {},Action::ClearCache => {- tokio::task::spawn_blocking(crate::cache::clear_all_cache);+ let sender = self.action_sender.clone();+ tokio::spawn(async move {+ let result = tokio::task::spawn_blocking(|| {+ crate::cache::clear_all_cache();+ Ok::<(), String>(())+ })+ .await+ .map_err(|error| format!("cache clear task failed: {error}"))+ .and_then(|result| result);+ sender.send(Action::CacheCleared(result)).ok();+ });self.state.stream_pool.clear();self.state.image_cache.clear();self.state.search_posters.clear();@@ -198,10 +208,21 @@ impl App {self.state.available_seasons.clear();self.state.available_episode_numbers.clear();self.prepare_image_refresh();- self.state- .set_status("Cache cleared completely.".to_string(), 150);+ self.state.set_status("Clearing cache...".to_string(), 150);}+ Action::CacheCleared(result) => match result {+ Ok(()) => {+ self.state+ .set_status("Cache cleared completely.".to_string(), 150);+ }+ Err(error) => {+ log::error!("cache clear failed: {error}");+ self.state+ .notify(NotificationKind::Error, "Cache clear failed", error);+ }+ },+Action::ToggleThemePopup => {self.state.show_theme_popup = !self.state.show_theme_popup;if self.state.show_theme_popup {@@ -220,6 +241,7 @@ impl App {let kind = crate::tui::theme::ThemeKind::parse(&theme_name);self.state.active_theme_kind = kind.as_str().to_string();self.theme = crate::tui::theme::Theme::from_kind(kind);+ self.persist_config();self.state.dirty = true;}