Skip to content

Commit

Permalink
Merge pull request #104 from jfaltis/unsave-songs
Browse files Browse the repository at this point in the history
Unsave already saved songs with 's'
  • Loading branch information
Rigellute committed Oct 27, 2019
2 parents 25f32e3 + 0557cbd commit 229c4b8
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 6 deletions.
22 changes: 19 additions & 3 deletions src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -739,10 +739,26 @@ impl App {
}
}

pub fn save_tracks(&mut self, track_ids: Vec<String>) {
pub fn toggle_save_track(&mut self, track_id: String) {
if let Some(spotify) = &self.spotify {
match spotify.current_user_saved_tracks_add(&track_ids) {
Ok(()) => {}
match spotify.current_user_saved_tracks_contains(&[track_id.clone()]) {
Ok(saved) => {
if saved.first() == Some(&true) {
match spotify.current_user_saved_tracks_delete(&[track_id]) {
Ok(()) => {}
Err(e) => {
self.handle_error(e);
}
}
} else {
match spotify.current_user_saved_tracks_add(&[track_id]) {
Ok(()) => {}
Err(e) => {
self.handle_error(e);
}
}
}
}
Err(e) => {
self.handle_error(e);
}
Expand Down
2 changes: 1 addition & 1 deletion src/handlers/album_tracks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ pub fn handler(key: Key, app: &mut App) {
.get(app.saved_album_tracks_index)
{
if let Some(track_id) = &selected_track.id {
app.save_tracks(vec![track_id.clone()]);
app.toggle_save_track(track_id.clone());
};
};
}
Expand Down
2 changes: 1 addition & 1 deletion src/handlers/playbar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ pub fn handler(key: Key, app: &mut App) {
if let Some(playing_context) = &app.current_playback_context {
if let Some(track) = &playing_context.item {
if let Some(id) = track.id.to_owned() {
app.save_tracks(vec![id]);
app.toggle_save_track(id);
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/handlers/recently_played.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ pub fn handler(key: Key, app: &mut App) {
recently_played_result.items.get(app.recently_played.index)
{
if let Some(track_id) = &selected_track.track.id {
app.save_tracks(vec![track_id.clone()]);
app.toggle_save_track(track_id.clone());
};
};
};
Expand Down

0 comments on commit 229c4b8

Please sign in to comment.