refactor(collection_details_handler): use the new handle_table_events macro
This commit is contained in:
@@ -1,7 +1,10 @@
|
||||
use crate::app::key_binding::DEFAULT_KEYBINDINGS;
|
||||
use crate::app::App;
|
||||
use crate::event::Key;
|
||||
use crate::handle_table_events;
|
||||
use crate::handlers::table_handler::TableHandlingProps;
|
||||
use crate::handlers::KeyEventHandler;
|
||||
use crate::models::radarr_models::CollectionMovie;
|
||||
use crate::models::servarr_data::radarr::radarr_data::{
|
||||
ActiveRadarrBlock, ADD_MOVIE_SELECTION_BLOCKS, COLLECTION_DETAILS_BLOCKS,
|
||||
EDIT_COLLECTION_SELECTION_BLOCKS,
|
||||
@@ -20,7 +23,25 @@ pub(super) struct CollectionDetailsHandler<'a, 'b> {
|
||||
_context: Option<ActiveRadarrBlock>,
|
||||
}
|
||||
|
||||
impl<'a, 'b> CollectionDetailsHandler<'a, 'b> {
|
||||
handle_table_events!(
|
||||
self,
|
||||
collection_movies,
|
||||
self.app.data.radarr_data.collection_movies,
|
||||
CollectionMovie
|
||||
);
|
||||
}
|
||||
|
||||
impl<'a, 'b> KeyEventHandler<'a, 'b, ActiveRadarrBlock> for CollectionDetailsHandler<'a, 'b> {
|
||||
fn handle(&mut self) {
|
||||
let collection_movies_table_handling_props =
|
||||
TableHandlingProps::new(ActiveRadarrBlock::CollectionDetails.into());
|
||||
|
||||
if !self.handle_collection_movies_table_events(collection_movies_table_handling_props) {
|
||||
self.handle_key_event();
|
||||
}
|
||||
}
|
||||
|
||||
fn accepts(active_block: ActiveRadarrBlock) -> bool {
|
||||
COLLECTION_DETAILS_BLOCKS.contains(&active_block)
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
use crate::app::key_binding::DEFAULT_KEYBINDINGS;
|
||||
use crate::app::App;
|
||||
use crate::event::Key;
|
||||
use crate::handle_table_events;
|
||||
use crate::handlers::radarr_handlers::collections::collection_details_handler::CollectionDetailsHandler;
|
||||
use crate::handlers::radarr_handlers::collections::edit_collection_handler::EditCollectionHandler;
|
||||
use crate::handlers::radarr_handlers::handle_change_tab_left_right_keys;
|
||||
@@ -11,9 +12,8 @@ use crate::models::servarr_data::radarr::radarr_data::{
|
||||
ActiveRadarrBlock, COLLECTIONS_BLOCKS, EDIT_COLLECTION_SELECTION_BLOCKS,
|
||||
};
|
||||
use crate::models::stateful_table::SortOption;
|
||||
use crate::models::{BlockSelectionState, HorizontallyScrollableText, Scrollable};
|
||||
use crate::models::{BlockSelectionState, Scrollable};
|
||||
use crate::network::radarr_network::RadarrEvent;
|
||||
use crate::handle_table_events;
|
||||
|
||||
mod collection_details_handler;
|
||||
mod edit_collection_handler;
|
||||
@@ -30,27 +30,38 @@ pub(super) struct CollectionsHandler<'a, 'b> {
|
||||
}
|
||||
|
||||
impl<'a, 'b> CollectionsHandler<'a, 'b> {
|
||||
handle_table_events!(self, collections, self.app.data.radarr_data.collections, Collection);
|
||||
handle_table_events!(
|
||||
self,
|
||||
collections,
|
||||
self.app.data.radarr_data.collections,
|
||||
Collection
|
||||
);
|
||||
}
|
||||
|
||||
impl<'a, 'b> KeyEventHandler<'a, 'b, ActiveRadarrBlock> for CollectionsHandler<'a, 'b> {
|
||||
fn handle(&mut self) {
|
||||
let collections_table_handling_props = TableHandlingProps::new(ActiveRadarrBlock::Collections.into())
|
||||
.sorting_block(ActiveRadarrBlock::CollectionsSortPrompt.into())
|
||||
.sort_by_fn(|a: &Collection, b: &Collection| a.id.cmp(&b.id))
|
||||
.sort_options(collections_sorting_options())
|
||||
.searching_block(ActiveRadarrBlock::SearchCollection.into())
|
||||
.search_error_block(ActiveRadarrBlock::SearchCollectionError.into())
|
||||
.search_field_fn(|collection| &collection.title.text)
|
||||
.filtering_block(ActiveRadarrBlock::FilterCollections.into())
|
||||
.filter_error_block(ActiveRadarrBlock::FilterCollectionsError.into())
|
||||
.filter_field_fn(|collection| &collection.title.text);
|
||||
|
||||
let collections_table_handling_props =
|
||||
TableHandlingProps::new(ActiveRadarrBlock::Collections.into())
|
||||
.sorting_block(ActiveRadarrBlock::CollectionsSortPrompt.into())
|
||||
.sort_by_fn(|a: &Collection, b: &Collection| a.id.cmp(&b.id))
|
||||
.sort_options(collections_sorting_options())
|
||||
.searching_block(ActiveRadarrBlock::SearchCollection.into())
|
||||
.search_error_block(ActiveRadarrBlock::SearchCollectionError.into())
|
||||
.search_field_fn(|collection| &collection.title.text)
|
||||
.filtering_block(ActiveRadarrBlock::FilterCollections.into())
|
||||
.filter_error_block(ActiveRadarrBlock::FilterCollectionsError.into())
|
||||
.filter_field_fn(|collection| &collection.title.text);
|
||||
|
||||
if !self.handle_collections_table_events(collections_table_handling_props) {
|
||||
match self.active_radarr_block {
|
||||
_ if CollectionDetailsHandler::accepts(self.active_radarr_block) => {
|
||||
CollectionDetailsHandler::with(self.key, self.app, self.active_radarr_block, self.context)
|
||||
.handle();
|
||||
CollectionDetailsHandler::with(
|
||||
self.key,
|
||||
self.app,
|
||||
self.active_radarr_block,
|
||||
self.context,
|
||||
)
|
||||
.handle();
|
||||
}
|
||||
_ if EditCollectionHandler::accepts(self.active_radarr_block) => {
|
||||
EditCollectionHandler::with(self.key, self.app, self.active_radarr_block, self.context)
|
||||
@@ -89,17 +100,13 @@ impl<'a, 'b> KeyEventHandler<'a, 'b, ActiveRadarrBlock> for CollectionsHandler<'
|
||||
!self.app.is_loading && !self.app.data.radarr_data.collections.is_empty()
|
||||
}
|
||||
|
||||
fn handle_scroll_up(&mut self) {
|
||||
}
|
||||
fn handle_scroll_up(&mut self) {}
|
||||
|
||||
fn handle_scroll_down(&mut self) {
|
||||
}
|
||||
fn handle_scroll_down(&mut self) {}
|
||||
|
||||
fn handle_home(&mut self) {
|
||||
}
|
||||
fn handle_home(&mut self) {}
|
||||
|
||||
fn handle_end(&mut self) {
|
||||
}
|
||||
fn handle_end(&mut self) {}
|
||||
|
||||
fn handle_delete(&mut self) {}
|
||||
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
use crate::models::HorizontallyScrollableText;
|
||||
use serde_json::Number;
|
||||
|
||||
use crate::app::key_binding::DEFAULT_KEYBINDINGS;
|
||||
@@ -54,8 +53,32 @@ impl<'a, 'b> MovieDetailsHandler<'a, 'b> {
|
||||
.movie_history,
|
||||
MovieHistoryItem
|
||||
);
|
||||
handle_table_events!(self, movie_cast, self.app.data.radarr_data.movie_details_modal.as_mut().unwrap().movie_cast, Credit);
|
||||
handle_table_events!(self, movie_crew, self.app.data.radarr_data.movie_details_modal.as_mut().unwrap().movie_crew, Credit);
|
||||
handle_table_events!(
|
||||
self,
|
||||
movie_cast,
|
||||
self
|
||||
.app
|
||||
.data
|
||||
.radarr_data
|
||||
.movie_details_modal
|
||||
.as_mut()
|
||||
.unwrap()
|
||||
.movie_cast,
|
||||
Credit
|
||||
);
|
||||
handle_table_events!(
|
||||
self,
|
||||
movie_crew,
|
||||
self
|
||||
.app
|
||||
.data
|
||||
.radarr_data
|
||||
.movie_details_modal
|
||||
.as_mut()
|
||||
.unwrap()
|
||||
.movie_crew,
|
||||
Credit
|
||||
);
|
||||
}
|
||||
|
||||
impl<'a, 'b> KeyEventHandler<'a, 'b, ActiveRadarrBlock> for MovieDetailsHandler<'a, 'b> {
|
||||
@@ -66,8 +89,7 @@ impl<'a, 'b> KeyEventHandler<'a, 'b, ActiveRadarrBlock> for MovieDetailsHandler<
|
||||
TableHandlingProps::new(ActiveRadarrBlock::ManualSearch.into())
|
||||
.sorting_block(ActiveRadarrBlock::ManualSearchSortPrompt.into())
|
||||
.sort_options(releases_sorting_options());
|
||||
let movie_cast_table_handling_props =
|
||||
TableHandlingProps::new(ActiveRadarrBlock::Cast.into());
|
||||
let movie_cast_table_handling_props = TableHandlingProps::new(ActiveRadarrBlock::Cast.into());
|
||||
let movie_crew_table_handling_props = TableHandlingProps::new(ActiveRadarrBlock::Crew.into());
|
||||
|
||||
if !self.handle_movie_history_table_events(movie_history_table_handling_props)
|
||||
@@ -127,8 +149,8 @@ impl<'a, 'b> KeyEventHandler<'a, 'b, ActiveRadarrBlock> for MovieDetailsHandler<
|
||||
}
|
||||
|
||||
fn handle_scroll_up(&mut self) {
|
||||
match self.active_radarr_block {
|
||||
ActiveRadarrBlock::MovieDetails => self
|
||||
if self.active_radarr_block == ActiveRadarrBlock::MovieDetails {
|
||||
self
|
||||
.app
|
||||
.data
|
||||
.radarr_data
|
||||
@@ -136,14 +158,13 @@ impl<'a, 'b> KeyEventHandler<'a, 'b, ActiveRadarrBlock> for MovieDetailsHandler<
|
||||
.as_mut()
|
||||
.unwrap()
|
||||
.movie_details
|
||||
.scroll_up(),
|
||||
_ => (),
|
||||
.scroll_up()
|
||||
}
|
||||
}
|
||||
|
||||
fn handle_scroll_down(&mut self) {
|
||||
match self.active_radarr_block {
|
||||
ActiveRadarrBlock::MovieDetails => self
|
||||
if self.active_radarr_block == ActiveRadarrBlock::MovieDetails {
|
||||
self
|
||||
.app
|
||||
.data
|
||||
.radarr_data
|
||||
@@ -151,14 +172,13 @@ impl<'a, 'b> KeyEventHandler<'a, 'b, ActiveRadarrBlock> for MovieDetailsHandler<
|
||||
.as_mut()
|
||||
.unwrap()
|
||||
.movie_details
|
||||
.scroll_down(),
|
||||
_ => (),
|
||||
.scroll_down()
|
||||
}
|
||||
}
|
||||
|
||||
fn handle_home(&mut self) {
|
||||
match self.active_radarr_block {
|
||||
ActiveRadarrBlock::MovieDetails => self
|
||||
if self.active_radarr_block == ActiveRadarrBlock::MovieDetails {
|
||||
self
|
||||
.app
|
||||
.data
|
||||
.radarr_data
|
||||
@@ -166,14 +186,13 @@ impl<'a, 'b> KeyEventHandler<'a, 'b, ActiveRadarrBlock> for MovieDetailsHandler<
|
||||
.as_mut()
|
||||
.unwrap()
|
||||
.movie_details
|
||||
.scroll_to_top(),
|
||||
_ => (),
|
||||
.scroll_to_top()
|
||||
}
|
||||
}
|
||||
|
||||
fn handle_end(&mut self) {
|
||||
match self.active_radarr_block {
|
||||
ActiveRadarrBlock::MovieDetails => self
|
||||
if let ActiveRadarrBlock::MovieDetails = self.active_radarr_block {
|
||||
self
|
||||
.app
|
||||
.data
|
||||
.radarr_data
|
||||
@@ -181,8 +200,7 @@ impl<'a, 'b> KeyEventHandler<'a, 'b, ActiveRadarrBlock> for MovieDetailsHandler<
|
||||
.as_mut()
|
||||
.unwrap()
|
||||
.movie_details
|
||||
.scroll_to_bottom(),
|
||||
_ => (),
|
||||
.scroll_to_bottom()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user