feat(discovery): show status activity while loading results
This commit is contained in:
1 parent
88dfef51ad
commit
9932de1c73
8 files changed
+108
-5
No files matched your search
+3
-1
@@ -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);
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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)]
|
||||
|
||||
@@ -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()
|
||||
|
||||
@@ -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 {
|
||||
|
||||
Reference in new issue
Block a user