Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unsave already saved songs with 's' #104

Merged
merged 3 commits into from
Oct 27, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 19 additions & 3 deletions src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -707,10 +707,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