Fixed UI bug that didn't alert users when they tried to add a movie that couldn't be found

This commit is contained in:
2023-08-08 10:50:05 -06:00
parent dc9ea91739
commit 316c129b99
3 changed files with 108 additions and 71 deletions
@@ -175,7 +175,15 @@ impl<'a> KeyEventHandler<'a, ActiveRadarrBlock> for AddMovieHandler<'a> {
.push_navigation_stack(ActiveRadarrBlock::AddMovieSearchResults.into());
self.app.should_ignore_quit_key = false;
}
ActiveRadarrBlock::AddMovieSearchResults => {
_ if *self.active_radarr_block == ActiveRadarrBlock::AddMovieSearchResults
&& !self
.app
.data
.radarr_data
.add_searched_movies
.items
.is_empty() =>
{
self
.app
.push_navigation_stack(ActiveRadarrBlock::AddMoviePrompt.into());
@@ -439,6 +447,11 @@ mod tests {
#[test]
fn test_add_movie_search_results_submit() {
let mut app = App::default();
app
.data
.radarr_data
.add_searched_movies
.set_items(vec![AddMovieSearchResult::default()]);
app.data.radarr_data.quality_profile_map =
HashMap::from([(1, "B - Test 2".to_owned()), (0, "A - Test 1".to_owned())]);
@@ -476,6 +489,23 @@ mod tests {
);
}
#[test]
fn test_add_movie_search_results_submit_does_nothing_on_empty_table() {
let mut app = App::default();
app.push_navigation_stack(ActiveRadarrBlock::AddMovieSearchResults.into());
AddMovieHandler::with(
&SUBMIT_KEY,
&mut app,
&ActiveRadarrBlock::AddMovieSearchResults,
)
.handle();
assert_eq!(
app.get_current_route(),
&ActiveRadarrBlock::AddMovieSearchResults.into()
);
}
#[test]
fn test_add_movie_prompt_prompt_decline() {
let mut app = App::default();
+76 -69
View File
@@ -9,8 +9,8 @@ use crate::models::radarr_models::AddMovieSearchResult;
use crate::models::Route;
use crate::ui::utils::{
borderless_block, get_width_with_margin, horizontal_chunks, layout_block,
layout_paragraph_borderless, show_cursor, style_default, style_help, style_primary,
title_block_centered, vertical_chunks_with_margin,
layout_paragraph_borderless, show_cursor, style_default, style_failure, style_help,
style_primary, title_block_centered, vertical_chunks_with_margin,
};
use crate::ui::{
draw_button, draw_drop_down_list, draw_drop_down_menu_button, draw_drop_down_popup,
@@ -91,75 +91,82 @@ fn draw_add_movie_search<B: Backend>(f: &mut Frame<'_, B>, app: &mut App, area:
.alignment(Alignment::Center);
f.render_widget(help_paragraph, chunks[2]);
draw_table(
f,
chunks[1],
layout_block(),
TableProps {
content: &mut app.data.radarr_data.add_searched_movies,
table_headers: vec![
"Title",
"Year",
"Runtime",
"IMDB",
"Rotten Tomatoes",
"Genres",
],
constraints: vec![
Constraint::Percentage(27),
Constraint::Percentage(8),
Constraint::Percentage(10),
Constraint::Percentage(8),
Constraint::Percentage(14),
Constraint::Percentage(30),
],
help: None,
},
|movie| {
let (hours, minutes) = convert_runtime(movie.runtime.as_u64().unwrap());
let imdb_rating = movie
.ratings
.imdb
.clone()
.unwrap_or_default()
.value
.as_f64()
.unwrap();
let rotten_tomatoes_rating = movie
.ratings
.rotten_tomatoes
.clone()
.unwrap_or_default()
.value
.as_u64()
.unwrap();
let imdb_rating = if imdb_rating == 0.0 {
String::default()
} else {
format!("{:.1}", imdb_rating)
};
let rotten_tomatoes_rating = if rotten_tomatoes_rating == 0 {
String::default()
} else {
format!("{}%", rotten_tomatoes_rating)
};
if app.data.radarr_data.add_searched_movies.items.is_empty() && !app.is_loading {
let mut error_text = Text::from("No movies found matching your query!");
error_text.patch_style(style_failure());
let error_paragraph = Paragraph::new(error_text).block(layout_block());
f.render_widget(error_paragraph, chunks[1]);
} else {
draw_table(
f,
chunks[1],
layout_block(),
TableProps {
content: &mut app.data.radarr_data.add_searched_movies,
table_headers: vec![
"Title",
"Year",
"Runtime",
"IMDB",
"Rotten Tomatoes",
"Genres",
],
constraints: vec![
Constraint::Percentage(27),
Constraint::Percentage(8),
Constraint::Percentage(10),
Constraint::Percentage(8),
Constraint::Percentage(14),
Constraint::Percentage(30),
],
help: None,
},
|movie| {
let (hours, minutes) = convert_runtime(movie.runtime.as_u64().unwrap());
let imdb_rating = movie
.ratings
.imdb
.clone()
.unwrap_or_default()
.value
.as_f64()
.unwrap();
let rotten_tomatoes_rating = movie
.ratings
.rotten_tomatoes
.clone()
.unwrap_or_default()
.value
.as_u64()
.unwrap();
let imdb_rating = if imdb_rating == 0.0 {
String::default()
} else {
format!("{:.1}", imdb_rating)
};
let rotten_tomatoes_rating = if rotten_tomatoes_rating == 0 {
String::default()
} else {
format!("{}%", rotten_tomatoes_rating)
};
movie
.title
.scroll_or_reset(get_width_with_margin(area), *movie == current_selection);
movie
.title
.scroll_or_reset(get_width_with_margin(area), *movie == current_selection);
Row::new(vec![
Cell::from(movie.title.to_string()),
Cell::from(movie.year.as_u64().unwrap().to_string()),
Cell::from(format!("{}h {}m", hours, minutes)),
Cell::from(imdb_rating),
Cell::from(rotten_tomatoes_rating),
Cell::from(movie.genres.join(", ")),
])
.style(style_primary())
},
app.is_loading,
);
Row::new(vec![
Cell::from(movie.title.to_string()),
Cell::from(movie.year.as_u64().unwrap().to_string()),
Cell::from(format!("{}h {}m", hours, minutes)),
Cell::from(imdb_rating),
Cell::from(rotten_tomatoes_rating),
Cell::from(movie.genres.join(", ")),
])
.style(style_primary())
},
app.is_loading,
);
}
}
_ => (),
}