Skip to content

Commit

Permalink
fix: Cancel all requests when switching Servarr tabs to both improve …
Browse files Browse the repository at this point in the history
…performance and fix issue #15
  • Loading branch information
Dark-Alex-17 committed Dec 17, 2024
1 parent 3ecaf04 commit 368d5d3
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/app/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ pub mod sonarr;
pub struct App<'a> {
navigation_stack: Vec<Route>,
network_tx: Option<Sender<NetworkEvent>>,
cancellation_token: CancellationToken,
pub cancellation_token: CancellationToken,
pub is_first_render: bool,
pub server_tabs: TabState,
pub error: HorizontallyScrollableText,
Expand Down
4 changes: 4 additions & 0 deletions src/handlers/handlers_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ mod tests {
use crate::models::sonarr_models::Series;
use pretty_assertions::assert_eq;
use rstest::rstest;
use tokio_util::sync::CancellationToken;

use crate::app::key_binding::DEFAULT_KEYBINDINGS;
use crate::app::App;
Expand Down Expand Up @@ -65,17 +66,20 @@ mod tests {
assert_eq!(app.get_current_route(), left_block.into());
assert!(app.is_first_render);
assert_eq!(app.error, HorizontallyScrollableText::default());
assert!(app.cancellation_token.is_cancelled());

app.server_tabs.set_index(index);
app.is_first_render = false;
app.error = "Test".into();
app.cancellation_token = CancellationToken::new();

handle_events(DEFAULT_KEYBINDINGS.next_servarr.key, &mut app);

assert_eq!(app.server_tabs.get_active_route(), right_block.into());
assert_eq!(app.get_current_route(), right_block.into());
assert!(app.is_first_render);
assert_eq!(app.error, HorizontallyScrollableText::default());
assert!(app.cancellation_token.is_cancelled());
}

#[rstest]
Expand Down
2 changes: 2 additions & 0 deletions src/handlers/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,10 +88,12 @@ pub fn handle_events(key: Key, app: &mut App<'_>) {
app.reset();
app.server_tabs.next();
app.pop_and_push_navigation_stack(app.server_tabs.get_active_route());
app.cancellation_token.cancel();
} else if key == DEFAULT_KEYBINDINGS.previous_servarr.key {
app.reset();
app.server_tabs.previous();
app.pop_and_push_navigation_stack(app.server_tabs.get_active_route());
app.cancellation_token.cancel();
} else {
match app.get_current_route() {
Route::Radarr(active_radarr_block, context) => {
Expand Down

0 comments on commit 368d5d3

Please sign in to comment.