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

Follow/unfollow artists #155

Merged
merged 6 commits into from Nov 22, 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
29 changes: 28 additions & 1 deletion src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -858,7 +858,6 @@ impl App {
Ok(saved_artists) => {
self.artists = saved_artists.artists.items.to_owned();
self.library.saved_artists.add_pages(saved_artists.artists);
self.push_navigation_stack(RouteId::Artists, ActiveBlock::Artists);
}
Err(e) => {
self.handle_error(e);
Expand Down Expand Up @@ -919,4 +918,32 @@ impl App {
}
}
}

pub fn user_unfollow_artists(&mut self) {
if let Some(artists) = self.library.saved_artists.get_results(None) {
if let Some(selected_artist) = artists.items.get(self.artists_list_index) {
if let Some(spotify) = &mut self.spotify {
let artist_id = &selected_artist.id;
match spotify.user_unfollow_artists(&[artist_id.to_owned()]) {
Ok(_) => self.get_artists(None),
Err(e) => self.handle_error(e),
}
}
}
}
}

pub fn user_follow_artists(&mut self) {
if let Some(artists) = &self.search_results.artists {
if let Some(selected_index) = self.search_results.selected_artists_index {
if let Some(spotify) = &mut self.spotify {
let selected_artist: &FullArtist = &artists.artists.items[selected_index];
let artist_id = &selected_artist.id;
if let Err(e) = spotify.user_follow_artists(&[artist_id.to_owned()]) {
self.handle_error(e);
}
}
}
}
}
}
1 change: 1 addition & 0 deletions src/handlers/artists.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ pub fn handler(key: Key, app: &mut App) {
let artist = &artists[app.artists_list_index];
app.get_artist_albums(&artist.id.to_owned(), &artist.name.to_owned());
}
Key::Char('D') => app.user_unfollow_artists(),
_ => {}
}
}
1 change: 1 addition & 0 deletions src/handlers/library.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ pub fn handler(key: Key, app: &mut App) {
// Artists,
4 => {
app.get_artists(None);
app.push_navigation_stack(RouteId::Artists, ActiveBlock::Artists);
}
// Podcasts,
5 => {
Expand Down
7 changes: 7 additions & 0 deletions src/handlers/search_results.rs
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,13 @@ pub fn handler(key: Key, app: &mut App) {
handle_enter_event_on_hovered_block(app)
}
}
Key::Char('w') => match app.search_results.selected_block {
SearchResultBlock::AlbumSearch => {}
SearchResultBlock::SongSearch => {}
SearchResultBlock::ArtistSearch => app.user_follow_artists(),
SearchResultBlock::PlaylistSearch => {}
SearchResultBlock::Empty => {}
},
// Add `s` to "see more" on each option
_ => {}
}
Expand Down
3 changes: 2 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,11 @@ use redirect_uri::redirect_uri_web_server;
use user_config::UserConfig;
use util::{Event, Events};

const SCOPES: [&str; 10] = [
const SCOPES: [&str; 11] = [
"playlist-read-collaborative",
"playlist-read-private",
"user-follow-read",
"user-follow-modify",
"user-library-modify",
"user-library-read",
"user-modify-playback-state",
Expand Down
1 change: 1 addition & 0 deletions src/ui/help.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,5 +76,6 @@ pub fn get_help_docs() -> Vec<Vec<&'static str>> {
"Pagination",
],
vec!["Delete saved album", "D", "Library -> Albums"],
vec!["Follow an artists", "w", "Search result"],
]
}