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()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -3,12 +3,12 @@ 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::handlers::{handle_clear_errors, handle_prompt_toggle, KeyEventHandler};
|
||||
use crate::models::servarr_data::sonarr::sonarr_data::{ActiveSonarrBlock, BLOCKLIST_BLOCKS};
|
||||
use crate::models::sonarr_models::BlocklistItem;
|
||||
use crate::models::stateful_table::SortOption;
|
||||
use crate::models::{Scrollable, HorizontallyScrollableText};
|
||||
use crate::models::Scrollable;
|
||||
use crate::network::sonarr_network::SonarrEvent;
|
||||
|
||||
#[cfg(test)]
|
||||
@@ -23,21 +23,27 @@ pub(super) struct BlocklistHandler<'a, 'b> {
|
||||
}
|
||||
|
||||
impl<'a, 'b> BlocklistHandler<'a, 'b> {
|
||||
handle_table_events!(self, blocklist, self.app.data.sonarr_data.blocklist, BlocklistItem);
|
||||
handle_table_events!(
|
||||
self,
|
||||
blocklist,
|
||||
self.app.data.sonarr_data.blocklist,
|
||||
BlocklistItem
|
||||
);
|
||||
}
|
||||
|
||||
impl<'a, 'b> KeyEventHandler<'a, 'b, ActiveSonarrBlock> for BlocklistHandler<'a, 'b> {
|
||||
fn handle(&mut self) {
|
||||
let blocklist_table_handling_props = TableHandlingProps::new(ActiveSonarrBlock::Blocklist.into())
|
||||
.sorting_block(ActiveSonarrBlock::BlocklistSortPrompt.into())
|
||||
.sort_by_fn(|a: &BlocklistItem, b: &BlocklistItem| a.id.cmp(&b.id))
|
||||
.sort_options(blocklist_sorting_options());
|
||||
|
||||
let blocklist_table_handling_props =
|
||||
TableHandlingProps::new(ActiveSonarrBlock::Blocklist.into())
|
||||
.sorting_block(ActiveSonarrBlock::BlocklistSortPrompt.into())
|
||||
.sort_by_fn(|a: &BlocklistItem, b: &BlocklistItem| a.id.cmp(&b.id))
|
||||
.sort_options(blocklist_sorting_options());
|
||||
|
||||
if !self.handle_blocklist_table_events(blocklist_table_handling_props) {
|
||||
self.handle_key_event();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
fn accepts(active_block: ActiveSonarrBlock) -> bool {
|
||||
BLOCKLIST_BLOCKS.contains(&active_block)
|
||||
}
|
||||
|
||||
@@ -1,14 +1,13 @@
|
||||
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::handlers::{handle_clear_errors, handle_prompt_toggle, KeyEventHandler};
|
||||
use crate::models::servarr_data::sonarr::sonarr_data::{ActiveSonarrBlock, DOWNLOADS_BLOCKS};
|
||||
use crate::models::Scrollable;
|
||||
use crate::models::sonarr_models::DownloadRecord;
|
||||
use crate::models::Scrollable;
|
||||
use crate::network::sonarr_network::SonarrEvent;
|
||||
|
||||
#[cfg(test)]
|
||||
@@ -23,18 +22,24 @@ pub(super) struct DownloadsHandler<'a, 'b> {
|
||||
}
|
||||
|
||||
impl<'a, 'b> DownloadsHandler<'a, 'b> {
|
||||
handle_table_events!(self, downloads, self.app.data.sonarr_data.downloads, DownloadRecord);
|
||||
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());
|
||||
|
||||
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)
|
||||
}
|
||||
@@ -61,17 +66,13 @@ impl<'a, 'b> KeyEventHandler<'a, 'b, ActiveSonarrBlock> for DownloadsHandler<'a,
|
||||
!self.app.is_loading && !self.app.data.sonarr_data.downloads.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) {
|
||||
if self.active_sonarr_block == ActiveSonarrBlock::Downloads {
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
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::table_handler::TableHandlingProps;
|
||||
use crate::handlers::{handle_clear_errors, KeyEventHandler};
|
||||
use crate::models::servarr_data::sonarr::sonarr_data::{ActiveSonarrBlock, HISTORY_BLOCKS};
|
||||
use crate::models::sonarr_models::SonarrHistoryItem;
|
||||
use crate::models::stateful_table::SortOption;
|
||||
use crate::models::{HorizontallyScrollableText, Scrollable};
|
||||
use crate::handle_table_events;
|
||||
use crate::models::Scrollable;
|
||||
|
||||
#[cfg(test)]
|
||||
#[path = "history_handler_tests.rs"]
|
||||
@@ -85,9 +85,8 @@ impl<'a, 'b> KeyEventHandler<'a, 'b, ActiveSonarrBlock> for HistoryHandler<'a, '
|
||||
fn handle_delete(&mut self) {}
|
||||
|
||||
fn handle_left_right_action(&mut self) {
|
||||
match self.active_sonarr_block {
|
||||
ActiveSonarrBlock::History => handle_change_tab_left_right_keys(self.app, self.key),
|
||||
_ => {}
|
||||
if self.active_sonarr_block == ActiveSonarrBlock::History {
|
||||
handle_change_tab_left_right_keys(self.app, self.key)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -14,7 +14,6 @@ use crate::models::servarr_data::sonarr::sonarr_data::{
|
||||
};
|
||||
use crate::models::servarr_models::Indexer;
|
||||
use crate::models::BlockSelectionState;
|
||||
use crate::models::HorizontallyScrollableText;
|
||||
use crate::models::Scrollable;
|
||||
use crate::network::sonarr_network::SonarrEvent;
|
||||
|
||||
|
||||
@@ -9,7 +9,7 @@ use crate::models::servarr_data::sonarr::sonarr_data::{
|
||||
ActiveSonarrBlock, EDIT_SERIES_SELECTION_BLOCKS, SERIES_DETAILS_BLOCKS,
|
||||
};
|
||||
use crate::models::sonarr_models::{Season, SonarrHistoryItem};
|
||||
use crate::models::{BlockSelectionState, HorizontallyScrollableText, Scrollable};
|
||||
use crate::models::{BlockSelectionState, Scrollable};
|
||||
use crate::network::sonarr_network::SonarrEvent;
|
||||
|
||||
#[cfg(test)]
|
||||
|
||||
@@ -319,7 +319,7 @@ macro_rules! handle_table_events {
|
||||
.app
|
||||
.push_navigation_stack(props.filtering_block.expect("Filtering block is undefined").into());
|
||||
$table.reset_filter();
|
||||
$table.filter = Some(HorizontallyScrollableText::default());
|
||||
$table.filter = Some($crate::models::HorizontallyScrollableText::default());
|
||||
$self.app.should_ignore_quit_key = true;
|
||||
|
||||
true
|
||||
@@ -333,7 +333,7 @@ macro_rules! handle_table_events {
|
||||
$self
|
||||
.app
|
||||
.push_navigation_stack(props.searching_block.expect("Searching block is undefined"));
|
||||
$table.search = Some(HorizontallyScrollableText::default());
|
||||
$table.search = Some($crate::models::HorizontallyScrollableText::default());
|
||||
$self.app.should_ignore_quit_key = true;
|
||||
|
||||
true
|
||||
|
||||
Reference in New Issue
Block a user