Refactored unnecessary data fields into Options to make the code cleaner, and to reduce the memory usage of the application
This commit is contained in:
@@ -80,15 +80,12 @@ pub fn draw_collection_details<B: Backend>(
|
||||
content_area,
|
||||
1,
|
||||
);
|
||||
let collection_selection = if !app.data.radarr_data.filtered_collections.items.is_empty() {
|
||||
app
|
||||
.data
|
||||
.radarr_data
|
||||
.filtered_collections
|
||||
.current_selection()
|
||||
} else {
|
||||
app.data.radarr_data.collections.current_selection()
|
||||
};
|
||||
let collection_selection =
|
||||
if let Some(filtered_collections) = app.data.radarr_data.filtered_collections.as_ref() {
|
||||
filtered_collections.current_selection()
|
||||
} else {
|
||||
app.data.radarr_data.collections.current_selection()
|
||||
};
|
||||
let quality_profile = app
|
||||
.data
|
||||
.radarr_data
|
||||
@@ -161,7 +158,8 @@ pub fn draw_collection_details<B: Backend>(
|
||||
chunks[1],
|
||||
layout_block_top_border_with_title(title_style("Movies")),
|
||||
TableProps {
|
||||
content: &mut app.data.radarr_data.collection_movies,
|
||||
content: Some(&mut app.data.radarr_data.collection_movies),
|
||||
wrapped_content: None,
|
||||
table_headers: vec![
|
||||
"✔",
|
||||
"Title",
|
||||
|
||||
@@ -97,20 +97,10 @@ fn draw_edit_collection_confirmation_prompt<B: Backend>(
|
||||
prompt_area: Rect,
|
||||
) {
|
||||
let (collection_title, collection_overview) =
|
||||
if app.data.radarr_data.filtered_collections.items.is_empty() {
|
||||
if let Some(filtered_collections) = app.data.radarr_data.filtered_collections.as_ref() {
|
||||
(
|
||||
app
|
||||
.data
|
||||
.radarr_data
|
||||
.collections
|
||||
.current_selection()
|
||||
.title
|
||||
.text
|
||||
.clone(),
|
||||
app
|
||||
.data
|
||||
.radarr_data
|
||||
.collections
|
||||
filtered_collections.current_selection().title.text.clone(),
|
||||
filtered_collections
|
||||
.current_selection()
|
||||
.overview
|
||||
.clone()
|
||||
@@ -121,7 +111,7 @@ fn draw_edit_collection_confirmation_prompt<B: Backend>(
|
||||
app
|
||||
.data
|
||||
.radarr_data
|
||||
.filtered_collections
|
||||
.collections
|
||||
.current_selection()
|
||||
.title
|
||||
.text
|
||||
@@ -129,7 +119,7 @@ fn draw_edit_collection_confirmation_prompt<B: Backend>(
|
||||
app
|
||||
.data
|
||||
.radarr_data
|
||||
.filtered_collections
|
||||
.collections
|
||||
.current_selection()
|
||||
.overview
|
||||
.clone()
|
||||
|
||||
@@ -100,25 +100,18 @@ impl DrawUi for CollectionsUi {
|
||||
}
|
||||
|
||||
pub(super) fn draw_collections<B: Backend>(f: &mut Frame<'_, B>, app: &mut App<'_>, area: Rect) {
|
||||
let current_selection = if !app.data.radarr_data.filtered_collections.items.is_empty() {
|
||||
app
|
||||
.data
|
||||
.radarr_data
|
||||
.filtered_collections
|
||||
.current_selection()
|
||||
.clone()
|
||||
} else if !app.data.radarr_data.collections.items.is_empty() {
|
||||
app.data.radarr_data.collections.current_selection().clone()
|
||||
} else {
|
||||
Collection::default()
|
||||
};
|
||||
let current_selection =
|
||||
if let Some(filtered_collections) = app.data.radarr_data.filtered_collections.as_ref() {
|
||||
filtered_collections.current_selection().clone()
|
||||
} else if !app.data.radarr_data.collections.items.is_empty() {
|
||||
app.data.radarr_data.collections.current_selection().clone()
|
||||
} else {
|
||||
Collection::default()
|
||||
};
|
||||
let quality_profile_map = &app.data.radarr_data.quality_profile_map;
|
||||
let content = if !app.data.radarr_data.filtered_collections.items.is_empty()
|
||||
&& !app.data.radarr_data.is_filtering
|
||||
{
|
||||
&mut app.data.radarr_data.filtered_collections
|
||||
} else {
|
||||
&mut app.data.radarr_data.collections
|
||||
let content = match app.data.radarr_data.filtered_collections.as_mut() {
|
||||
Some(filtered_collections) if !app.data.radarr_data.is_filtering => Some(filtered_collections),
|
||||
_ => Some(&mut app.data.radarr_data.collections),
|
||||
};
|
||||
draw_table(
|
||||
f,
|
||||
@@ -126,6 +119,7 @@ pub(super) fn draw_collections<B: Backend>(f: &mut Frame<'_, B>, app: &mut App<'
|
||||
layout_block_top_border(),
|
||||
TableProps {
|
||||
content,
|
||||
wrapped_content: None,
|
||||
table_headers: vec![
|
||||
"Collection",
|
||||
"Number of Movies",
|
||||
|
||||
@@ -62,7 +62,8 @@ fn draw_downloads<B: Backend>(f: &mut Frame<'_, B>, app: &mut App<'_>, area: Rec
|
||||
area,
|
||||
layout_block_top_border(),
|
||||
TableProps {
|
||||
content: &mut app.data.radarr_data.downloads,
|
||||
content: Some(&mut app.data.radarr_data.downloads),
|
||||
wrapped_content: None,
|
||||
table_headers: vec![
|
||||
"Title",
|
||||
"Percent Complete",
|
||||
|
||||
@@ -59,7 +59,8 @@ fn draw_indexers<B: Backend>(f: &mut Frame<'_, B>, app: &mut App<'_>, area: Rect
|
||||
area,
|
||||
layout_block_top_border(),
|
||||
TableProps {
|
||||
content: &mut app.data.radarr_data.indexers,
|
||||
content: Some(&mut app.data.radarr_data.indexers),
|
||||
wrapped_content: None,
|
||||
table_headers: vec![
|
||||
"Indexer",
|
||||
"RSS",
|
||||
|
||||
@@ -104,16 +104,13 @@ impl DrawUi for AddMovieUi {
|
||||
}
|
||||
|
||||
fn draw_add_movie_search<B: Backend>(f: &mut Frame<'_, B>, app: &mut App<'_>, area: Rect) {
|
||||
let current_selection = if app.data.radarr_data.add_searched_movies.items.is_empty() {
|
||||
AddMovieSearchResult::default()
|
||||
} else {
|
||||
app
|
||||
.data
|
||||
.radarr_data
|
||||
.add_searched_movies
|
||||
.current_selection()
|
||||
.clone()
|
||||
};
|
||||
let is_loading = app.is_loading || app.data.radarr_data.add_searched_movies.is_none();
|
||||
let current_selection =
|
||||
if let Some(add_searched_movies) = app.data.radarr_data.add_searched_movies.as_ref() {
|
||||
add_searched_movies.current_selection().clone()
|
||||
} else {
|
||||
AddMovieSearchResult::default()
|
||||
};
|
||||
|
||||
let chunks = vertical_chunks_with_margin(
|
||||
vec![
|
||||
@@ -181,7 +178,8 @@ fn draw_add_movie_search<B: Backend>(f: &mut Frame<'_, B>, app: &mut App<'_>, ar
|
||||
chunks[1],
|
||||
layout_block(),
|
||||
TableProps {
|
||||
content: &mut app.data.radarr_data.add_searched_movies,
|
||||
content: None,
|
||||
wrapped_content: Some(app.data.radarr_data.add_searched_movies.as_mut()),
|
||||
table_headers: vec![
|
||||
"✔",
|
||||
"Title",
|
||||
@@ -260,7 +258,7 @@ fn draw_add_movie_search<B: Backend>(f: &mut Frame<'_, B>, app: &mut App<'_>, ar
|
||||
])
|
||||
.style(style_primary())
|
||||
},
|
||||
app.is_loading,
|
||||
is_loading,
|
||||
true,
|
||||
);
|
||||
}
|
||||
@@ -354,6 +352,8 @@ fn draw_confirmation_prompt<B: Backend>(
|
||||
.data
|
||||
.radarr_data
|
||||
.add_searched_movies
|
||||
.as_ref()
|
||||
.unwrap()
|
||||
.current_selection()
|
||||
.title
|
||||
.text,
|
||||
@@ -361,6 +361,8 @@ fn draw_confirmation_prompt<B: Backend>(
|
||||
.data
|
||||
.radarr_data
|
||||
.add_searched_movies
|
||||
.as_ref()
|
||||
.unwrap()
|
||||
.current_selection()
|
||||
.overview
|
||||
.clone(),
|
||||
|
||||
@@ -93,43 +93,31 @@ fn draw_edit_movie_confirmation_prompt<B: Backend>(
|
||||
app: &mut App<'_>,
|
||||
prompt_area: Rect,
|
||||
) {
|
||||
let (movie_title, movie_overview) = if app.data.radarr_data.filtered_movies.items.is_empty() {
|
||||
(
|
||||
app
|
||||
.data
|
||||
.radarr_data
|
||||
.movies
|
||||
.current_selection()
|
||||
.title
|
||||
.text
|
||||
.clone(),
|
||||
app
|
||||
.data
|
||||
.radarr_data
|
||||
.movies
|
||||
.current_selection()
|
||||
.overview
|
||||
.clone(),
|
||||
)
|
||||
} else {
|
||||
(
|
||||
app
|
||||
.data
|
||||
.radarr_data
|
||||
.filtered_movies
|
||||
.current_selection()
|
||||
.title
|
||||
.text
|
||||
.clone(),
|
||||
app
|
||||
.data
|
||||
.radarr_data
|
||||
.filtered_movies
|
||||
.current_selection()
|
||||
.overview
|
||||
.clone(),
|
||||
)
|
||||
};
|
||||
let (movie_title, movie_overview) =
|
||||
if let Some(filtered_movies) = app.data.radarr_data.filtered_movies.as_ref() {
|
||||
(
|
||||
filtered_movies.current_selection().title.text.clone(),
|
||||
filtered_movies.current_selection().overview.clone(),
|
||||
)
|
||||
} else {
|
||||
(
|
||||
app
|
||||
.data
|
||||
.radarr_data
|
||||
.movies
|
||||
.current_selection()
|
||||
.title
|
||||
.text
|
||||
.clone(),
|
||||
app
|
||||
.data
|
||||
.radarr_data
|
||||
.movies
|
||||
.current_selection()
|
||||
.overview
|
||||
.clone(),
|
||||
)
|
||||
};
|
||||
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();
|
||||
|
||||
@@ -108,27 +108,20 @@ impl DrawUi for LibraryUi {
|
||||
}
|
||||
|
||||
pub(super) fn draw_library<B: Backend>(f: &mut Frame<'_, B>, app: &mut App<'_>, area: Rect) {
|
||||
let current_selection = if !app.data.radarr_data.filtered_movies.items.is_empty() {
|
||||
app
|
||||
.data
|
||||
.radarr_data
|
||||
.filtered_movies
|
||||
.current_selection()
|
||||
.clone()
|
||||
} else if !app.data.radarr_data.movies.items.is_empty() {
|
||||
app.data.radarr_data.movies.current_selection().clone()
|
||||
} else {
|
||||
Movie::default()
|
||||
};
|
||||
let current_selection =
|
||||
if let Some(filtered_movies) = app.data.radarr_data.filtered_movies.as_ref() {
|
||||
filtered_movies.current_selection().clone()
|
||||
} else if !app.data.radarr_data.movies.items.is_empty() {
|
||||
app.data.radarr_data.movies.current_selection().clone()
|
||||
} else {
|
||||
Movie::default()
|
||||
};
|
||||
let quality_profile_map = &app.data.radarr_data.quality_profile_map;
|
||||
let tags_map = &app.data.radarr_data.tags_map;
|
||||
let downloads_vec = &app.data.radarr_data.downloads.items;
|
||||
let content = if !app.data.radarr_data.filtered_movies.items.is_empty()
|
||||
&& !app.data.radarr_data.is_filtering
|
||||
{
|
||||
&mut app.data.radarr_data.filtered_movies
|
||||
} else {
|
||||
&mut app.data.radarr_data.movies
|
||||
let content = match app.data.radarr_data.filtered_movies.as_mut() {
|
||||
Some(filtered_movies) if !app.data.radarr_data.is_filtering => Some(filtered_movies),
|
||||
_ => Some(&mut app.data.radarr_data.movies),
|
||||
};
|
||||
|
||||
draw_table(
|
||||
@@ -137,6 +130,7 @@ pub(super) fn draw_library<B: Backend>(f: &mut Frame<'_, B>, app: &mut App<'_>,
|
||||
layout_block_top_border(),
|
||||
TableProps {
|
||||
content,
|
||||
wrapped_content: None,
|
||||
table_headers: vec![
|
||||
"Title",
|
||||
"Year",
|
||||
|
||||
@@ -269,7 +269,8 @@ fn draw_movie_history<B: Backend>(f: &mut Frame<'_, B>, app: &mut App<'_>, conte
|
||||
content_area,
|
||||
layout_block_top_border(),
|
||||
TableProps {
|
||||
content: &mut movie_details_modal.movie_history,
|
||||
content: Some(&mut movie_details_modal.movie_history),
|
||||
wrapped_content: None,
|
||||
table_headers: vec!["Source Title", "Event Type", "Languages", "Quality", "Date"],
|
||||
constraints: vec![
|
||||
Constraint::Percentage(34),
|
||||
@@ -326,13 +327,16 @@ fn draw_movie_cast<B: Backend>(f: &mut Frame<'_, B>, app: &mut App<'_>, content_
|
||||
content_area,
|
||||
layout_block_top_border(),
|
||||
TableProps {
|
||||
content: &mut app
|
||||
.data
|
||||
.radarr_data
|
||||
.movie_details_modal
|
||||
.as_mut()
|
||||
.unwrap()
|
||||
.movie_cast,
|
||||
content: Some(
|
||||
&mut app
|
||||
.data
|
||||
.radarr_data
|
||||
.movie_details_modal
|
||||
.as_mut()
|
||||
.unwrap()
|
||||
.movie_cast,
|
||||
),
|
||||
wrapped_content: None,
|
||||
constraints: iter::repeat(Constraint::Ratio(1, 2)).take(2).collect(),
|
||||
table_headers: vec!["Cast Member", "Character"],
|
||||
help: app
|
||||
@@ -365,13 +369,16 @@ fn draw_movie_crew<B: Backend>(f: &mut Frame<'_, B>, app: &mut App<'_>, content_
|
||||
content_area,
|
||||
layout_block_top_border(),
|
||||
TableProps {
|
||||
content: &mut app
|
||||
.data
|
||||
.radarr_data
|
||||
.movie_details_modal
|
||||
.as_mut()
|
||||
.unwrap()
|
||||
.movie_crew,
|
||||
content: Some(
|
||||
&mut app
|
||||
.data
|
||||
.radarr_data
|
||||
.movie_details_modal
|
||||
.as_mut()
|
||||
.unwrap()
|
||||
.movie_crew,
|
||||
),
|
||||
wrapped_content: None,
|
||||
constraints: iter::repeat(Constraint::Ratio(1, 3)).take(3).collect(),
|
||||
table_headers: vec!["Crew Member", "Job", "Department"],
|
||||
help: app
|
||||
@@ -455,13 +462,16 @@ fn draw_movie_releases<B: Backend>(f: &mut Frame<'_, B>, app: &mut App<'_>, cont
|
||||
content_area,
|
||||
layout_block_top_border(),
|
||||
TableProps {
|
||||
content: &mut app
|
||||
.data
|
||||
.radarr_data
|
||||
.movie_details_modal
|
||||
.as_mut()
|
||||
.unwrap()
|
||||
.movie_releases,
|
||||
content: Some(
|
||||
&mut app
|
||||
.data
|
||||
.radarr_data
|
||||
.movie_details_modal
|
||||
.as_mut()
|
||||
.unwrap()
|
||||
.movie_releases,
|
||||
),
|
||||
wrapped_content: None,
|
||||
constraints: vec![
|
||||
Constraint::Length(9),
|
||||
Constraint::Length(10),
|
||||
|
||||
@@ -61,7 +61,8 @@ fn draw_root_folders<B: Backend>(f: &mut Frame<'_, B>, app: &mut App<'_>, area:
|
||||
area,
|
||||
layout_block_top_border(),
|
||||
TableProps {
|
||||
content: &mut app.data.radarr_data.root_folders,
|
||||
content: Some(&mut app.data.radarr_data.root_folders),
|
||||
wrapped_content: None,
|
||||
table_headers: vec!["Path", "Free Space", "Unmapped Folders"],
|
||||
constraints: vec![
|
||||
Constraint::Percentage(60),
|
||||
|
||||
@@ -106,7 +106,8 @@ fn draw_tasks<B: Backend>(f: &mut Frame<'_, B>, app: &mut App<'_>, area: Rect) {
|
||||
area,
|
||||
title_block("Tasks"),
|
||||
TableProps {
|
||||
content: &mut app.data.radarr_data.tasks,
|
||||
content: Some(&mut app.data.radarr_data.tasks),
|
||||
wrapped_content: None,
|
||||
table_headers: TASK_TABLE_HEADERS.to_vec(),
|
||||
constraints: TASK_TABLE_CONSTRAINTS.to_vec(),
|
||||
help: None,
|
||||
@@ -134,7 +135,8 @@ pub(super) fn draw_queued_events<B: Backend>(f: &mut Frame<'_, B>, app: &mut App
|
||||
area,
|
||||
title_block("Queued Events"),
|
||||
TableProps {
|
||||
content: &mut app.data.radarr_data.queued_events,
|
||||
content: Some(&mut app.data.radarr_data.queued_events),
|
||||
wrapped_content: None,
|
||||
table_headers: vec!["Trigger", "Status", "Name", "Queued", "Started", "Duration"],
|
||||
constraints: vec![
|
||||
Constraint::Percentage(13),
|
||||
|
||||
@@ -109,7 +109,8 @@ fn draw_tasks_popup<B: Backend>(f: &mut Frame<'_, B>, app: &mut App<'_>, area: R
|
||||
context_area,
|
||||
borderless_block(),
|
||||
TableProps {
|
||||
content: &mut app.data.radarr_data.tasks,
|
||||
content: Some(&mut app.data.radarr_data.tasks),
|
||||
wrapped_content: None,
|
||||
table_headers: TASK_TABLE_HEADERS.to_vec(),
|
||||
constraints: TASK_TABLE_CONSTRAINTS.to_vec(),
|
||||
help: None,
|
||||
|
||||
Reference in New Issue
Block a user