Skip to content

Commit

Permalink
Only allow request cancellation when the selected request is pending
Browse files Browse the repository at this point in the history
  • Loading branch information
LucasPickering committed Dec 7, 2024
1 parent 8cd971c commit 9b0721d
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 10 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
- Improve UX of query text box
- The query is now auto-applied when changed (with a 500ms debounce), and drops focus on the text box when Enter is pressed

### Fixed

- Don't show request cancellation dialog if the selected request isn't building/loading

## [2.3.0] - 2024-11-11

### Added
Expand Down
8 changes: 8 additions & 0 deletions crates/tui/src/http.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
23 changes: 13 additions & 10 deletions crates/tui/src/view/component/root.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down

0 comments on commit 9b0721d

Please sign in to comment.