refactor: Migrated the handle_table_events macro into a trait for better IDE support, created a TableEventAdapter wrapper for the KeyEventHandlers to make it so that the trait can be used properly and a simple function to replace the previous call to the handle_table_events macro
This commit is contained in:
@@ -1,12 +1,11 @@
|
||||
use crate::app::App;
|
||||
use crate::event::Key;
|
||||
use crate::handlers::radarr_handlers::handle_change_tab_left_right_keys;
|
||||
use crate::handlers::table_handler::TableHandlingConfig;
|
||||
use crate::handlers::table_handler::{TableHandlingConfig, handle_table};
|
||||
use crate::handlers::{KeyEventHandler, handle_clear_errors, handle_prompt_toggle};
|
||||
use crate::models::radarr_models::DownloadRecord;
|
||||
use crate::matches_key;
|
||||
use crate::models::servarr_data::radarr::radarr_data::{ActiveRadarrBlock, DOWNLOADS_BLOCKS};
|
||||
use crate::network::radarr_network::RadarrEvent;
|
||||
use crate::{handle_table_events, matches_key};
|
||||
|
||||
#[cfg(test)]
|
||||
#[path = "downloads_handler_tests.rs"]
|
||||
@@ -20,13 +19,6 @@ pub(super) struct DownloadsHandler<'a, 'b> {
|
||||
}
|
||||
|
||||
impl DownloadsHandler<'_, '_> {
|
||||
handle_table_events!(
|
||||
self,
|
||||
downloads,
|
||||
self.app.data.radarr_data.downloads,
|
||||
DownloadRecord
|
||||
);
|
||||
|
||||
fn extract_download_id(&self) -> i64 {
|
||||
self.app.data.radarr_data.downloads.current_selection().id
|
||||
}
|
||||
@@ -37,7 +29,11 @@ impl<'a, 'b> KeyEventHandler<'a, 'b, ActiveRadarrBlock> for DownloadsHandler<'a,
|
||||
let downloads_table_handling_config =
|
||||
TableHandlingConfig::new(ActiveRadarrBlock::Downloads.into());
|
||||
|
||||
if !self.handle_downloads_table_events(downloads_table_handling_config) {
|
||||
if !handle_table(
|
||||
self,
|
||||
|app| &mut app.data.radarr_data.downloads,
|
||||
downloads_table_handling_config,
|
||||
) {
|
||||
self.handle_key_event();
|
||||
}
|
||||
}
|
||||
@@ -163,4 +159,12 @@ impl<'a, 'b> KeyEventHandler<'a, 'b, ActiveRadarrBlock> for DownloadsHandler<'a,
|
||||
_ => (),
|
||||
}
|
||||
}
|
||||
|
||||
fn app_mut(&mut self) -> &mut App<'b> {
|
||||
self.app
|
||||
}
|
||||
|
||||
fn current_route(&self) -> crate::models::Route {
|
||||
self.app.get_current_route()
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user