Refactored the UI module and the handlers module to do a more chain-of-responsibility method to manage the UI's and handlers for different key events. Also, initial work for indexer settings as well

This commit is contained in:
2023-08-08 10:50:07 -06:00
parent 718613d59f
commit cf11527fef
67 changed files with 5255 additions and 2216 deletions
@@ -0,0 +1,63 @@
use tui::backend::Backend;
use tui::layout::Rect;
use tui::Frame;
use crate::app::radarr::{ActiveRadarrBlock, DELETE_MOVIE_BLOCKS};
use crate::app::App;
use crate::models::Route;
use crate::ui::radarr_ui::library::draw_library;
use crate::ui::{draw_prompt_box_with_checkboxes, draw_prompt_popup_over, DrawUi};
#[cfg(test)]
#[path = "delete_movie_ui_tests.rs"]
mod delete_movie_ui_tests;
pub(super) struct DeleteMovieUi {}
impl DrawUi for DeleteMovieUi {
fn accepts(route: Route) -> bool {
if let Route::Radarr(active_radarr_block, _) = route {
return DELETE_MOVIE_BLOCKS.contains(&active_radarr_block);
}
false
}
fn draw<B: Backend>(f: &mut Frame<'_, B>, app: &mut App<'_>, content_rect: Rect) {
if matches!(
*app.get_current_route(),
Route::Radarr(ActiveRadarrBlock::DeleteMoviePrompt, _)
) {
let draw_delete_movie_prompt =
|f: &mut Frame<'_, B>, app: &mut App<'_>, prompt_area: Rect| {
let selected_block = app.data.radarr_data.selected_block.get_active_block();
draw_prompt_box_with_checkboxes(
f,
prompt_area,
"Delete Movie",
format!(
"Do you really want to delete: {}?",
app.data.radarr_data.movies.current_selection().title
)
.as_str(),
vec![
(
"Delete Movie Files",
app.data.radarr_data.delete_movie_files,
selected_block == &ActiveRadarrBlock::DeleteMovieToggleDeleteFile,
),
(
"Add List Exclusion",
app.data.radarr_data.add_list_exclusion,
selected_block == &ActiveRadarrBlock::DeleteMovieToggleAddListExclusion,
),
],
selected_block == &ActiveRadarrBlock::DeleteMovieConfirmPrompt,
app.data.radarr_data.prompt_confirm,
)
};
draw_prompt_popup_over(f, app, content_rect, draw_library, draw_delete_movie_prompt);
}
}
}