diff --git a/crates/tui/src/http.rs b/crates/tui/src/http.rs index b88a314c..85780f15 100644 --- a/crates/tui/src/http.rs +++ b/crates/tui/src/http.rs @@ -311,6 +311,14 @@ impl RequestStore { Ok(()) } + /// Is the given request either building or loading? + pub fn is_in_progress(&self, id: RequestId) -> bool { + matches!( + self.get(id), + Some(RequestState::Building { .. } | RequestState::Loading { .. },) + ) + } + /// Replace a request state in the store with new state, by mapping it /// through a function. This assumes the request state is supposed to be in /// the state, so it logs a message if it isn't (panics in debug mode). This diff --git a/crates/tui/src/view/component/root.rs b/crates/tui/src/view/component/root.rs index 0e1a893a..5ceaa14e 100644 --- a/crates/tui/src/view/component/root.rs +++ b/crates/tui/src/view/component/root.rs @@ -151,16 +151,19 @@ impl EventHandler for Root { } Action::Cancel => { if let Some(request_id) = self.selected_request_id.0 { - ViewContext::open_modal(ConfirmModal::new( - "Cancel request?".into(), - move |response| { - if response { - ViewContext::send_message( - Message::HttpCancel(request_id), - ); - } - }, - )) + // 2024 edition: if-let chain + if context.request_store.is_in_progress(request_id) { + ViewContext::open_modal(ConfirmModal::new( + "Cancel request?".into(), + move |response| { + if response { + ViewContext::send_message( + Message::HttpCancel(request_id), + ); + } + }, + )) + } } } Action::Quit => ViewContext::send_message(Message::Quit),