Refactored the filter and search logic to follow the established modal logic and added some refactored functions to the UI module as well to clean up the UI code too

This commit is contained in:
2023-08-10 16:43:57 -06:00
parent ce12ebd301
commit f7cb832095
15 changed files with 695 additions and 463 deletions
+3 -126
View File
@@ -11,9 +11,7 @@ use tui::Frame;
use crate::app::App;
use crate::logos::RADARR_LOGO;
use crate::models::radarr_models::{DiskSpace, DownloadRecord, Movie, RootFolder};
use crate::models::servarr_data::radarr::radarr_data::{
ActiveRadarrBlock, RadarrData, FILTER_BLOCKS, SEARCH_BLOCKS,
};
use crate::models::servarr_data::radarr::radarr_data::RadarrData;
use crate::models::Route;
use crate::ui::draw_tabs;
use crate::ui::loading;
@@ -25,9 +23,8 @@ use crate::ui::radarr_ui::root_folders::RootFoldersUi;
use crate::ui::radarr_ui::system::SystemUi;
use crate::ui::utils::{
borderless_block, horizontal_chunks, layout_block, line_gauge_with_label, line_gauge_with_title,
show_cursor, style_awaiting_import, style_bold, style_default, style_failure, style_help,
style_success, style_unmonitored, style_warning, title_block, title_block_centered,
vertical_chunks_with_margin,
style_awaiting_import, style_bold, style_default, style_failure, style_success,
style_unmonitored, style_warning, title_block, vertical_chunks_with_margin,
};
use crate::ui::DrawUi;
use crate::utils::convert_to_gb;
@@ -231,126 +228,6 @@ fn determine_row_style(downloads_vec: &[DownloadRecord], movie: &Movie) -> Style
}
}
fn draw_search_box<B: Backend>(f: &mut Frame<'_, B>, app: &mut App<'_>, area: Rect) {
let chunks = vertical_chunks_with_margin(
vec![
Constraint::Length(3),
Constraint::Length(1),
Constraint::Min(0),
],
area,
1,
);
if !app.data.radarr_data.is_searching {
let error_msg = match app.get_current_route() {
Route::Radarr(active_radarr_block, _) => match active_radarr_block {
ActiveRadarrBlock::SearchMovie => "Movie not found!",
ActiveRadarrBlock::SearchCollection => "Collection not found!",
_ => "",
},
_ => "",
};
let input = Paragraph::new(error_msg)
.style(style_failure())
.block(layout_block());
f.render_widget(input, chunks[0]);
} else {
let default_content = String::default();
let (block_title, offset, block_content) = match app.get_current_route() {
Route::Radarr(active_radarr_block, _) => match active_radarr_block {
_ if SEARCH_BLOCKS.contains(active_radarr_block) => (
"Search",
*app
.data
.radarr_data
.search
.as_ref()
.unwrap()
.offset
.borrow(),
&app.data.radarr_data.search.as_ref().unwrap().text,
),
_ => ("", 0, &default_content),
},
_ => ("", 0, &default_content),
};
let input = Paragraph::new(block_content.as_str())
.style(style_default())
.block(title_block_centered(block_title));
let help = Paragraph::new("<esc> cancel")
.style(style_help())
.alignment(Alignment::Center)
.block(borderless_block());
show_cursor(f, chunks[0], offset, block_content);
f.render_widget(input, chunks[0]);
f.render_widget(help, chunks[1]);
}
}
fn draw_filter_box<B: Backend>(f: &mut Frame<'_, B>, app: &mut App<'_>, area: Rect) {
let chunks = vertical_chunks_with_margin(
vec![
Constraint::Length(3),
Constraint::Length(1),
Constraint::Min(0),
],
area,
1,
);
if !app.data.radarr_data.is_filtering {
let error_msg = match app.get_current_route() {
Route::Radarr(active_radarr_block, _) => match active_radarr_block {
ActiveRadarrBlock::FilterMovies => "No movies found matching filter!",
ActiveRadarrBlock::FilterCollections => "No collections found matching filter!",
_ => "",
},
_ => "",
};
let input = Paragraph::new(error_msg)
.style(style_failure())
.block(layout_block());
f.render_widget(input, chunks[0]);
} else {
let default_content = String::default();
let (block_title, offset, block_content) = match app.get_current_route() {
Route::Radarr(active_radarr_block, _) => match active_radarr_block {
_ if FILTER_BLOCKS.contains(active_radarr_block) => (
"Filter",
*app
.data
.radarr_data
.filter
.as_ref()
.unwrap()
.offset
.borrow(),
&app.data.radarr_data.filter.as_ref().unwrap().text,
),
_ => ("", 0, &default_content),
},
_ => ("", 0, &default_content),
};
let input = Paragraph::new(block_content.as_str())
.style(style_default())
.block(title_block_centered(block_title));
let help = Paragraph::new("<esc> cancel")
.style(style_help())
.alignment(Alignment::Center)
.block(borderless_block());
show_cursor(f, chunks[0], offset, block_content);
f.render_widget(input, chunks[0]);
f.render_widget(help, chunks[1]);
}
}
fn draw_radarr_logo<B: Backend>(f: &mut Frame<'_, B>, area: Rect) {
let mut logo_text = Text::from(RADARR_LOGO);
logo_text.patch_style(Style::default().fg(Color::LightYellow));