refactor: Reduced the number of clones necessary when building modal structs
This commit is contained in:
@@ -22,6 +22,13 @@ pub(super) struct EditCollectionHandler<'a, 'b> {
|
||||
|
||||
impl<'a, 'b> EditCollectionHandler<'a, 'b> {
|
||||
fn build_edit_collection_params(&mut self) -> EditCollectionParams {
|
||||
let edit_collection_modal = self
|
||||
.app
|
||||
.data
|
||||
.radarr_data
|
||||
.edit_collection_modal
|
||||
.take()
|
||||
.expect("EditCollectionModal is None");
|
||||
let collection_id = self.app.data.radarr_data.collections.current_selection().id;
|
||||
let EditCollectionModal {
|
||||
path,
|
||||
@@ -29,13 +36,7 @@ impl<'a, 'b> EditCollectionHandler<'a, 'b> {
|
||||
minimum_availability_list,
|
||||
monitored,
|
||||
quality_profile_list,
|
||||
} = self
|
||||
.app
|
||||
.data
|
||||
.radarr_data
|
||||
.edit_collection_modal
|
||||
.as_ref()
|
||||
.unwrap();
|
||||
} = edit_collection_modal;
|
||||
let quality_profile = quality_profile_list.current_selection();
|
||||
let quality_profile_id = *self
|
||||
.app
|
||||
@@ -48,15 +49,13 @@ impl<'a, 'b> EditCollectionHandler<'a, 'b> {
|
||||
.next()
|
||||
.unwrap();
|
||||
|
||||
let root_folder_path: String = path.text.clone();
|
||||
let monitored = monitored.unwrap_or_default();
|
||||
let root_folder_path = path.text;
|
||||
let search_on_add = search_on_add.unwrap_or_default();
|
||||
let minimum_availability = *minimum_availability_list.current_selection();
|
||||
self.app.data.radarr_data.edit_collection_modal = None;
|
||||
|
||||
EditCollectionParams {
|
||||
collection_id,
|
||||
monitored: Some(monitored),
|
||||
monitored,
|
||||
minimum_availability: Some(minimum_availability),
|
||||
quality_profile_id: Some(quality_profile_id),
|
||||
root_folder_path: Some(root_folder_path),
|
||||
|
||||
@@ -21,56 +21,42 @@ pub(super) struct EditIndexerHandler<'a, 'b> {
|
||||
|
||||
impl<'a, 'b> EditIndexerHandler<'a, 'b> {
|
||||
fn build_edit_indexer_params(&mut self) -> EditIndexerParams {
|
||||
let indexer_id = self.app.data.radarr_data.indexers.current_selection().id;
|
||||
let tags = self
|
||||
let edit_indexer_modal = self
|
||||
.app
|
||||
.data
|
||||
.radarr_data
|
||||
.edit_indexer_modal
|
||||
.as_ref()
|
||||
.unwrap()
|
||||
.tags
|
||||
.text
|
||||
.clone();
|
||||
.take()
|
||||
.expect("Edit Indexer Modal is None");
|
||||
let indexer_id = self.app.data.radarr_data.indexers.current_selection().id;
|
||||
let tags = edit_indexer_modal.tags.text;
|
||||
|
||||
let params = {
|
||||
let EditIndexerModal {
|
||||
name,
|
||||
enable_rss,
|
||||
enable_automatic_search,
|
||||
enable_interactive_search,
|
||||
url,
|
||||
api_key,
|
||||
seed_ratio,
|
||||
priority,
|
||||
..
|
||||
} = self
|
||||
.app
|
||||
.data
|
||||
.radarr_data
|
||||
.edit_indexer_modal
|
||||
.as_ref()
|
||||
.unwrap();
|
||||
let EditIndexerModal {
|
||||
name,
|
||||
enable_rss,
|
||||
enable_automatic_search,
|
||||
enable_interactive_search,
|
||||
url,
|
||||
api_key,
|
||||
seed_ratio,
|
||||
priority,
|
||||
..
|
||||
} = edit_indexer_modal;
|
||||
|
||||
EditIndexerParams {
|
||||
indexer_id,
|
||||
name: Some(name.text.clone()),
|
||||
enable_rss: Some(enable_rss.unwrap_or_default()),
|
||||
enable_automatic_search: Some(enable_automatic_search.unwrap_or_default()),
|
||||
enable_interactive_search: Some(enable_interactive_search.unwrap_or_default()),
|
||||
url: Some(url.text.clone()),
|
||||
api_key: Some(api_key.text.clone()),
|
||||
seed_ratio: Some(seed_ratio.text.clone()),
|
||||
tags: None,
|
||||
tag_input_string: Some(tags),
|
||||
priority: Some(*priority),
|
||||
clear_tags: false,
|
||||
}
|
||||
};
|
||||
|
||||
self.app.data.radarr_data.edit_indexer_modal = None;
|
||||
|
||||
params
|
||||
EditIndexerParams {
|
||||
indexer_id,
|
||||
name: Some(name.text),
|
||||
enable_rss: Some(enable_rss.unwrap_or_default()),
|
||||
enable_automatic_search: Some(enable_automatic_search.unwrap_or_default()),
|
||||
enable_interactive_search: Some(enable_interactive_search.unwrap_or_default()),
|
||||
url: Some(url.text),
|
||||
api_key: Some(api_key.text),
|
||||
seed_ratio: Some(seed_ratio.text),
|
||||
tags: None,
|
||||
tag_input_string: Some(tags),
|
||||
priority: Some(priority),
|
||||
clear_tags: false,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -22,9 +22,13 @@ pub(super) struct IndexerSettingsHandler<'a, 'b> {
|
||||
|
||||
impl<'a, 'b> IndexerSettingsHandler<'a, 'b> {
|
||||
fn build_edit_indexer_settings_body(&mut self) -> IndexerSettings {
|
||||
let indexer_settings = self.app.data.radarr_data.indexer_settings.clone().unwrap();
|
||||
self.app.data.radarr_data.indexer_settings = None;
|
||||
indexer_settings
|
||||
self
|
||||
.app
|
||||
.data
|
||||
.radarr_data
|
||||
.indexer_settings
|
||||
.take()
|
||||
.expect("Indexer settings not found")
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -39,23 +39,21 @@ impl<'a, 'b> AddMovieHandler<'a, 'b> {
|
||||
);
|
||||
|
||||
fn build_add_movie_body(&mut self) -> AddMovieBody {
|
||||
let tags = self
|
||||
let add_movie_modal = self
|
||||
.app
|
||||
.data
|
||||
.radarr_data
|
||||
.add_movie_modal
|
||||
.as_ref()
|
||||
.unwrap()
|
||||
.tags
|
||||
.text
|
||||
.clone();
|
||||
.take()
|
||||
.expect("AddMovieModal is None");
|
||||
let tags = add_movie_modal.tags.text;
|
||||
let AddMovieModal {
|
||||
root_folder_list,
|
||||
monitor_list,
|
||||
minimum_availability_list,
|
||||
quality_profile_list,
|
||||
..
|
||||
} = self.app.data.radarr_data.add_movie_modal.as_ref().unwrap();
|
||||
} = add_movie_modal;
|
||||
let (tmdb_id, title) = if let Some(context) = self.context {
|
||||
if context == ActiveRadarrBlock::CollectionDetails {
|
||||
let CollectionMovie { tmdb_id, title, .. } = self
|
||||
@@ -63,9 +61,8 @@ impl<'a, 'b> AddMovieHandler<'a, 'b> {
|
||||
.data
|
||||
.radarr_data
|
||||
.collection_movies
|
||||
.current_selection()
|
||||
.clone();
|
||||
(tmdb_id, title.text)
|
||||
.current_selection();
|
||||
(*tmdb_id, title.clone().text)
|
||||
} else {
|
||||
let AddMovieSearchResult { tmdb_id, title, .. } = self
|
||||
.app
|
||||
@@ -74,9 +71,8 @@ impl<'a, 'b> AddMovieHandler<'a, 'b> {
|
||||
.add_searched_movies
|
||||
.as_ref()
|
||||
.unwrap()
|
||||
.current_selection()
|
||||
.clone();
|
||||
(tmdb_id, title.text)
|
||||
.current_selection();
|
||||
(*tmdb_id, title.clone().text)
|
||||
}
|
||||
} else {
|
||||
let AddMovieSearchResult { tmdb_id, title, .. } = self
|
||||
@@ -86,9 +82,8 @@ impl<'a, 'b> AddMovieHandler<'a, 'b> {
|
||||
.add_searched_movies
|
||||
.as_ref()
|
||||
.unwrap()
|
||||
.current_selection()
|
||||
.clone();
|
||||
(tmdb_id, title.text)
|
||||
.current_selection();
|
||||
(*tmdb_id, title.clone().text)
|
||||
};
|
||||
let quality_profile = quality_profile_list.current_selection();
|
||||
let quality_profile_id = *self
|
||||
@@ -106,8 +101,6 @@ impl<'a, 'b> AddMovieHandler<'a, 'b> {
|
||||
let monitor = monitor_list.current_selection().to_string();
|
||||
let minimum_availability = minimum_availability_list.current_selection().to_string();
|
||||
|
||||
self.app.data.radarr_data.add_movie_modal = None;
|
||||
|
||||
AddMovieBody {
|
||||
tmdb_id,
|
||||
title,
|
||||
|
||||
@@ -23,51 +23,43 @@ pub(super) struct EditMovieHandler<'a, 'b> {
|
||||
impl<'a, 'b> EditMovieHandler<'a, 'b> {
|
||||
fn build_edit_movie_params(&mut self) -> EditMovieParams {
|
||||
let movie_id = self.app.data.radarr_data.movies.current_selection().id;
|
||||
let tags = self
|
||||
let edit_movie_modal = self
|
||||
.app
|
||||
.data
|
||||
.radarr_data
|
||||
.edit_movie_modal
|
||||
.as_ref()
|
||||
.unwrap()
|
||||
.tags
|
||||
.text
|
||||
.clone();
|
||||
let params = {
|
||||
let EditMovieModal {
|
||||
monitored,
|
||||
path,
|
||||
minimum_availability_list,
|
||||
quality_profile_list,
|
||||
..
|
||||
} = self.app.data.radarr_data.edit_movie_modal.as_ref().unwrap();
|
||||
let quality_profile = quality_profile_list.current_selection();
|
||||
let quality_profile_id = *self
|
||||
.app
|
||||
.data
|
||||
.radarr_data
|
||||
.quality_profile_map
|
||||
.iter()
|
||||
.filter(|(_, value)| *value == quality_profile)
|
||||
.map(|(key, _)| key)
|
||||
.next()
|
||||
.unwrap();
|
||||
.take()
|
||||
.expect("Edit movie modal is None");
|
||||
let tags = edit_movie_modal.tags.text;
|
||||
let EditMovieModal {
|
||||
monitored,
|
||||
path,
|
||||
minimum_availability_list,
|
||||
quality_profile_list,
|
||||
..
|
||||
} = edit_movie_modal;
|
||||
let quality_profile = quality_profile_list.current_selection();
|
||||
let quality_profile_id = *self
|
||||
.app
|
||||
.data
|
||||
.radarr_data
|
||||
.quality_profile_map
|
||||
.iter()
|
||||
.filter(|(_, value)| *value == quality_profile)
|
||||
.map(|(key, _)| key)
|
||||
.next()
|
||||
.unwrap();
|
||||
|
||||
EditMovieParams {
|
||||
movie_id,
|
||||
monitored: *monitored,
|
||||
minimum_availability: Some(*minimum_availability_list.current_selection()),
|
||||
quality_profile_id: Some(quality_profile_id),
|
||||
root_folder_path: Some(path.text.clone()),
|
||||
tags: None,
|
||||
tag_input_string: Some(tags),
|
||||
clear_tags: false,
|
||||
}
|
||||
};
|
||||
|
||||
self.app.data.radarr_data.edit_movie_modal = None;
|
||||
|
||||
params
|
||||
EditMovieParams {
|
||||
movie_id,
|
||||
monitored,
|
||||
minimum_availability: Some(*minimum_availability_list.current_selection()),
|
||||
quality_profile_id: Some(quality_profile_id),
|
||||
root_folder_path: Some(path.text),
|
||||
tags: None,
|
||||
tag_input_string: Some(tags),
|
||||
clear_tags: false,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -30,19 +30,17 @@ impl<'a, 'b> RootFoldersHandler<'a, 'b> {
|
||||
);
|
||||
|
||||
fn build_add_root_folder_body(&mut self) -> AddRootFolderBody {
|
||||
let path = self
|
||||
let edit_root_folder = self
|
||||
.app
|
||||
.data
|
||||
.radarr_data
|
||||
.edit_root_folder
|
||||
.as_ref()
|
||||
.unwrap()
|
||||
.text
|
||||
.clone();
|
||||
.take()
|
||||
.expect("AddRootFolder is None");
|
||||
|
||||
self.app.data.radarr_data.edit_root_folder = None;
|
||||
|
||||
AddRootFolderBody { path }
|
||||
AddRootFolderBody {
|
||||
path: edit_root_folder.text,
|
||||
}
|
||||
}
|
||||
|
||||
fn extract_root_folder_id(&mut self) -> i64 {
|
||||
|
||||
@@ -21,55 +21,41 @@ pub(super) struct EditIndexerHandler<'a, 'b> {
|
||||
|
||||
impl<'a, 'b> EditIndexerHandler<'a, 'b> {
|
||||
fn build_edit_indexer_params(&mut self) -> EditIndexerParams {
|
||||
let indexer_id = self.app.data.sonarr_data.indexers.current_selection().id;
|
||||
let tags = self
|
||||
let edit_indexer_modal = self
|
||||
.app
|
||||
.data
|
||||
.sonarr_data
|
||||
.edit_indexer_modal
|
||||
.as_ref()
|
||||
.unwrap()
|
||||
.tags
|
||||
.text
|
||||
.clone();
|
||||
let params = {
|
||||
let EditIndexerModal {
|
||||
name,
|
||||
enable_rss,
|
||||
enable_automatic_search,
|
||||
enable_interactive_search,
|
||||
url,
|
||||
api_key,
|
||||
seed_ratio,
|
||||
priority,
|
||||
..
|
||||
} = self
|
||||
.app
|
||||
.data
|
||||
.sonarr_data
|
||||
.edit_indexer_modal
|
||||
.as_ref()
|
||||
.unwrap();
|
||||
.take()
|
||||
.expect("EditIndexerModal is None");
|
||||
let indexer_id = self.app.data.sonarr_data.indexers.current_selection().id;
|
||||
let tags = edit_indexer_modal.tags.text;
|
||||
let EditIndexerModal {
|
||||
name,
|
||||
enable_rss,
|
||||
enable_automatic_search,
|
||||
enable_interactive_search,
|
||||
url,
|
||||
api_key,
|
||||
seed_ratio,
|
||||
priority,
|
||||
..
|
||||
} = edit_indexer_modal;
|
||||
|
||||
EditIndexerParams {
|
||||
indexer_id,
|
||||
name: Some(name.text.clone()),
|
||||
enable_rss: Some(enable_rss.unwrap_or_default()),
|
||||
enable_automatic_search: Some(enable_automatic_search.unwrap_or_default()),
|
||||
enable_interactive_search: Some(enable_interactive_search.unwrap_or_default()),
|
||||
url: Some(url.text.clone()),
|
||||
api_key: Some(api_key.text.clone()),
|
||||
seed_ratio: Some(seed_ratio.text.clone()),
|
||||
tags: None,
|
||||
tag_input_string: Some(tags),
|
||||
priority: Some(*priority),
|
||||
clear_tags: false,
|
||||
}
|
||||
};
|
||||
|
||||
self.app.data.sonarr_data.edit_indexer_modal = None;
|
||||
|
||||
params
|
||||
EditIndexerParams {
|
||||
indexer_id,
|
||||
name: Some(name.text),
|
||||
enable_rss,
|
||||
enable_automatic_search,
|
||||
enable_interactive_search,
|
||||
url: Some(url.text),
|
||||
api_key: Some(api_key.text),
|
||||
seed_ratio: Some(seed_ratio.text),
|
||||
tags: None,
|
||||
tag_input_string: Some(tags),
|
||||
priority: Some(priority),
|
||||
clear_tags: false,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -22,18 +22,13 @@ pub(super) struct IndexerSettingsHandler<'a, 'b> {
|
||||
|
||||
impl<'a, 'b> IndexerSettingsHandler<'a, 'b> {
|
||||
fn build_edit_indexer_settings_params(&mut self) -> IndexerSettings {
|
||||
let indexer_settings = self
|
||||
self
|
||||
.app
|
||||
.data
|
||||
.sonarr_data
|
||||
.indexer_settings
|
||||
.as_ref()
|
||||
.unwrap()
|
||||
.clone();
|
||||
|
||||
self.app.data.sonarr_data.indexer_settings = None;
|
||||
|
||||
indexer_settings
|
||||
.take()
|
||||
.expect("IndexerSettings is None")
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -37,16 +37,14 @@ impl<'a, 'b> AddSeriesHandler<'a, 'b> {
|
||||
);
|
||||
|
||||
fn build_add_series_body(&mut self) -> AddSeriesBody {
|
||||
let tags = self
|
||||
let add_series_modal = self
|
||||
.app
|
||||
.data
|
||||
.sonarr_data
|
||||
.add_series_modal
|
||||
.as_ref()
|
||||
.unwrap()
|
||||
.tags
|
||||
.text
|
||||
.clone();
|
||||
.take()
|
||||
.expect("AddSeriesModal is None");
|
||||
let tags = add_series_modal.tags.text;
|
||||
let AddSeriesModal {
|
||||
root_folder_list,
|
||||
monitor_list,
|
||||
@@ -55,8 +53,7 @@ impl<'a, 'b> AddSeriesHandler<'a, 'b> {
|
||||
series_type_list,
|
||||
use_season_folder,
|
||||
..
|
||||
} = self.app.data.sonarr_data.add_series_modal.as_ref().unwrap();
|
||||
let season_folder = *use_season_folder;
|
||||
} = add_series_modal;
|
||||
let (tvdb_id, title) = {
|
||||
let AddSeriesSearchResult { tvdb_id, title, .. } = self
|
||||
.app
|
||||
@@ -65,9 +62,8 @@ impl<'a, 'b> AddSeriesHandler<'a, 'b> {
|
||||
.add_searched_series
|
||||
.as_ref()
|
||||
.unwrap()
|
||||
.current_selection()
|
||||
.clone();
|
||||
(tvdb_id, title.text)
|
||||
.current_selection();
|
||||
(*tvdb_id, title.clone().text)
|
||||
};
|
||||
let quality_profile = quality_profile_list.current_selection();
|
||||
let quality_profile_id = *self
|
||||
@@ -96,8 +92,6 @@ impl<'a, 'b> AddSeriesHandler<'a, 'b> {
|
||||
let monitor = monitor_list.current_selection().to_string();
|
||||
let series_type = series_type_list.current_selection().to_string();
|
||||
|
||||
self.app.data.sonarr_data.add_series_modal = None;
|
||||
|
||||
AddSeriesBody {
|
||||
tvdb_id,
|
||||
title,
|
||||
@@ -106,7 +100,7 @@ impl<'a, 'b> AddSeriesHandler<'a, 'b> {
|
||||
quality_profile_id,
|
||||
language_profile_id,
|
||||
series_type,
|
||||
season_folder,
|
||||
season_folder: use_season_folder,
|
||||
tags: Vec::new(),
|
||||
tag_input_string: Some(tags),
|
||||
add_options: AddSeriesOptions {
|
||||
|
||||
@@ -22,73 +22,59 @@ pub(super) struct EditSeriesHandler<'a, 'b> {
|
||||
|
||||
impl<'a, 'b> EditSeriesHandler<'a, 'b> {
|
||||
fn build_edit_series_params(&mut self) -> EditSeriesParams {
|
||||
let series_id = self.app.data.sonarr_data.series.current_selection().id;
|
||||
let tags = self
|
||||
let edit_series_modal = self
|
||||
.app
|
||||
.data
|
||||
.sonarr_data
|
||||
.edit_series_modal
|
||||
.as_ref()
|
||||
.unwrap()
|
||||
.tags
|
||||
.text
|
||||
.clone();
|
||||
.take()
|
||||
.expect("EditSeriesModal is None");
|
||||
let series_id = self.app.data.sonarr_data.series.current_selection().id;
|
||||
let tags = edit_series_modal.tags.text;
|
||||
|
||||
let params = {
|
||||
let EditSeriesModal {
|
||||
monitored,
|
||||
use_season_folders,
|
||||
path,
|
||||
series_type_list,
|
||||
quality_profile_list,
|
||||
language_profile_list,
|
||||
..
|
||||
} = self
|
||||
.app
|
||||
.data
|
||||
.sonarr_data
|
||||
.edit_series_modal
|
||||
.as_ref()
|
||||
.unwrap();
|
||||
let quality_profile = quality_profile_list.current_selection();
|
||||
let quality_profile_id = *self
|
||||
.app
|
||||
.data
|
||||
.sonarr_data
|
||||
.quality_profile_map
|
||||
.iter()
|
||||
.filter(|(_, value)| *value == quality_profile)
|
||||
.map(|(key, _)| key)
|
||||
.next()
|
||||
.unwrap();
|
||||
let language_profile = language_profile_list.current_selection();
|
||||
let language_profile_id = *self
|
||||
.app
|
||||
.data
|
||||
.sonarr_data
|
||||
.language_profiles_map
|
||||
.iter()
|
||||
.filter(|(_, value)| *value == language_profile)
|
||||
.map(|(key, _)| key)
|
||||
.next()
|
||||
.unwrap();
|
||||
let EditSeriesModal {
|
||||
monitored,
|
||||
use_season_folders,
|
||||
path,
|
||||
series_type_list,
|
||||
quality_profile_list,
|
||||
language_profile_list,
|
||||
..
|
||||
} = edit_series_modal;
|
||||
let quality_profile = quality_profile_list.current_selection();
|
||||
let quality_profile_id = *self
|
||||
.app
|
||||
.data
|
||||
.sonarr_data
|
||||
.quality_profile_map
|
||||
.iter()
|
||||
.filter(|(_, value)| *value == quality_profile)
|
||||
.map(|(key, _)| key)
|
||||
.next()
|
||||
.unwrap();
|
||||
let language_profile = language_profile_list.current_selection();
|
||||
let language_profile_id = *self
|
||||
.app
|
||||
.data
|
||||
.sonarr_data
|
||||
.language_profiles_map
|
||||
.iter()
|
||||
.filter(|(_, value)| *value == language_profile)
|
||||
.map(|(key, _)| key)
|
||||
.next()
|
||||
.unwrap();
|
||||
|
||||
EditSeriesParams {
|
||||
series_id,
|
||||
monitored: Some(monitored.unwrap_or_default()),
|
||||
use_season_folders: Some(use_season_folders.unwrap_or_default()),
|
||||
series_type: Some(*series_type_list.current_selection()),
|
||||
quality_profile_id: Some(quality_profile_id),
|
||||
language_profile_id: Some(language_profile_id),
|
||||
root_folder_path: Some(path.text.clone()),
|
||||
tag_input_string: Some(tags),
|
||||
..EditSeriesParams::default()
|
||||
}
|
||||
};
|
||||
|
||||
self.app.data.sonarr_data.edit_series_modal = None;
|
||||
|
||||
params
|
||||
EditSeriesParams {
|
||||
series_id,
|
||||
monitored,
|
||||
use_season_folders,
|
||||
series_type: Some(*series_type_list.current_selection()),
|
||||
quality_profile_id: Some(quality_profile_id),
|
||||
language_profile_id: Some(language_profile_id),
|
||||
root_folder_path: Some(path.text),
|
||||
tag_input_string: Some(tags),
|
||||
..EditSeriesParams::default()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -35,11 +35,9 @@ impl<'a, 'b> RootFoldersHandler<'a, 'b> {
|
||||
.data
|
||||
.sonarr_data
|
||||
.edit_root_folder
|
||||
.as_ref()
|
||||
.unwrap()
|
||||
.text
|
||||
.clone();
|
||||
self.app.data.sonarr_data.edit_root_folder = None;
|
||||
.take()
|
||||
.expect("EditRootFolder is None")
|
||||
.text;
|
||||
AddRootFolderBody { path: root_folder }
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user