Task names; Fixing following button and adding notifications

This commit is contained in:
James Barnsley
2019-10-16 16:42:38 +13:00
parent c487f8979a
commit c82326f452
10 changed files with 60 additions and 7683 deletions

View File

@ -760,12 +760,14 @@ export function following(uri, method = 'GET') {
endpoint = `playlists/${helpers.getFromUri('playlistid', uri)}/followers`;
}
break;
default:
break;
}
request(dispatch, getState, endpoint, method, data)
.then(
(response) => {
if (response) {
if (Array.isArray(response) && response.length > 0) {
is_following = response[0];
} else {
is_following = is_following;
@ -776,6 +778,14 @@ export function following(uri, method = 'GET') {
key: uri,
in_library: is_following,
});
if (method !== 'GET') {
dispatch(uiActions.createNotification(
{
message: is_following ? `Added ${asset_name} to library` : `Removed ${asset_name} from library`,
}
));
}
},
(error) => {
dispatch(coreActions.handleException(
@ -1047,7 +1057,7 @@ export function getArtist(uri, full = false) {
// Start with an empty object
// As each requests completes, they'll add to this object
const artist = {};
// We need our artist, obviously
const requests = [
request(dispatch, getState, `artists/${helpers.getFromUri('artistid', uri)}`, 'GET', false, true)
@ -1349,30 +1359,6 @@ export function getAlbum(uri) {
};
}
export function toggleAlbumInLibrary(uri, method) {
if (method == 'PUT') var new_state = 1;
if (method == 'DELETE') var new_state = 0;
return (dispatch, getState) => {
request(dispatch, getState, `me/albums?ids=${helpers.getFromUri('albumid', uri)}`, method)
.then(
(response) => {
dispatch({
type: 'SPOTIFY_ALBUM_FOLLOWING',
key: uri,
data: new_state,
});
},
(error) => {
dispatch(coreActions.handleException(
'Could not add/remove library album',
error,
));
},
);
};
}
/**
* =============================================================== PLAYLIST(S) ==========
@ -1710,30 +1696,6 @@ export function getAllPlaylistTracksProcessor(data) {
};
}
export function toggleFollowingPlaylist(uri, method) {
if (method == 'PUT') var new_state = 1;
if (method == 'DELETE') var new_state = 0;
return (dispatch, getState) => {
request(dispatch, getState, `playlists/${helpers.getFromUri('playlistid', uri)}/followers`, method)
.then(
(response) => {
dispatch({
type: 'SPOTIFY_PLAYLIST_FOLLOWING_LOADED',
key: uri,
is_following: new_state,
});
},
(error) => {
dispatch(coreActions.handleException(
'Could not add/remove library playlist',
error,
));
},
);
};
}
export function addTracksToPlaylist(uri, tracks_uris) {
return (dispatch, getState) => {
request(dispatch, getState, `playlists/${helpers.getFromUri('playlistid', uri)}/tracks`, 'POST', { uris: tracks_uris })