From 9932de1c73f920a00bb3a0a6faabd680ef2afbb8 Mon Sep 17 00:00:00 2001 From: objz Date: Fri, 25 Sep 2026 10:10:48 +0200 Subject: [PATCH] feat(discovery): show status activity while loading results --- src/tui/event.rs | 4 ++- src/tui/input.rs | 13 +++++++ src/tui/render.rs | 2 ++ src/tui/tests/widgets/content/discovery.rs | 35 +++++++++++++++++++ src/tui/widgets/content/discovery.rs | 34 ++++++++++++++++++ src/tui/widgets/popups/import_modpack/mod.rs | 4 +-- .../widgets/popups/import_modpack/state.rs | 12 +++++++ src/tui/widgets/status.rs | 9 +++-- 8 files changed, 108 insertions(+), 5 deletions(-) diff --git a/src/tui/event.rs b/src/tui/event.rs index 5f50973..05cf570 100644 --- a/src/tui/event.rs +++ b/src/tui/event.rs @@ -165,7 +165,9 @@ impl App { self.ensure_provider_conflict_popup(); self.ensure_active_discovery_loaded(); let progress_active = progress::is_active(); - let spinner_active = progress_active || crate::instance::runtime::has_active(); + let spinner_active = progress_active + || crate::instance::runtime::has_active() + || self.discovery_activity().is_some(); if spinner_active { // only advance the spinner every 8 ticks to keep it readable self.throbber_tick = self.throbber_tick.wrapping_add(1); diff --git a/src/tui/input.rs b/src/tui/input.rs index aee6207..d02fbea 100644 --- a/src/tui/input.rs +++ b/src/tui/input.rs @@ -1424,6 +1424,19 @@ impl App { } } + pub(super) fn discovery_activity(&self) -> Option<&'static str> { + if self.instances_state.show_import_popup { + return widgets::popups::import_modpack::discovery_activity(); + } + if self.content_mode != widgets::content::ContentMode::Discover + || self.instances_state.selected_instance().is_none() + { + return None; + } + self.active_discovery_state() + .and_then(widgets::content::discovery::DiscoveryState::activity_label) + } + fn spawn_bulk_content_updates(&mut self) { if self.content_update_popup.is_some() { return; diff --git a/src/tui/render.rs b/src/tui/render.rs index 6218de9..cf8aee7 100644 --- a/src/tui/render.rs +++ b/src/tui/render.rs @@ -138,11 +138,13 @@ impl App { &mut self.settings_state, self.instances_state.selected_instance(), ); + let discovery_activity = self.discovery_activity(); widgets::status::render( frame, bottom_chunks[2], self.focused, &mut self.throbber_state, + discovery_activity, ); if self.focused == FocusedArea::OverviewExpanded { diff --git a/src/tui/tests/widgets/content/discovery.rs b/src/tui/tests/widgets/content/discovery.rs index d247230..c02f0af 100644 --- a/src/tui/tests/widgets/content/discovery.rs +++ b/src/tui/tests/widgets/content/discovery.rs @@ -1752,6 +1752,41 @@ fn filtered_refresh_applies_a_provider_page_in_one_frame() { ); } +#[test] +fn discovery_activity_tracks_search_pages_and_icon_loading() { + let mut state = DiscoveryState::new(ContentKind::Mod); + let instance = instance("one", "1.21.1"); + assert_eq!(state.activity_label(), None); + let first = state.begin_search(&instance); + assert_eq!(state.activity_label(), Some("Searching Discovery...")); + let mut entry = project_entry(project("icon"), None); + entry.provider_icon = true; + first.stream.upsert(entry); + state.list.drain_pending(); + DiscoveryState::push_result( + &first.pending, + first.generation, + 0, + Ok(DiscoveryPageResult { + received: 1, + total_hits: 100, + }), + ); + state.drain_pending(); + assert_eq!(state.activity_label(), Some("Loading Discovery icons...")); + first + .stream + .send_icon_unavailable("icon".to_owned(), "icon".into(), None); + state.list.drain_pending(); + assert_eq!(state.activity_label(), None); + let _next = state.begin_next_page().unwrap(); + assert_eq!(state.activity_label(), Some("Loading more results...")); + state.page_loading = false; + state.filter_version_picker_open = true; + *state.filter_game_versions.lock().unwrap() = crate::tui::widgets::popups::LoadState::Loading; + assert_eq!(state.activity_label(), Some("Loading game versions...")); +} + #[test] fn rapidly_cycling_a_category_discards_superseded_rows_and_results() { let mut state = DiscoveryState::new(ContentKind::Mod); diff --git a/src/tui/widgets/content/discovery.rs b/src/tui/widgets/content/discovery.rs index 697b00a..b1c3dc3 100644 --- a/src/tui/widgets/content/discovery.rs +++ b/src/tui/widgets/content/discovery.rs @@ -2041,6 +2041,40 @@ impl DiscoveryState { .is_some_and(|changed| changed.elapsed() >= SEARCH_DEBOUNCE) } + pub(crate) fn activity_label(&self) -> Option<&'static str> { + if self.local_mode { + return None; + } + if self.search_changed_at.is_some() || self.page_loading { + return Some(if self.next_offset == 0 { + "Searching Discovery..." + } else { + "Loading more results..." + }); + } + if self.retry_page_at.is_some() { + return Some("Retrying Discovery..."); + } + if self + .version_popup + .as_ref() + .is_some_and(|popup| popup.loading) + { + return Some("Loading versions..."); + } + if self.filter_version_picker_open + && self.filter_game_versions.lock().is_ok_and(|versions| { + matches!(*versions, crate::tui::widgets::popups::LoadState::Loading) + }) + { + return Some("Loading game versions..."); + } + if self.list.has_pending_icons() { + return Some("Loading Discovery icons..."); + } + None + } + fn apply_selected_sort(&mut self) { if self.local_mode { let selected = self.sort_panel_selected + 5; diff --git a/src/tui/widgets/popups/import_modpack/mod.rs b/src/tui/widgets/popups/import_modpack/mod.rs index 5cca01e..4bedbe9 100644 --- a/src/tui/widgets/popups/import_modpack/mod.rs +++ b/src/tui/widgets/popups/import_modpack/mod.rs @@ -8,8 +8,8 @@ mod state; pub use render::render; pub use render::{popup_rect, render_with_picker}; pub use state::{ - ImportResult, ImportStep, ImportWizardState, drain, handle_discovery_click, handle_key, - has_version_popup, open, take_result, + ImportResult, ImportStep, ImportWizardState, discovery_activity, drain, handle_discovery_click, + handle_key, has_version_popup, open, take_result, }; #[cfg(test)] diff --git a/src/tui/widgets/popups/import_modpack/state.rs b/src/tui/widgets/popups/import_modpack/state.rs index 69dc7e4..eb9e979 100644 --- a/src/tui/widgets/popups/import_modpack/state.rs +++ b/src/tui/widgets/popups/import_modpack/state.rs @@ -126,6 +126,18 @@ pub fn has_version_popup() -> bool { .is_ok_and(|state| state.version_popup.is_some()) } +pub fn discovery_activity() -> Option<&'static str> { + let wizard = IMPORT_STATE.lock().ok()?; + let step = wizard.step.clone(); + let loading_versions = matches!(wizard.versions, LoadState::Loading); + drop(wizard); + match step { + ImportStep::Discover => DISCOVERY_STATE.lock().ok()?.activity_label(), + ImportStep::Version if loading_versions => Some("Loading modpack versions..."), + _ => None, + } +} + pub fn handle_discovery_click(x: u16, y: u16) -> bool { if !IMPORT_STATE .lock() diff --git a/src/tui/widgets/status.rs b/src/tui/widgets/status.rs index 841d874..2065a54 100644 --- a/src/tui/widgets/status.rs +++ b/src/tui/widgets/status.rs @@ -24,6 +24,7 @@ pub fn render( area: Rect, focused: FocusedArea, throbber_state: &mut ThrobberState, + discovery_activity: Option<&str>, ) { let theme = THEME.as_ref(); let border_color = if focused == FocusedArea::Overview { @@ -50,7 +51,7 @@ pub fn render( } }; - if state.current_action.is_none() { + if state.current_action.is_none() && discovery_activity.is_none() { frame.render_widget( Paragraph::new(Span::styled("Ready", Style::default().fg(theme.text_dim()))) .block(block), @@ -62,7 +63,11 @@ pub fn render( let inner = block.inner(area); frame.render_widget(block, area); - let action_text = state.current_action.as_deref().unwrap_or(""); + let action_text = state + .current_action + .as_deref() + .or(discovery_activity) + .unwrap_or(""); let sub_text = state.sub_action.as_deref().unwrap_or(""); match state.progress {