refactor: Refactored several usages of sort_by_key and match guards to utilize newer Rust version APIs
This commit is contained in:
@@ -231,8 +231,8 @@ mod tests {
|
||||
let expected_keybinding_items = Vec::from(SERVARR_CONTEXT_CLUES)
|
||||
.iter()
|
||||
.map(|(key, desc)| {
|
||||
let (key, alt_key) = if key.alt.is_some() {
|
||||
(key.key.to_string(), key.alt.as_ref().unwrap().to_string())
|
||||
let (key, alt_key) = if let Some(key1) = key.alt {
|
||||
(key.key.to_string(), key1.to_string())
|
||||
} else {
|
||||
(key.key.to_string(), String::new())
|
||||
};
|
||||
@@ -338,8 +338,8 @@ mod tests {
|
||||
}
|
||||
|
||||
fn context_clue_to_keybinding_item(key: &KeyBinding, desc: &&str) -> KeybindingItem {
|
||||
let (key, alt_key) = if key.alt.is_some() {
|
||||
(key.key.to_string(), key.alt.as_ref().unwrap().to_string())
|
||||
let (key, alt_key) = if let Some(key1) = key.alt {
|
||||
(key.key.to_string(), key1.to_string())
|
||||
} else {
|
||||
(key.key.to_string(), String::new())
|
||||
};
|
||||
|
||||
@@ -506,18 +506,17 @@ impl<'a, 'b> KeyEventHandler<'a, 'b, ActiveLidarrBlock> for EditIndexerHandler<'
|
||||
.tags
|
||||
);
|
||||
}
|
||||
ActiveLidarrBlock::EditIndexerPrompt => {
|
||||
ActiveLidarrBlock::EditIndexerPrompt
|
||||
if self.app.data.lidarr_data.selected_block.get_active_block()
|
||||
== ActiveLidarrBlock::EditIndexerConfirmPrompt
|
||||
&& matches_key!(confirm, self.key)
|
||||
{
|
||||
self.app.data.lidarr_data.prompt_confirm = true;
|
||||
self.app.data.lidarr_data.prompt_confirm_action =
|
||||
Some(LidarrEvent::EditIndexer(self.build_edit_indexer_params()));
|
||||
self.app.should_refresh = true;
|
||||
&& matches_key!(confirm, self.key) =>
|
||||
{
|
||||
self.app.data.lidarr_data.prompt_confirm = true;
|
||||
self.app.data.lidarr_data.prompt_confirm_action =
|
||||
Some(LidarrEvent::EditIndexer(self.build_edit_indexer_params()));
|
||||
self.app.should_refresh = true;
|
||||
|
||||
self.app.pop_navigation_stack();
|
||||
}
|
||||
self.app.pop_navigation_stack();
|
||||
}
|
||||
_ => (),
|
||||
}
|
||||
|
||||
@@ -106,10 +106,10 @@ impl<'a, 'b> KeyEventHandler<'a, 'b, ActiveLidarrBlock> for IndexerSettingsHandl
|
||||
indexer_settings.maximum_size -= 1;
|
||||
}
|
||||
}
|
||||
ActiveLidarrBlock::IndexerSettingsRssSyncIntervalInput => {
|
||||
if indexer_settings.rss_sync_interval > 0 {
|
||||
indexer_settings.rss_sync_interval -= 1;
|
||||
}
|
||||
ActiveLidarrBlock::IndexerSettingsRssSyncIntervalInput
|
||||
if indexer_settings.rss_sync_interval > 0 =>
|
||||
{
|
||||
indexer_settings.rss_sync_interval -= 1;
|
||||
}
|
||||
_ => (),
|
||||
}
|
||||
|
||||
@@ -591,16 +591,15 @@ impl<'a, 'b> KeyEventHandler<'a, 'b, ActiveLidarrBlock> for AddArtistHandler<'a,
|
||||
.tags
|
||||
)
|
||||
}
|
||||
ActiveLidarrBlock::AddArtistPrompt => {
|
||||
ActiveLidarrBlock::AddArtistPrompt
|
||||
if self.app.data.lidarr_data.selected_block.get_active_block()
|
||||
== ActiveLidarrBlock::AddArtistConfirmPrompt
|
||||
&& matches_key!(confirm, key)
|
||||
{
|
||||
self.app.data.lidarr_data.prompt_confirm = true;
|
||||
self.app.data.lidarr_data.prompt_confirm_action =
|
||||
Some(LidarrEvent::AddArtist(self.build_add_artist_body()));
|
||||
self.app.pop_navigation_stack();
|
||||
}
|
||||
&& matches_key!(confirm, key) =>
|
||||
{
|
||||
self.app.data.lidarr_data.prompt_confirm = true;
|
||||
self.app.data.lidarr_data.prompt_confirm_action =
|
||||
Some(LidarrEvent::AddArtist(self.build_add_artist_body()));
|
||||
self.app.pop_navigation_stack();
|
||||
}
|
||||
_ => (),
|
||||
}
|
||||
|
||||
@@ -293,16 +293,16 @@ impl<'a, 'b> KeyEventHandler<'a, 'b, ActiveLidarrBlock> for ArtistDetailsHandler
|
||||
self.app.data.lidarr_data.selected_block =
|
||||
BlockSelectionState::new(EDIT_ARTIST_SELECTION_BLOCKS);
|
||||
}
|
||||
_ if matches_key!(toggle_monitoring, key) => {
|
||||
if !self.app.data.lidarr_data.albums.is_empty() {
|
||||
self.app.data.lidarr_data.prompt_confirm = true;
|
||||
self.app.data.lidarr_data.prompt_confirm_action =
|
||||
Some(LidarrEvent::ToggleAlbumMonitoring(self.extract_album_id()));
|
||||
_ if matches_key!(toggle_monitoring, key)
|
||||
&& !self.app.data.lidarr_data.albums.is_empty() =>
|
||||
{
|
||||
self.app.data.lidarr_data.prompt_confirm = true;
|
||||
self.app.data.lidarr_data.prompt_confirm_action =
|
||||
Some(LidarrEvent::ToggleAlbumMonitoring(self.extract_album_id()));
|
||||
|
||||
self
|
||||
.app
|
||||
.pop_and_push_navigation_stack(self.active_lidarr_block.into());
|
||||
}
|
||||
self
|
||||
.app
|
||||
.pop_and_push_navigation_stack(self.active_lidarr_block.into());
|
||||
}
|
||||
_ => (),
|
||||
},
|
||||
|
||||
@@ -428,18 +428,17 @@ impl<'a, 'b> KeyEventHandler<'a, 'b, ActiveLidarrBlock> for EditArtistHandler<'a
|
||||
.tags
|
||||
)
|
||||
}
|
||||
ActiveLidarrBlock::EditArtistPrompt => {
|
||||
ActiveLidarrBlock::EditArtistPrompt
|
||||
if self.app.data.lidarr_data.selected_block.get_active_block()
|
||||
== ActiveLidarrBlock::EditArtistConfirmPrompt
|
||||
&& matches_key!(confirm, key)
|
||||
{
|
||||
self.app.data.lidarr_data.prompt_confirm = true;
|
||||
self.app.data.lidarr_data.prompt_confirm_action =
|
||||
Some(LidarrEvent::EditArtist(self.build_edit_artist_params()));
|
||||
self.app.should_refresh = true;
|
||||
&& matches_key!(confirm, key) =>
|
||||
{
|
||||
self.app.data.lidarr_data.prompt_confirm = true;
|
||||
self.app.data.lidarr_data.prompt_confirm_action =
|
||||
Some(LidarrEvent::EditArtist(self.build_edit_artist_params()));
|
||||
self.app.should_refresh = true;
|
||||
|
||||
self.app.pop_navigation_stack();
|
||||
}
|
||||
self.app.pop_navigation_stack();
|
||||
}
|
||||
_ => (),
|
||||
}
|
||||
|
||||
@@ -505,19 +505,18 @@ impl<'a, 'b> KeyEventHandler<'a, 'b, ActiveLidarrBlock> for AddRootFolderHandler
|
||||
.tags
|
||||
)
|
||||
}
|
||||
ActiveLidarrBlock::AddRootFolderPrompt => {
|
||||
ActiveLidarrBlock::AddRootFolderPrompt
|
||||
if self.app.data.lidarr_data.selected_block.get_active_block()
|
||||
== ActiveLidarrBlock::AddRootFolderConfirmPrompt
|
||||
&& matches_key!(confirm, key)
|
||||
{
|
||||
self.app.data.lidarr_data.prompt_confirm = true;
|
||||
self.app.data.lidarr_data.prompt_confirm_action = Some(LidarrEvent::AddRootFolder(
|
||||
self.build_add_root_folder_body(),
|
||||
));
|
||||
self.app.should_refresh = true;
|
||||
&& matches_key!(confirm, key) =>
|
||||
{
|
||||
self.app.data.lidarr_data.prompt_confirm = true;
|
||||
self.app.data.lidarr_data.prompt_confirm_action = Some(LidarrEvent::AddRootFolder(
|
||||
self.build_add_root_folder_body(),
|
||||
));
|
||||
self.app.should_refresh = true;
|
||||
|
||||
self.app.pop_navigation_stack();
|
||||
}
|
||||
self.app.pop_navigation_stack();
|
||||
}
|
||||
_ => (),
|
||||
}
|
||||
|
||||
+2
-2
@@ -139,8 +139,8 @@ pub fn handle_events(key: Key, app: &mut App<'_>) {
|
||||
|
||||
pub fn populate_keymapping_table(app: &mut App<'_>) {
|
||||
let context_clue_to_keybinding_item = |key: &KeyBinding, desc: &&str| {
|
||||
let (key, alt_key) = if key.alt.is_some() {
|
||||
(key.key.to_string(), key.alt.as_ref().unwrap().to_string())
|
||||
let (key, alt_key) = if let Some(key1) = key.alt {
|
||||
(key.key.to_string(), key1.to_string())
|
||||
} else {
|
||||
(key.key.to_string(), String::new())
|
||||
};
|
||||
|
||||
@@ -354,19 +354,18 @@ impl<'a, 'b> KeyEventHandler<'a, 'b, ActiveRadarrBlock> for EditCollectionHandle
|
||||
.path
|
||||
)
|
||||
}
|
||||
ActiveRadarrBlock::EditCollectionPrompt => {
|
||||
ActiveRadarrBlock::EditCollectionPrompt
|
||||
if self.app.data.radarr_data.selected_block.get_active_block()
|
||||
== ActiveRadarrBlock::EditCollectionConfirmPrompt
|
||||
&& matches_key!(confirm, key)
|
||||
{
|
||||
self.app.data.radarr_data.prompt_confirm = true;
|
||||
self.app.data.radarr_data.prompt_confirm_action = Some(RadarrEvent::EditCollection(
|
||||
self.build_edit_collection_params(),
|
||||
));
|
||||
self.app.should_refresh = true;
|
||||
&& matches_key!(confirm, key) =>
|
||||
{
|
||||
self.app.data.radarr_data.prompt_confirm = true;
|
||||
self.app.data.radarr_data.prompt_confirm_action = Some(RadarrEvent::EditCollection(
|
||||
self.build_edit_collection_params(),
|
||||
));
|
||||
self.app.should_refresh = true;
|
||||
|
||||
self.app.pop_navigation_stack();
|
||||
}
|
||||
self.app.pop_navigation_stack();
|
||||
}
|
||||
_ => (),
|
||||
}
|
||||
|
||||
@@ -507,18 +507,17 @@ impl<'a, 'b> KeyEventHandler<'a, 'b, ActiveRadarrBlock> for EditIndexerHandler<'
|
||||
.tags
|
||||
);
|
||||
}
|
||||
ActiveRadarrBlock::EditIndexerPrompt => {
|
||||
ActiveRadarrBlock::EditIndexerPrompt
|
||||
if self.app.data.radarr_data.selected_block.get_active_block()
|
||||
== ActiveRadarrBlock::EditIndexerConfirmPrompt
|
||||
&& matches_key!(confirm, self.key)
|
||||
{
|
||||
self.app.data.radarr_data.prompt_confirm = true;
|
||||
self.app.data.radarr_data.prompt_confirm_action =
|
||||
Some(RadarrEvent::EditIndexer(self.build_edit_indexer_params()));
|
||||
self.app.should_refresh = true;
|
||||
&& matches_key!(confirm, self.key) =>
|
||||
{
|
||||
self.app.data.radarr_data.prompt_confirm = true;
|
||||
self.app.data.radarr_data.prompt_confirm_action =
|
||||
Some(RadarrEvent::EditIndexer(self.build_edit_indexer_params()));
|
||||
self.app.should_refresh = true;
|
||||
|
||||
self.app.pop_navigation_stack();
|
||||
}
|
||||
self.app.pop_navigation_stack();
|
||||
}
|
||||
_ => (),
|
||||
}
|
||||
|
||||
@@ -114,10 +114,10 @@ impl<'a, 'b> KeyEventHandler<'a, 'b, ActiveRadarrBlock> for IndexerSettingsHandl
|
||||
ActiveRadarrBlock::IndexerSettingsAvailabilityDelayInput => {
|
||||
indexer_settings.availability_delay -= 1;
|
||||
}
|
||||
ActiveRadarrBlock::IndexerSettingsRssSyncIntervalInput => {
|
||||
if indexer_settings.rss_sync_interval > 0 {
|
||||
indexer_settings.rss_sync_interval -= 1;
|
||||
}
|
||||
ActiveRadarrBlock::IndexerSettingsRssSyncIntervalInput
|
||||
if indexer_settings.rss_sync_interval > 0 =>
|
||||
{
|
||||
indexer_settings.rss_sync_interval -= 1;
|
||||
}
|
||||
_ => (),
|
||||
}
|
||||
@@ -272,19 +272,18 @@ impl<'a, 'b> KeyEventHandler<'a, 'b, ActiveRadarrBlock> for IndexerSettingsHandl
|
||||
.whitelisted_hardcoded_subs
|
||||
)
|
||||
}
|
||||
ActiveRadarrBlock::AllIndexerSettingsPrompt => {
|
||||
ActiveRadarrBlock::AllIndexerSettingsPrompt
|
||||
if self.app.data.radarr_data.selected_block.get_active_block()
|
||||
== ActiveRadarrBlock::IndexerSettingsConfirmPrompt
|
||||
&& matches_key!(confirm, self.key)
|
||||
{
|
||||
self.app.data.radarr_data.prompt_confirm = true;
|
||||
self.app.data.radarr_data.prompt_confirm_action = Some(
|
||||
RadarrEvent::EditAllIndexerSettings(self.build_edit_indexer_settings_body()),
|
||||
);
|
||||
self.app.should_refresh = true;
|
||||
&& matches_key!(confirm, self.key) =>
|
||||
{
|
||||
self.app.data.radarr_data.prompt_confirm = true;
|
||||
self.app.data.radarr_data.prompt_confirm_action = Some(
|
||||
RadarrEvent::EditAllIndexerSettings(self.build_edit_indexer_settings_body()),
|
||||
);
|
||||
self.app.should_refresh = true;
|
||||
|
||||
self.app.pop_navigation_stack();
|
||||
}
|
||||
self.app.pop_navigation_stack();
|
||||
}
|
||||
_ => (),
|
||||
}
|
||||
|
||||
@@ -539,16 +539,15 @@ impl<'a, 'b> KeyEventHandler<'a, 'b, ActiveRadarrBlock> for AddMovieHandler<'a,
|
||||
.tags
|
||||
)
|
||||
}
|
||||
ActiveRadarrBlock::AddMoviePrompt => {
|
||||
ActiveRadarrBlock::AddMoviePrompt
|
||||
if self.app.data.radarr_data.selected_block.get_active_block()
|
||||
== ActiveRadarrBlock::AddMovieConfirmPrompt
|
||||
&& matches_key!(confirm, key)
|
||||
{
|
||||
self.app.data.radarr_data.prompt_confirm = true;
|
||||
self.app.data.radarr_data.prompt_confirm_action =
|
||||
Some(RadarrEvent::AddMovie(self.build_add_movie_body()));
|
||||
self.app.pop_navigation_stack();
|
||||
}
|
||||
&& matches_key!(confirm, key) =>
|
||||
{
|
||||
self.app.data.radarr_data.prompt_confirm = true;
|
||||
self.app.data.radarr_data.prompt_confirm_action =
|
||||
Some(RadarrEvent::AddMovie(self.build_add_movie_body()));
|
||||
self.app.pop_navigation_stack();
|
||||
}
|
||||
_ => (),
|
||||
}
|
||||
|
||||
@@ -376,18 +376,17 @@ impl<'a, 'b> KeyEventHandler<'a, 'b, ActiveRadarrBlock> for EditMovieHandler<'a,
|
||||
.tags
|
||||
)
|
||||
}
|
||||
ActiveRadarrBlock::EditMoviePrompt => {
|
||||
ActiveRadarrBlock::EditMoviePrompt
|
||||
if self.app.data.radarr_data.selected_block.get_active_block()
|
||||
== ActiveRadarrBlock::EditMovieConfirmPrompt
|
||||
&& matches_key!(confirm, key)
|
||||
{
|
||||
self.app.data.radarr_data.prompt_confirm = true;
|
||||
self.app.data.radarr_data.prompt_confirm_action =
|
||||
Some(RadarrEvent::EditMovie(self.build_edit_movie_params()));
|
||||
self.app.should_refresh = true;
|
||||
&& matches_key!(confirm, key) =>
|
||||
{
|
||||
self.app.data.radarr_data.prompt_confirm = true;
|
||||
self.app.data.radarr_data.prompt_confirm_action =
|
||||
Some(RadarrEvent::EditMovie(self.build_edit_movie_params()));
|
||||
self.app.should_refresh = true;
|
||||
|
||||
self.app.pop_navigation_stack();
|
||||
}
|
||||
self.app.pop_navigation_stack();
|
||||
}
|
||||
_ => (),
|
||||
}
|
||||
|
||||
@@ -506,18 +506,17 @@ impl<'a, 'b> KeyEventHandler<'a, 'b, ActiveSonarrBlock> for EditIndexerHandler<'
|
||||
.tags
|
||||
);
|
||||
}
|
||||
ActiveSonarrBlock::EditIndexerPrompt => {
|
||||
ActiveSonarrBlock::EditIndexerPrompt
|
||||
if self.app.data.sonarr_data.selected_block.get_active_block()
|
||||
== ActiveSonarrBlock::EditIndexerConfirmPrompt
|
||||
&& matches_key!(confirm, self.key)
|
||||
{
|
||||
self.app.data.sonarr_data.prompt_confirm = true;
|
||||
self.app.data.sonarr_data.prompt_confirm_action =
|
||||
Some(SonarrEvent::EditIndexer(self.build_edit_indexer_params()));
|
||||
self.app.should_refresh = true;
|
||||
&& matches_key!(confirm, self.key) =>
|
||||
{
|
||||
self.app.data.sonarr_data.prompt_confirm = true;
|
||||
self.app.data.sonarr_data.prompt_confirm_action =
|
||||
Some(SonarrEvent::EditIndexer(self.build_edit_indexer_params()));
|
||||
self.app.should_refresh = true;
|
||||
|
||||
self.app.pop_navigation_stack();
|
||||
}
|
||||
self.app.pop_navigation_stack();
|
||||
}
|
||||
_ => (),
|
||||
}
|
||||
|
||||
@@ -106,10 +106,10 @@ impl<'a, 'b> KeyEventHandler<'a, 'b, ActiveSonarrBlock> for IndexerSettingsHandl
|
||||
indexer_settings.maximum_size -= 1;
|
||||
}
|
||||
}
|
||||
ActiveSonarrBlock::IndexerSettingsRssSyncIntervalInput => {
|
||||
if indexer_settings.rss_sync_interval > 0 {
|
||||
indexer_settings.rss_sync_interval -= 1;
|
||||
}
|
||||
ActiveSonarrBlock::IndexerSettingsRssSyncIntervalInput
|
||||
if indexer_settings.rss_sync_interval > 0 =>
|
||||
{
|
||||
indexer_settings.rss_sync_interval -= 1;
|
||||
}
|
||||
_ => (),
|
||||
}
|
||||
|
||||
@@ -606,16 +606,15 @@ impl<'a, 'b> KeyEventHandler<'a, 'b, ActiveSonarrBlock> for AddSeriesHandler<'a,
|
||||
.tags
|
||||
)
|
||||
}
|
||||
ActiveSonarrBlock::AddSeriesPrompt => {
|
||||
ActiveSonarrBlock::AddSeriesPrompt
|
||||
if self.app.data.sonarr_data.selected_block.get_active_block()
|
||||
== ActiveSonarrBlock::AddSeriesConfirmPrompt
|
||||
&& matches_key!(confirm, key)
|
||||
{
|
||||
self.app.data.sonarr_data.prompt_confirm = true;
|
||||
self.app.data.sonarr_data.prompt_confirm_action =
|
||||
Some(SonarrEvent::AddSeries(self.build_add_series_body()));
|
||||
self.app.pop_navigation_stack();
|
||||
}
|
||||
&& matches_key!(confirm, key) =>
|
||||
{
|
||||
self.app.data.sonarr_data.prompt_confirm = true;
|
||||
self.app.data.sonarr_data.prompt_confirm_action =
|
||||
Some(SonarrEvent::AddSeries(self.build_add_series_body()));
|
||||
self.app.pop_navigation_stack();
|
||||
}
|
||||
_ => (),
|
||||
}
|
||||
|
||||
@@ -450,18 +450,17 @@ impl<'a, 'b> KeyEventHandler<'a, 'b, ActiveSonarrBlock> for EditSeriesHandler<'a
|
||||
.tags
|
||||
)
|
||||
}
|
||||
ActiveSonarrBlock::EditSeriesPrompt => {
|
||||
ActiveSonarrBlock::EditSeriesPrompt
|
||||
if self.app.data.sonarr_data.selected_block.get_active_block()
|
||||
== ActiveSonarrBlock::EditSeriesConfirmPrompt
|
||||
&& matches_key!(confirm, key)
|
||||
{
|
||||
self.app.data.sonarr_data.prompt_confirm = true;
|
||||
self.app.data.sonarr_data.prompt_confirm_action =
|
||||
Some(SonarrEvent::EditSeries(self.build_edit_series_params()));
|
||||
self.app.should_refresh = true;
|
||||
&& matches_key!(confirm, key) =>
|
||||
{
|
||||
self.app.data.sonarr_data.prompt_confirm = true;
|
||||
self.app.data.sonarr_data.prompt_confirm_action =
|
||||
Some(SonarrEvent::EditSeries(self.build_edit_series_params()));
|
||||
self.app.should_refresh = true;
|
||||
|
||||
self.app.pop_navigation_stack();
|
||||
}
|
||||
self.app.pop_navigation_stack();
|
||||
}
|
||||
_ => (),
|
||||
}
|
||||
|
||||
@@ -893,7 +893,7 @@ mod tests {
|
||||
app.push_navigation_stack(ActiveRadarrBlock::MoviesSortPrompt.into());
|
||||
|
||||
let mut expected_vec = movies_vec();
|
||||
expected_vec.sort_by(|a, b| a.id.cmp(&b.id));
|
||||
expected_vec.sort_by_key(|a| a.id);
|
||||
expected_vec.reverse();
|
||||
|
||||
TableHandlerUnit::new(
|
||||
|
||||
Reference in New Issue
Block a user