refactor(downloads_handler): Use the new handle_table_events macro
This commit is contained in:
@@ -1,10 +1,14 @@
|
|||||||
|
use crate::models::HorizontallyScrollableText;
|
||||||
use crate::app::key_binding::DEFAULT_KEYBINDINGS;
|
use crate::app::key_binding::DEFAULT_KEYBINDINGS;
|
||||||
use crate::app::App;
|
use crate::app::App;
|
||||||
use crate::event::Key;
|
use crate::event::Key;
|
||||||
|
use crate::handle_table_events;
|
||||||
use crate::handlers::sonarr_handlers::handle_change_tab_left_right_keys;
|
use crate::handlers::sonarr_handlers::handle_change_tab_left_right_keys;
|
||||||
use crate::handlers::{handle_clear_errors, handle_prompt_toggle, KeyEventHandler};
|
use crate::handlers::{handle_clear_errors, handle_prompt_toggle, KeyEventHandler};
|
||||||
|
use crate::handlers::table_handler::TableHandlingProps;
|
||||||
use crate::models::servarr_data::sonarr::sonarr_data::{ActiveSonarrBlock, DOWNLOADS_BLOCKS};
|
use crate::models::servarr_data::sonarr::sonarr_data::{ActiveSonarrBlock, DOWNLOADS_BLOCKS};
|
||||||
use crate::models::Scrollable;
|
use crate::models::Scrollable;
|
||||||
|
use crate::models::sonarr_models::DownloadRecord;
|
||||||
use crate::network::sonarr_network::SonarrEvent;
|
use crate::network::sonarr_network::SonarrEvent;
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
@@ -18,7 +22,19 @@ pub(super) struct DownloadsHandler<'a, 'b> {
|
|||||||
_context: Option<ActiveSonarrBlock>,
|
_context: Option<ActiveSonarrBlock>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl<'a, 'b> DownloadsHandler<'a, 'b> {
|
||||||
|
handle_table_events!(self, downloads, self.app.data.sonarr_data.downloads, DownloadRecord);
|
||||||
|
}
|
||||||
|
|
||||||
impl<'a, 'b> KeyEventHandler<'a, 'b, ActiveSonarrBlock> for DownloadsHandler<'a, 'b> {
|
impl<'a, 'b> KeyEventHandler<'a, 'b, ActiveSonarrBlock> for DownloadsHandler<'a, 'b> {
|
||||||
|
fn handle(&mut self) {
|
||||||
|
let download_table_handling_props = TableHandlingProps::new(ActiveSonarrBlock::Downloads.into());
|
||||||
|
|
||||||
|
if !self.handle_downloads_table_events(download_table_handling_props) {
|
||||||
|
self.handle_key_event();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fn accepts(active_block: ActiveSonarrBlock) -> bool {
|
fn accepts(active_block: ActiveSonarrBlock) -> bool {
|
||||||
DOWNLOADS_BLOCKS.contains(&active_block)
|
DOWNLOADS_BLOCKS.contains(&active_block)
|
||||||
}
|
}
|
||||||
@@ -46,27 +62,15 @@ impl<'a, 'b> KeyEventHandler<'a, 'b, ActiveSonarrBlock> for DownloadsHandler<'a,
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn handle_scroll_up(&mut self) {
|
fn handle_scroll_up(&mut self) {
|
||||||
if self.active_sonarr_block == ActiveSonarrBlock::Downloads {
|
|
||||||
self.app.data.sonarr_data.downloads.scroll_up()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn handle_scroll_down(&mut self) {
|
fn handle_scroll_down(&mut self) {
|
||||||
if self.active_sonarr_block == ActiveSonarrBlock::Downloads {
|
|
||||||
self.app.data.sonarr_data.downloads.scroll_down()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn handle_home(&mut self) {
|
fn handle_home(&mut self) {
|
||||||
if self.active_sonarr_block == ActiveSonarrBlock::Downloads {
|
|
||||||
self.app.data.sonarr_data.downloads.scroll_to_top()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn handle_end(&mut self) {
|
fn handle_end(&mut self) {
|
||||||
if self.active_sonarr_block == ActiveSonarrBlock::Downloads {
|
|
||||||
self.app.data.sonarr_data.downloads.scroll_to_bottom()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn handle_delete(&mut self) {
|
fn handle_delete(&mut self) {
|
||||||
|
|||||||
Reference in New Issue
Block a user