refactor(downloads_handler): Use the new handle_table_events macro

This commit is contained in:
2024-12-08 12:35:12 -07:00
parent c58e8b1a00
commit 35bc6cf31c
+16 -12
View File
@@ -1,10 +1,14 @@
use crate::models::HorizontallyScrollableText;
use crate::app::key_binding::DEFAULT_KEYBINDINGS;
use crate::app::App;
use crate::event::Key;
use crate::handle_table_events;
use crate::handlers::sonarr_handlers::handle_change_tab_left_right_keys;
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::Scrollable;
use crate::models::sonarr_models::DownloadRecord;
use crate::network::sonarr_network::SonarrEvent;
#[cfg(test)]
@@ -18,7 +22,19 @@ pub(super) struct DownloadsHandler<'a, 'b> {
_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> {
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 {
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) {
if self.active_sonarr_block == ActiveSonarrBlock::Downloads {
self.app.data.sonarr_data.downloads.scroll_up()
}
}
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) {
if self.active_sonarr_block == ActiveSonarrBlock::Downloads {
self.app.data.sonarr_data.downloads.scroll_to_top()
}
}
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) {