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:
2025-12-04 16:03:58 -07:00
parent 71240373c0
commit 35dce0bf01
42 changed files with 1425 additions and 756 deletions
@@ -1,4 +1,4 @@
use crate::handlers::table_handler::TableHandlingConfig;
use crate::handlers::table_handler::{TableHandlingConfig, handle_table};
use crate::handlers::{KeyEventHandler, handle_prompt_toggle};
use crate::models::radarr_models::{
AddMovieBody, AddMovieOptions, AddMovieSearchResult, CollectionMovie,
@@ -9,9 +9,7 @@ use crate::models::servarr_data::radarr::radarr_data::{
};
use crate::models::{BlockSelectionState, Scrollable};
use crate::network::radarr_network::RadarrEvent;
use crate::{
App, Key, handle_table_events, handle_text_box_keys, handle_text_box_left_right_keys, matches_key,
};
use crate::{App, Key, handle_text_box_keys, handle_text_box_left_right_keys, matches_key};
#[cfg(test)]
#[path = "add_movie_handler_tests.rs"]
@@ -25,19 +23,6 @@ pub(super) struct AddMovieHandler<'a, 'b> {
}
impl AddMovieHandler<'_, '_> {
handle_table_events!(
self,
add_movie_search_results,
self
.app
.data
.radarr_data
.add_searched_movies
.as_mut()
.expect("add_searched_movies should be initialized"),
AddMovieSearchResult
);
fn build_add_movie_body(&mut self) -> AddMovieBody {
let add_movie_modal = self
.app
@@ -123,7 +108,18 @@ impl<'a, 'b> KeyEventHandler<'a, 'b, ActiveRadarrBlock> for AddMovieHandler<'a,
let add_movie_table_handling_config =
TableHandlingConfig::new(ActiveRadarrBlock::AddMovieSearchResults.into());
if !self.handle_add_movie_search_results_table_events(add_movie_table_handling_config) {
if !handle_table(
self,
|app| {
app
.data
.radarr_data
.add_searched_movies
.as_mut()
.expect("add_searched_movies should be initialized")
},
add_movie_table_handling_config,
) {
self.handle_key_event();
}
}
@@ -557,4 +553,12 @@ impl<'a, 'b> KeyEventHandler<'a, 'b, ActiveRadarrBlock> for AddMovieHandler<'a,
_ => (),
}
}
fn app_mut(&mut self) -> &mut App<'b> {
self.app
}
fn current_route(&self) -> crate::models::Route {
self.app.get_current_route()
}
}