Updated Ratatui, created custom deserialization logic for i64s to make life easier, and used string interpolation where possible to reduce the lines needed to write log messages or create formatted text

This commit is contained in:
2023-09-07 17:20:38 -06:00
parent e13d1ece58
commit b16a58deae
43 changed files with 426 additions and 536 deletions
+7 -7
View File
@@ -29,7 +29,7 @@ use crate::App;
#[path = "add_movie_ui_tests.rs"]
mod add_movie_ui_tests;
pub(super) struct AddMovieUi {}
pub(super) struct AddMovieUi;
impl DrawUi for AddMovieUi {
fn accepts(route: Route) -> bool {
@@ -201,7 +201,7 @@ fn draw_add_movie_search<B: Backend>(f: &mut Frame<'_, B>, app: &mut App<'_>, ar
help: None,
},
|movie| {
let (hours, minutes) = convert_runtime(movie.runtime.as_u64().unwrap());
let (hours, minutes) = convert_runtime(movie.runtime);
let imdb_rating = movie
.ratings
.imdb
@@ -221,12 +221,12 @@ fn draw_add_movie_search<B: Backend>(f: &mut Frame<'_, B>, app: &mut App<'_>, ar
let imdb_rating = if imdb_rating == 0.0 {
String::new()
} else {
format!("{:.1}", imdb_rating)
format!("{imdb_rating:.1}")
};
let rotten_tomatoes_rating = if rotten_tomatoes_rating == 0 {
String::new()
} else {
format!("{}%", rotten_tomatoes_rating)
format!("{rotten_tomatoes_rating}%")
};
let in_library = if app
.data
@@ -250,8 +250,8 @@ fn draw_add_movie_search<B: Backend>(f: &mut Frame<'_, B>, app: &mut App<'_>, ar
Row::new(vec![
Cell::from(in_library),
Cell::from(movie.title.to_string()),
Cell::from(movie.year.as_u64().unwrap().to_string()),
Cell::from(format!("{}h {}m", hours, minutes)),
Cell::from(movie.year.to_string()),
Cell::from(format!("{hours}h {minutes}m")),
Cell::from(imdb_rating),
Cell::from(rotten_tomatoes_rating),
Cell::from(movie.genres.join(", ")),
@@ -368,7 +368,7 @@ fn draw_confirmation_prompt<B: Backend>(
.clone(),
)
};
let title = format!("Add Movie - {}", movie_title);
let title = format!("Add Movie - {movie_title}");
let prompt = movie_overview;
let yes_no_value = app.data.radarr_data.prompt_confirm;
let selected_block = app.data.radarr_data.selected_block.get_active_block();
+1 -1
View File
@@ -12,7 +12,7 @@ use crate::ui::{draw_prompt_box_with_checkboxes, draw_prompt_popup_over, DrawUi}
#[path = "delete_movie_ui_tests.rs"]
mod delete_movie_ui_tests;
pub(super) struct DeleteMovieUi {}
pub(super) struct DeleteMovieUi;
impl DrawUi for DeleteMovieUi {
fn accepts(route: Route) -> bool {
+2 -2
View File
@@ -25,7 +25,7 @@ use crate::ui::{
#[path = "edit_movie_ui_tests.rs"]
mod edit_movie_ui_tests;
pub(super) struct EditMovieUi {}
pub(super) struct EditMovieUi;
impl DrawUi for EditMovieUi {
fn accepts(route: Route) -> bool {
@@ -118,7 +118,7 @@ fn draw_edit_movie_confirmation_prompt<B: Backend>(
.clone(),
)
};
let title = format!("Edit - {}", movie_title);
let title = format!("Edit - {movie_title}");
let yes_no_value = app.data.radarr_data.prompt_confirm;
let selected_block = app.data.radarr_data.selected_block.get_active_block();
let highlight_yes_no = selected_block == &ActiveRadarrBlock::EditMovieConfirmPrompt;
+8 -8
View File
@@ -28,7 +28,7 @@ mod movie_details_ui;
#[path = "library_ui_tests.rs"]
mod library_ui_tests;
pub(super) struct LibraryUi {}
pub(super) struct LibraryUi;
impl DrawUi for LibraryUi {
fn accepts(route: Route) -> bool {
@@ -168,11 +168,11 @@ pub(super) fn draw_library<B: Backend>(f: &mut Frame<'_, B>, app: &mut App<'_>,
app.tick_count % app.ticks_until_scroll == 0,
);
let monitored = if movie.monitored { "🏷" } else { "" };
let (hours, minutes) = convert_runtime(movie.runtime.as_u64().unwrap());
let file_size: f64 = convert_to_gb(movie.size_on_disk.as_u64().unwrap());
let certification = movie.certification.clone().unwrap_or_else(|| "".to_owned());
let (hours, minutes) = convert_runtime(movie.runtime);
let file_size: f64 = convert_to_gb(movie.size_on_disk);
let certification = movie.certification.clone().unwrap_or_default();
let quality_profile = quality_profile_map
.get_by_left(&movie.quality_profile_id.as_u64().unwrap())
.get_by_left(&movie.quality_profile_id)
.unwrap()
.to_owned();
let tags = movie
@@ -180,7 +180,7 @@ pub(super) fn draw_library<B: Backend>(f: &mut Frame<'_, B>, app: &mut App<'_>,
.iter()
.map(|tag_id| {
tags_map
.get_by_left(&tag_id.as_u64().unwrap())
.get_by_left(&tag_id.as_i64().unwrap())
.unwrap()
.clone()
})
@@ -191,10 +191,10 @@ pub(super) fn draw_library<B: Backend>(f: &mut Frame<'_, B>, app: &mut App<'_>,
Cell::from(movie.title.to_string()),
Cell::from(movie.year.to_string()),
Cell::from(movie.studio.to_string()),
Cell::from(format!("{}h {}m", hours, minutes)),
Cell::from(format!("{hours}h {minutes}m")),
Cell::from(certification),
Cell::from(movie.original_language.name.to_owned()),
Cell::from(format!("{:.2} GB", file_size)),
Cell::from(format!("{file_size:.2} GB")),
Cell::from(quality_profile),
Cell::from(monitored.to_owned()),
Cell::from(tags),
+6 -6
View File
@@ -28,7 +28,7 @@ use crate::utils::convert_to_gb;
#[path = "movie_details_ui_tests.rs"]
mod movie_details_ui_tests;
pub(super) struct MovieDetailsUi {}
pub(super) struct MovieDetailsUi;
impl DrawUi for MovieDetailsUi {
fn accepts(route: Route) -> bool {
@@ -504,21 +504,21 @@ fn draw_movie_releases<B: Backend>(f: &mut Frame<'_, B>, app: &mut App<'_>, cont
quality,
..
} = release;
let age = format!("{} days", age.as_u64().unwrap_or(0));
let age = format!("{age} days");
title.scroll_left_or_reset(
get_width_from_percentage(content_area, 30),
current_selection == *release
&& current_route != ActiveRadarrBlock::ManualSearchConfirmPrompt.into(),
app.tick_count % app.ticks_until_scroll == 0,
);
let size = convert_to_gb(size.as_u64().unwrap());
let size = convert_to_gb(*size);
let rejected_str = if *rejected { "" } else { "" };
let peers = if seeders.is_none() || leechers.is_none() {
Text::default()
} else {
let seeders = seeders.clone().unwrap().as_u64().unwrap();
let leechers = leechers.clone().unwrap().as_u64().unwrap();
let mut text = Text::from(format!("{} / {}", seeders, leechers));
let mut text = Text::from(format!("{seeders} / {leechers}"));
text.patch_style(determine_peer_style(seeders, leechers));
text
@@ -537,7 +537,7 @@ fn draw_movie_releases<B: Backend>(f: &mut Frame<'_, B>, app: &mut App<'_>, cont
Cell::from(rejected_str),
Cell::from(title.to_string()),
Cell::from(indexer.clone()),
Cell::from(format!("{:.1} GB", size)),
Cell::from(format!("{size:.1} GB")),
Cell::from(peers),
Cell::from(language),
Cell::from(quality),
@@ -589,7 +589,7 @@ fn draw_manual_search_confirm_prompt<B: Backend>(
.clone()
.unwrap_or_default()
.iter()
.map(|item| Line::from(vec![Span::styled(format!("{}", item), style_primary())]))
.map(|item| Line::from(vec![Span::styled(format!("{item}"), style_primary())]))
.collect::<Vec<Line<'_>>>();
lines_vec.append(&mut rejections_spans);