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:
+1
-1
@@ -16,7 +16,7 @@ indoc = "2.0.0"
|
|||||||
log = "0.4.17"
|
log = "0.4.17"
|
||||||
log4rs = { version = "1.2.0", features = ["file_appender"] }
|
log4rs = { version = "1.2.0", features = ["file_appender"] }
|
||||||
regex = "1.7.1"
|
regex = "1.7.1"
|
||||||
reqwest = { version = "0.11.13", features = ["json"] }
|
reqwest = { version = "0.11.14", features = ["json"] }
|
||||||
serde_yaml = "0.9.16"
|
serde_yaml = "0.9.16"
|
||||||
serde_json = "1.0.91"
|
serde_json = "1.0.91"
|
||||||
serde = { version = "1.0", features = ["derive"] }
|
serde = { version = "1.0", features = ["derive"] }
|
||||||
|
|||||||
@@ -175,7 +175,15 @@ impl<'a> KeyEventHandler<'a, ActiveRadarrBlock> for AddMovieHandler<'a> {
|
|||||||
.push_navigation_stack(ActiveRadarrBlock::AddMovieSearchResults.into());
|
.push_navigation_stack(ActiveRadarrBlock::AddMovieSearchResults.into());
|
||||||
self.app.should_ignore_quit_key = false;
|
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
|
self
|
||||||
.app
|
.app
|
||||||
.push_navigation_stack(ActiveRadarrBlock::AddMoviePrompt.into());
|
.push_navigation_stack(ActiveRadarrBlock::AddMoviePrompt.into());
|
||||||
@@ -439,6 +447,11 @@ mod tests {
|
|||||||
#[test]
|
#[test]
|
||||||
fn test_add_movie_search_results_submit() {
|
fn test_add_movie_search_results_submit() {
|
||||||
let mut app = App::default();
|
let mut app = App::default();
|
||||||
|
app
|
||||||
|
.data
|
||||||
|
.radarr_data
|
||||||
|
.add_searched_movies
|
||||||
|
.set_items(vec![AddMovieSearchResult::default()]);
|
||||||
app.data.radarr_data.quality_profile_map =
|
app.data.radarr_data.quality_profile_map =
|
||||||
HashMap::from([(1, "B - Test 2".to_owned()), (0, "A - Test 1".to_owned())]);
|
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]
|
#[test]
|
||||||
fn test_add_movie_prompt_prompt_decline() {
|
fn test_add_movie_prompt_prompt_decline() {
|
||||||
let mut app = App::default();
|
let mut app = App::default();
|
||||||
|
|||||||
@@ -9,8 +9,8 @@ use crate::models::radarr_models::AddMovieSearchResult;
|
|||||||
use crate::models::Route;
|
use crate::models::Route;
|
||||||
use crate::ui::utils::{
|
use crate::ui::utils::{
|
||||||
borderless_block, get_width_with_margin, horizontal_chunks, layout_block,
|
borderless_block, get_width_with_margin, horizontal_chunks, layout_block,
|
||||||
layout_paragraph_borderless, show_cursor, style_default, style_help, style_primary,
|
layout_paragraph_borderless, show_cursor, style_default, style_failure, style_help,
|
||||||
title_block_centered, vertical_chunks_with_margin,
|
style_primary, title_block_centered, vertical_chunks_with_margin,
|
||||||
};
|
};
|
||||||
use crate::ui::{
|
use crate::ui::{
|
||||||
draw_button, draw_drop_down_list, draw_drop_down_menu_button, draw_drop_down_popup,
|
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);
|
.alignment(Alignment::Center);
|
||||||
f.render_widget(help_paragraph, chunks[2]);
|
f.render_widget(help_paragraph, chunks[2]);
|
||||||
|
|
||||||
draw_table(
|
if app.data.radarr_data.add_searched_movies.items.is_empty() && !app.is_loading {
|
||||||
f,
|
let mut error_text = Text::from("No movies found matching your query!");
|
||||||
chunks[1],
|
error_text.patch_style(style_failure());
|
||||||
layout_block(),
|
let error_paragraph = Paragraph::new(error_text).block(layout_block());
|
||||||
TableProps {
|
f.render_widget(error_paragraph, chunks[1]);
|
||||||
content: &mut app.data.radarr_data.add_searched_movies,
|
} else {
|
||||||
table_headers: vec![
|
draw_table(
|
||||||
"Title",
|
f,
|
||||||
"Year",
|
chunks[1],
|
||||||
"Runtime",
|
layout_block(),
|
||||||
"IMDB",
|
TableProps {
|
||||||
"Rotten Tomatoes",
|
content: &mut app.data.radarr_data.add_searched_movies,
|
||||||
"Genres",
|
table_headers: vec![
|
||||||
],
|
"Title",
|
||||||
constraints: vec![
|
"Year",
|
||||||
Constraint::Percentage(27),
|
"Runtime",
|
||||||
Constraint::Percentage(8),
|
"IMDB",
|
||||||
Constraint::Percentage(10),
|
"Rotten Tomatoes",
|
||||||
Constraint::Percentage(8),
|
"Genres",
|
||||||
Constraint::Percentage(14),
|
],
|
||||||
Constraint::Percentage(30),
|
constraints: vec![
|
||||||
],
|
Constraint::Percentage(27),
|
||||||
help: None,
|
Constraint::Percentage(8),
|
||||||
},
|
Constraint::Percentage(10),
|
||||||
|movie| {
|
Constraint::Percentage(8),
|
||||||
let (hours, minutes) = convert_runtime(movie.runtime.as_u64().unwrap());
|
Constraint::Percentage(14),
|
||||||
let imdb_rating = movie
|
Constraint::Percentage(30),
|
||||||
.ratings
|
],
|
||||||
.imdb
|
help: None,
|
||||||
.clone()
|
},
|
||||||
.unwrap_or_default()
|
|movie| {
|
||||||
.value
|
let (hours, minutes) = convert_runtime(movie.runtime.as_u64().unwrap());
|
||||||
.as_f64()
|
let imdb_rating = movie
|
||||||
.unwrap();
|
.ratings
|
||||||
let rotten_tomatoes_rating = movie
|
.imdb
|
||||||
.ratings
|
.clone()
|
||||||
.rotten_tomatoes
|
.unwrap_or_default()
|
||||||
.clone()
|
.value
|
||||||
.unwrap_or_default()
|
.as_f64()
|
||||||
.value
|
.unwrap();
|
||||||
.as_u64()
|
let rotten_tomatoes_rating = movie
|
||||||
.unwrap();
|
.ratings
|
||||||
let imdb_rating = if imdb_rating == 0.0 {
|
.rotten_tomatoes
|
||||||
String::default()
|
.clone()
|
||||||
} else {
|
.unwrap_or_default()
|
||||||
format!("{:.1}", imdb_rating)
|
.value
|
||||||
};
|
.as_u64()
|
||||||
let rotten_tomatoes_rating = if rotten_tomatoes_rating == 0 {
|
.unwrap();
|
||||||
String::default()
|
let imdb_rating = if imdb_rating == 0.0 {
|
||||||
} else {
|
String::default()
|
||||||
format!("{}%", rotten_tomatoes_rating)
|
} else {
|
||||||
};
|
format!("{:.1}", imdb_rating)
|
||||||
|
};
|
||||||
|
let rotten_tomatoes_rating = if rotten_tomatoes_rating == 0 {
|
||||||
|
String::default()
|
||||||
|
} else {
|
||||||
|
format!("{}%", rotten_tomatoes_rating)
|
||||||
|
};
|
||||||
|
|
||||||
movie
|
movie
|
||||||
.title
|
.title
|
||||||
.scroll_or_reset(get_width_with_margin(area), *movie == current_selection);
|
.scroll_or_reset(get_width_with_margin(area), *movie == current_selection);
|
||||||
|
|
||||||
Row::new(vec![
|
Row::new(vec![
|
||||||
Cell::from(movie.title.to_string()),
|
Cell::from(movie.title.to_string()),
|
||||||
Cell::from(movie.year.as_u64().unwrap().to_string()),
|
Cell::from(movie.year.as_u64().unwrap().to_string()),
|
||||||
Cell::from(format!("{}h {}m", hours, minutes)),
|
Cell::from(format!("{}h {}m", hours, minutes)),
|
||||||
Cell::from(imdb_rating),
|
Cell::from(imdb_rating),
|
||||||
Cell::from(rotten_tomatoes_rating),
|
Cell::from(rotten_tomatoes_rating),
|
||||||
Cell::from(movie.genres.join(", ")),
|
Cell::from(movie.genres.join(", ")),
|
||||||
])
|
])
|
||||||
.style(style_primary())
|
.style(style_primary())
|
||||||
},
|
},
|
||||||
app.is_loading,
|
app.is_loading,
|
||||||
);
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
_ => (),
|
_ => (),
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user