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
@@ -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()
}
}
}