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

Fix save in album view #119

Merged
merged 1 commit into from
Oct 28, 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
10 changes: 9 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,18 @@

## [Unreleased]

### Added

- Improve onboarding: auto fill the redirect url [#98](https://github.com/Rigellute/spotify-tui/pull/98)
- Indicate if a track is "liked" in Recently Played, Album tracks and song list views using "♥" - [#103](https://github.com/Rigellute/spotify-tui/pull/103)
- Fix app crash when pressing `enter`, `q` and then `down`. [#109](https://github.com/Rigellute/spotify-tui/pull/109)
- Add ability to toggle the saved state of a track: pressing `s` on an already saved track will unsave it. [#104](https://github.com/Rigellute/spotify-tui/pull/104)
- Add collaborative playlists scope. You'll need to reauthenticate due to this change. [#115](https://github.com/Rigellute/spotify-tui/pull/115)

### Fixed

- Fix app crash when pressing `enter`, `q` and then `down`. [#109](https://github.com/Rigellute/spotify-tui/pull/109)
- Fix trying to save a track in the album view [#119](https://github.com/Rigellute/spotify-tui/pull/119)
- Fix UI toggling saved track [#119](https://github.com/Rigellute/spotify-tui/pull/119)

## [0.7.0] - 2019-10-20

Expand Down
17 changes: 11 additions & 6 deletions src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ pub struct TrackTable {
pub struct SelectedAlbum {
pub album: SimplifiedAlbum,
pub tracks: Page<SimplifiedTrack>,
pub selected_index: Option<usize>,
pub selected_index: usize,
}

#[derive(Clone)]
Expand Down Expand Up @@ -717,7 +717,7 @@ impl App {
self.selected_album = Some(SelectedAlbum {
album,
tracks: tracks.clone(),
selected_index: Some(0),
selected_index: 0,
});

self.current_user_saved_tracks_contains(
Expand All @@ -744,15 +744,20 @@ impl App {
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(()) => {}
match spotify.current_user_saved_tracks_delete(&[track_id.clone()]) {
Ok(()) => {
self.liked_song_ids_set.remove(&track_id);
}
Err(e) => {
self.handle_error(e);
}
}
} else {
match spotify.current_user_saved_tracks_add(&[track_id]) {
Ok(()) => {}
match spotify.current_user_saved_tracks_add(&[track_id.clone()]) {
Ok(()) => {
// TODO: This should ideally use the same logic as `self.current_user_saved_tracks_contains`
self.liked_song_ids_set.insert(track_id);
}
Err(e) => {
self.handle_error(e);
}
Expand Down
24 changes: 18 additions & 6 deletions src/handlers/album_tracks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ pub fn handler(key: Key, app: &mut App) {
if let Some(selected_album) = &mut app.selected_album {
let next_index = common_key_events::on_down_press_handler(
&selected_album.tracks.items,
selected_album.selected_index,
Some(selected_album.selected_index),
);
selected_album.selected_index = Some(next_index);
selected_album.selected_index = next_index;
}
}
},
Expand All @@ -45,9 +45,9 @@ pub fn handler(key: Key, app: &mut App) {
if let Some(selected_album) = &mut app.selected_album {
let next_index = common_key_events::on_up_press_handler(
&selected_album.tracks.items,
selected_album.selected_index,
Some(selected_album.selected_index),
);
selected_album.selected_index = Some(next_index);
selected_album.selected_index = next_index;
}
}
},
Expand All @@ -68,7 +68,19 @@ pub fn handler(key: Key, app: &mut App) {
}
};
}
AlbumTableContext::Simplified => {}
AlbumTableContext::Simplified => {
if let Some(selected_album) = app.selected_album.clone() {
if let Some(selected_track) = selected_album
.tracks
.items
.get(selected_album.selected_index)
{
if let Some(track_id) = &selected_track.id {
app.toggle_save_track(track_id.clone());
};
};
};
}
},
Key::Char('\n') => match app.album_table_context {
AlbumTableContext::Full => {
Expand All @@ -87,7 +99,7 @@ pub fn handler(key: Key, app: &mut App) {
app.start_playback(
selected_album.album.uri.clone(),
None,
selected_album.selected_index,
Some(selected_album.selected_index),
);
};
}
Expand Down
2 changes: 1 addition & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ use redirect_uri::redirect_uri_web_server;
use util::{Event, Events};

const SCOPES: [&str; 10] = [
"playlist-read-private",
"playlist-read-collaborative",
"playlist-read-private",
"user-follow-read",
"user-library-modify",
"user-library-read",
Expand Down
2 changes: 1 addition & 1 deletion src/ui/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -476,7 +476,7 @@ where
selected_album.album.name,
create_artist_string(&selected_album.album.artists)
),
selected_index: selected_album.selected_index.unwrap_or(0),
selected_index: selected_album.selected_index,
}),
None => None,
},
Expand Down