Skip to content

Commit

Permalink
skip single selection for artist actions (#507)
Browse files Browse the repository at this point in the history
  • Loading branch information
aNNiMON authored Jul 19, 2024
1 parent ed9c4d4 commit 04f08f9
Showing 1 changed file with 42 additions and 23 deletions.
65 changes: 42 additions & 23 deletions spotify_player/src/event/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::{
client::{ClientRequest, PlayerRequest},
command::{self, Action, ActionContext, Command},
command::{self, construct_artist_actions, Action, ActionContext, Command},
config,
key::{Key, KeySequence},
state::*,
Expand Down Expand Up @@ -144,11 +144,7 @@ pub fn handle_action_in_context(
}
}
Action::GoToArtist => {
ui.popup = Some(PopupState::ArtistList(
ArtistPopupAction::Browse,
track.artists,
new_list_state(),
));
handle_go_to_artist(track.artists, ui);
}
Action::AddToQueue => {
client_pub.send(ClientRequest::AddTrackToQueue(track.id))?;
Expand Down Expand Up @@ -191,13 +187,7 @@ pub fn handle_action_in_context(
seed_name: name,
})?;
}
Action::ShowActionsOnArtist => {
ui.popup = Some(PopupState::ArtistList(
ArtistPopupAction::ShowActions,
track.artists,
new_list_state(),
));
}
Action::ShowActionsOnArtist => handle_show_actions_on_artist(track.artists, data, ui),
Action::ShowActionsOnAlbum => {
if let Some(album) = track.album {
let context = ActionContext::Album(album.clone());
Expand All @@ -224,11 +214,7 @@ pub fn handle_action_in_context(
},
ActionContext::Album(album) => match action {
Action::GoToArtist => {
ui.popup = Some(PopupState::ArtistList(
ArtistPopupAction::Browse,
album.artists,
new_list_state(),
));
handle_go_to_artist(album.artists, ui);
}
Action::GoToRadio => {
let uri = album.id.uri();
Expand All @@ -240,11 +226,7 @@ pub fn handle_action_in_context(
})?;
}
Action::ShowActionsOnArtist => {
ui.popup = Some(PopupState::ArtistList(
ArtistPopupAction::ShowActions,
album.artists,
new_list_state(),
));
handle_show_actions_on_artist(album.artists, data, ui);
}
Action::AddToLibrary => {
client_pub.send(ClientRequest::AddToLibrary(Item::Album(album)))?;
Expand Down Expand Up @@ -323,6 +305,43 @@ pub fn handle_action_in_context(
Ok(())
}

fn handle_go_to_artist(artists: Vec<Artist>, ui: &mut UIStateGuard) {
if artists.len() == 1 {
let context_id = ContextId::Artist(artists[0].id.clone());
ui.new_page(PageState::Context {
id: None,
context_page_type: ContextPageType::Browsing(context_id),
state: None,
});
} else {
ui.popup = Some(PopupState::ArtistList(
ArtistPopupAction::Browse,
artists,
new_list_state(),
));
}
}

fn handle_show_actions_on_artist(
artists: Vec<Artist>,
data: &DataReadGuard,
ui: &mut UIStateGuard,
) {
if artists.len() == 1 {
let actions = construct_artist_actions(&artists[0], data);
ui.popup = Some(PopupState::ActionList(
ActionListItem::Artist(artists[0].clone(), actions),
new_list_state(),
));
} else {
ui.popup = Some(PopupState::ArtistList(
ArtistPopupAction::ShowActions,
artists,
new_list_state(),
));
}
}

/// Handle a global command that is not specific to any page/popup
fn handle_global_command(
command: Command,
Expand Down

0 comments on commit 04f08f9

Please sign in to comment.