Skip to content
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
54 changes: 53 additions & 1 deletion src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -928,7 +928,7 @@ impl App {
}
}

pub fn delete_current_user_saved_album(&mut self) {
pub fn current_user_saved_album_delete(&mut self) {
if let Some(albums) = self.library.saved_albums.get_results(None) {
if let Some(selected_album) = albums.items.get(self.album_list_index) {
if let Some(spotify) = &mut self.spotify {
Expand All @@ -942,6 +942,23 @@ impl App {
}
}

pub fn current_user_saved_album_add(&mut self) {
if let Some(albums) = &self.search_results.albums {
if let Some(selected_index) = self.search_results.selected_album_index {
if let Some(spotify) = &self.spotify {
let selected_album = &albums.albums.items[selected_index];
if let Some(artist_id) = &selected_album.id {
if let Err(e) =
spotify.current_user_saved_albums_add(&[artist_id.to_owned()])
{
self.handle_error(e);
}
}
}
}
}
}

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) {
Expand Down Expand Up @@ -969,4 +986,39 @@ impl App {
}
}
}

pub fn user_follow_playlists(&mut self) {
if let (Some(playlists), Some(selected_index), Some(spotify)) = (
&self.search_results.playlists,
self.search_results.selected_playlists_index,
&self.spotify,
) {
let selected_playlist: &SimplifiedPlaylist = &playlists.playlists.items[selected_index];
let selected_id = &selected_playlist.id;
let selected_public = selected_playlist.public;
let selected_owner_id = &selected_playlist.owner.id;
if let Err(e) = spotify.user_playlist_follow_playlist(
&selected_owner_id,
&selected_id,
selected_public,
) {
self.handle_error(e);
}
}
}

pub fn user_unfollow_playlists(&mut self) {
if let (Some(playlists), Some(selected_index), Some(user), Some(spotify)) = (
&self.playlists,
self.selected_playlist_index,
&self.user,
&self.spotify,
) {
let selected_playlist = &playlists.items[selected_index];
let selected_id = &selected_playlist.id;
if let Err(e) = spotify.user_playlist_unfollow(&user.id, &selected_id) {
self.handle_error(e);
}
}
}
}
2 changes: 1 addition & 1 deletion src/handlers/album_list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ pub fn handler(key: Key, app: &mut App) {
}
Key::Ctrl('d') => app.get_current_user_saved_albums_next(),
Key::Ctrl('u') => app.get_current_user_saved_albums_previous(),
Key::Char('D') => app.delete_current_user_saved_album(),
Key::Char('D') => app.current_user_saved_album_delete(),
_ => {}
};
}
Expand Down
11 changes: 11 additions & 0 deletions src/handlers/playlist.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,17 @@ pub fn handler(key: Key, app: &mut App) {
}
};
}
Key::Char('D') => {
app.user_unfollow_playlists();
if let Some(spotify) = &app.spotify {
let playlists = spotify.current_user_playlists(app.large_search_limit, None);

match playlists {
Ok(p) => app.playlists = Some(p),
Err(e) => app.handle_error(e),
};
}
}
_ => {}
}
}
Expand Down
14 changes: 12 additions & 2 deletions src/handlers/search_results.rs
Original file line number Diff line number Diff line change
Expand Up @@ -278,10 +278,20 @@ pub fn handler(key: Key, app: &mut App) {
}
}
Key::Char('w') => match app.search_results.selected_block {
SearchResultBlock::AlbumSearch => {}
SearchResultBlock::AlbumSearch => app.current_user_saved_album_add(),
SearchResultBlock::SongSearch => {}
SearchResultBlock::ArtistSearch => app.user_follow_artists(),
SearchResultBlock::PlaylistSearch => {}
SearchResultBlock::PlaylistSearch => {
app.user_follow_playlists();
if let Some(spotify) = &app.spotify {
let playlists = spotify.current_user_playlists(app.large_search_limit, None);

match playlists {
Ok(p) => app.playlists = Some(p),
Err(e) => app.handle_error(e),
}
}
}
SearchResultBlock::Empty => {}
},
// Add `s` to "see more" on each option
Expand Down
4 changes: 3 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,11 @@ use redirect_uri::redirect_uri_web_server;
use user_config::UserConfig;
use util::{Event, Events};

const SCOPES: [&str; 11] = [
const SCOPES: [&str; 13] = [
"playlist-read-collaborative",
"playlist-read-private",
"playlist-modify-private",
"playlist-modify-public",
"user-follow-read",
"user-follow-modify",
"user-library-modify",
Expand Down