refactor(root_folder_handler): Use the new handle_table_events macro
This commit is contained in:
@@ -2,11 +2,13 @@ use crate::app::key_binding::DEFAULT_KEYBINDINGS;
|
||||
use crate::app::App;
|
||||
use crate::event::Key;
|
||||
use crate::handlers::sonarr_handlers::handle_change_tab_left_right_keys;
|
||||
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, ROOT_FOLDERS_BLOCKS};
|
||||
use crate::models::servarr_models::RootFolder;
|
||||
use crate::models::{HorizontallyScrollableText, Scrollable};
|
||||
use crate::network::sonarr_network::SonarrEvent;
|
||||
use crate::{handle_text_box_keys, handle_text_box_left_right_keys};
|
||||
use crate::{handle_table_events, handle_text_box_keys, handle_text_box_left_right_keys};
|
||||
|
||||
#[cfg(test)]
|
||||
#[path = "root_folders_handler_tests.rs"]
|
||||
@@ -19,7 +21,25 @@ pub(super) struct RootFoldersHandler<'a, 'b> {
|
||||
_context: Option<ActiveSonarrBlock>,
|
||||
}
|
||||
|
||||
impl<'a, 'b> RootFoldersHandler<'a, 'b> {
|
||||
handle_table_events!(
|
||||
self,
|
||||
root_folders,
|
||||
self.app.data.sonarr_data.root_folders,
|
||||
RootFolder
|
||||
);
|
||||
}
|
||||
|
||||
impl<'a, 'b> KeyEventHandler<'a, 'b, ActiveSonarrBlock> for RootFoldersHandler<'a, 'b> {
|
||||
fn handle(&mut self) {
|
||||
let root_folders_table_handling_props =
|
||||
TableHandlingProps::new(ActiveSonarrBlock::RootFolders.into());
|
||||
|
||||
if !self.handle_root_folders_table_events(root_folders_table_handling_props) {
|
||||
self.handle_key_event();
|
||||
}
|
||||
}
|
||||
|
||||
fn accepts(active_block: ActiveSonarrBlock) -> bool {
|
||||
ROOT_FOLDERS_BLOCKS.contains(&active_block)
|
||||
}
|
||||
@@ -46,45 +66,33 @@ impl<'a, 'b> KeyEventHandler<'a, 'b, ActiveSonarrBlock> for RootFoldersHandler<'
|
||||
!self.app.is_loading && !self.app.data.sonarr_data.root_folders.is_empty()
|
||||
}
|
||||
|
||||
fn handle_scroll_up(&mut self) {
|
||||
if self.active_sonarr_block == ActiveSonarrBlock::RootFolders {
|
||||
self.app.data.sonarr_data.root_folders.scroll_up()
|
||||
}
|
||||
}
|
||||
fn handle_scroll_up(&mut self) {}
|
||||
|
||||
fn handle_scroll_down(&mut self) {
|
||||
if self.active_sonarr_block == ActiveSonarrBlock::RootFolders {
|
||||
self.app.data.sonarr_data.root_folders.scroll_down()
|
||||
}
|
||||
}
|
||||
fn handle_scroll_down(&mut self) {}
|
||||
|
||||
fn handle_home(&mut self) {
|
||||
match self.active_sonarr_block {
|
||||
ActiveSonarrBlock::RootFolders => self.app.data.sonarr_data.root_folders.scroll_to_top(),
|
||||
ActiveSonarrBlock::AddRootFolderPrompt => self
|
||||
if self.active_sonarr_block == ActiveSonarrBlock::AddRootFolderPrompt {
|
||||
self
|
||||
.app
|
||||
.data
|
||||
.sonarr_data
|
||||
.edit_root_folder
|
||||
.as_mut()
|
||||
.unwrap()
|
||||
.scroll_home(),
|
||||
_ => (),
|
||||
.scroll_home()
|
||||
}
|
||||
}
|
||||
|
||||
fn handle_end(&mut self) {
|
||||
match self.active_sonarr_block {
|
||||
ActiveSonarrBlock::RootFolders => self.app.data.sonarr_data.root_folders.scroll_to_bottom(),
|
||||
ActiveSonarrBlock::AddRootFolderPrompt => self
|
||||
if self.active_sonarr_block == ActiveSonarrBlock::AddRootFolderPrompt {
|
||||
self
|
||||
.app
|
||||
.data
|
||||
.sonarr_data
|
||||
.edit_root_folder
|
||||
.as_mut()
|
||||
.unwrap()
|
||||
.reset_offset(),
|
||||
_ => (),
|
||||
.reset_offset()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -123,6 +123,7 @@ mod tests {
|
||||
fn test_add_root_folder_prompt_home_end_keys() {
|
||||
let mut app = App::default();
|
||||
app.push_navigation_stack(ActiveSonarrBlock::RootFolders.into());
|
||||
app.push_navigation_stack(ActiveSonarrBlock::AddRootFolderPrompt.into());
|
||||
app
|
||||
.data
|
||||
.sonarr_data
|
||||
|
||||
Reference in New Issue
Block a user