refactor: Reduced the number of clones necessary when building modal structs

This commit is contained in:
2025-01-18 13:56:18 -07:00
parent 652bbcd5d4
commit fda69178b9
13 changed files with 203 additions and 276 deletions
@@ -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 }
}