Skip to content

Commit

Permalink
impl GoToShow
Browse files Browse the repository at this point in the history
  • Loading branch information
SebRollen committed Aug 23, 2024
1 parent 61e5c60 commit 26f0166
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 8 deletions.
12 changes: 8 additions & 4 deletions spotify_player/src/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ pub enum Action {
GoToArtist,
GoToAlbum,
GoToRadio,
GoToShow,
AddToLibrary,
AddToPlaylist,
AddToQueue,
Expand Down Expand Up @@ -268,15 +269,18 @@ pub fn construct_show_actions(show: &Show, data: &DataReadGuard) -> Vec<Action>
}

/// constructs a list of actions on an episode
pub fn construct_episode_actions(_episode: &Episode, _data: &DataReadGuard) -> Vec<Action> {
vec![
pub fn construct_episode_actions(episode: &Episode, _data: &DataReadGuard) -> Vec<Action> {
let mut actions = vec![
//TODO: implement the below
//Action::GoToShow
//Action::ShowActionsOnShow,
Action::CopyLink,
Action::AddToPlaylist,
Action::AddToQueue,
]
];
if episode.show.is_some() {
actions.push(Action::GoToShow)
}
actions
}

impl Command {
Expand Down
18 changes: 14 additions & 4 deletions spotify_player/src/event/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -357,10 +357,20 @@ pub fn handle_action_in_context(
_ => Ok(false),
},
ActionContext::Episode(episode) => match action {
//Action::GoToShow => {
// handle_go_to_artist(track.artists, ui);
// Ok(true)
//}
Action::GoToShow => {
if let Some(show) = episode.show {
let context_id = ContextId::Show(
ShowId::from_uri(&parse_uri(&show.id.uri()))?.into_static(),
);
ui.new_page(PageState::Context {
id: None,
context_page_type: ContextPageType::Browsing(context_id),
state: None,
});
return Ok(true);
}
Ok(false)
}
Action::AddToQueue => {
client_pub.send(ClientRequest::AddEpisodeToQueue(episode.id))?;
ui.popup = None;
Expand Down
3 changes: 3 additions & 0 deletions spotify_player/src/state/model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,7 @@ pub struct Episode {
pub name: String,
pub description: String,
pub duration: std::time::Duration,
pub show: Option<Show>,
}

#[derive(Deserialize, Serialize, Debug, Clone)]
Expand Down Expand Up @@ -578,6 +579,7 @@ impl From<rspotify_model::SimplifiedEpisode> for Episode {
name: episode.name,
description: episode.description,
duration: episode.duration.to_std().expect("valid chrono duration"),
show: None,
}
}
}
Expand All @@ -589,6 +591,7 @@ impl From<rspotify_model::FullEpisode> for Episode {
name: episode.name,
description: episode.description,
duration: episode.duration.to_std().expect("valid chrono duration"),
show: Some(episode.show.into()),
}
}
}
Expand Down

0 comments on commit 26f0166

Please sign in to comment.