fix: Cancel all requests when switching Servarr tabs to both improve performance and fix issue #15
This commit is contained in:
+1
-1
@@ -26,7 +26,7 @@ pub mod sonarr;
|
|||||||
pub struct App<'a> {
|
pub struct App<'a> {
|
||||||
navigation_stack: Vec<Route>,
|
navigation_stack: Vec<Route>,
|
||||||
network_tx: Option<Sender<NetworkEvent>>,
|
network_tx: Option<Sender<NetworkEvent>>,
|
||||||
cancellation_token: CancellationToken,
|
pub cancellation_token: CancellationToken,
|
||||||
pub is_first_render: bool,
|
pub is_first_render: bool,
|
||||||
pub server_tabs: TabState,
|
pub server_tabs: TabState,
|
||||||
pub error: HorizontallyScrollableText,
|
pub error: HorizontallyScrollableText,
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ mod tests {
|
|||||||
use crate::models::sonarr_models::Series;
|
use crate::models::sonarr_models::Series;
|
||||||
use pretty_assertions::assert_eq;
|
use pretty_assertions::assert_eq;
|
||||||
use rstest::rstest;
|
use rstest::rstest;
|
||||||
|
use tokio_util::sync::CancellationToken;
|
||||||
|
|
||||||
use crate::app::key_binding::DEFAULT_KEYBINDINGS;
|
use crate::app::key_binding::DEFAULT_KEYBINDINGS;
|
||||||
use crate::app::App;
|
use crate::app::App;
|
||||||
@@ -65,10 +66,12 @@ mod tests {
|
|||||||
assert_eq!(app.get_current_route(), left_block.into());
|
assert_eq!(app.get_current_route(), left_block.into());
|
||||||
assert!(app.is_first_render);
|
assert!(app.is_first_render);
|
||||||
assert_eq!(app.error, HorizontallyScrollableText::default());
|
assert_eq!(app.error, HorizontallyScrollableText::default());
|
||||||
|
assert!(app.cancellation_token.is_cancelled());
|
||||||
|
|
||||||
app.server_tabs.set_index(index);
|
app.server_tabs.set_index(index);
|
||||||
app.is_first_render = false;
|
app.is_first_render = false;
|
||||||
app.error = "Test".into();
|
app.error = "Test".into();
|
||||||
|
app.cancellation_token = CancellationToken::new();
|
||||||
|
|
||||||
handle_events(DEFAULT_KEYBINDINGS.next_servarr.key, &mut app);
|
handle_events(DEFAULT_KEYBINDINGS.next_servarr.key, &mut app);
|
||||||
|
|
||||||
@@ -76,6 +79,7 @@ mod tests {
|
|||||||
assert_eq!(app.get_current_route(), right_block.into());
|
assert_eq!(app.get_current_route(), right_block.into());
|
||||||
assert!(app.is_first_render);
|
assert!(app.is_first_render);
|
||||||
assert_eq!(app.error, HorizontallyScrollableText::default());
|
assert_eq!(app.error, HorizontallyScrollableText::default());
|
||||||
|
assert!(app.cancellation_token.is_cancelled());
|
||||||
}
|
}
|
||||||
|
|
||||||
#[rstest]
|
#[rstest]
|
||||||
|
|||||||
@@ -88,10 +88,12 @@ pub fn handle_events(key: Key, app: &mut App<'_>) {
|
|||||||
app.reset();
|
app.reset();
|
||||||
app.server_tabs.next();
|
app.server_tabs.next();
|
||||||
app.pop_and_push_navigation_stack(app.server_tabs.get_active_route());
|
app.pop_and_push_navigation_stack(app.server_tabs.get_active_route());
|
||||||
|
app.cancellation_token.cancel();
|
||||||
} else if key == DEFAULT_KEYBINDINGS.previous_servarr.key {
|
} else if key == DEFAULT_KEYBINDINGS.previous_servarr.key {
|
||||||
app.reset();
|
app.reset();
|
||||||
app.server_tabs.previous();
|
app.server_tabs.previous();
|
||||||
app.pop_and_push_navigation_stack(app.server_tabs.get_active_route());
|
app.pop_and_push_navigation_stack(app.server_tabs.get_active_route());
|
||||||
|
app.cancellation_token.cancel();
|
||||||
} else {
|
} else {
|
||||||
match app.get_current_route() {
|
match app.get_current_route() {
|
||||||
Route::Radarr(active_radarr_block, context) => {
|
Route::Radarr(active_radarr_block, context) => {
|
||||||
|
|||||||
Reference in New Issue
Block a user