Moving libraries into each provider for better granularity; Loading all artists (larger than expected)
This commit is contained in:
@ -912,19 +912,6 @@ export function getArtists( uris ){
|
||||
}
|
||||
|
||||
|
||||
export function getLibraryArtists(){
|
||||
return (dispatch, getState) => {
|
||||
sendRequest( dispatch, getState, 'me/following?type=artist&limit=50' )
|
||||
.then( response => {
|
||||
dispatch({
|
||||
type: 'SPOTIFY_LIBRARY_ARTISTS_LOADED',
|
||||
data: response
|
||||
})
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
export function playArtistTopTracks(uri){
|
||||
return (dispatch, getState) => {
|
||||
const artists = getState().ui.artists
|
||||
@ -1305,54 +1292,13 @@ export function reorderPlaylistTracks( uri, range_start, range_length, insert_be
|
||||
**/
|
||||
|
||||
|
||||
/**
|
||||
* ALbums
|
||||
**/
|
||||
|
||||
export function getLibraryAlbums(){
|
||||
return (dispatch, getState) => {
|
||||
dispatch(uiActions.startProcess('SPOTIFY_GET_LIBRARY_ALBUMS_PROCESSOR','Loading Spotify library albums', {next: 'me/albums?limit=50'}))
|
||||
}
|
||||
}
|
||||
|
||||
export function getLibraryAlbumsProcessor(data){
|
||||
return (dispatch, getState) => {
|
||||
sendRequest(dispatch, getState, data.next)
|
||||
.then( response => {
|
||||
|
||||
dispatch({
|
||||
type: 'SPOTIFY_LIBRARY_ALBUMS_LOADED',
|
||||
albums: response.items
|
||||
})
|
||||
|
||||
// Check to see if we've been cancelled
|
||||
if (getState().ui.processes['SPOTIFY_GET_LIBRARY_ALBUMS_PROCESSOR'] !== undefined){
|
||||
var processor = getState().ui.processes['SPOTIFY_GET_LIBRARY_ALBUMS_PROCESSOR']
|
||||
|
||||
if (processor.cancelling){
|
||||
dispatch(uiActions.processFinished('SPOTIFY_GET_LIBRARY_ALBUMS_PROCESSOR'))
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
// We got a next link, so we've got more work to be done
|
||||
if (response.next){
|
||||
dispatch(uiActions.runProcess('SPOTIFY_GET_LIBRARY_ALBUMS_PROCESSOR', {next: response.next}))
|
||||
} else {
|
||||
dispatch(uiActions.processFinished('SPOTIFY_GET_LIBRARY_ALBUMS_PROCESSOR'))
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Playlists
|
||||
**/
|
||||
|
||||
export function getLibraryPlaylists(){
|
||||
return (dispatch, getState) => {
|
||||
dispatch(uiActions.startProcess('SPOTIFY_GET_LIBRARY_PLAYLISTS_PROCESSOR','Loading Spotify library playlists', {next: 'me/playlists?limit=50'}))
|
||||
dispatch(uiActions.startProcess('SPOTIFY_GET_LIBRARY_PLAYLISTS_PROCESSOR','Loading Spotify playlists', {next: 'me/playlists?limit=50'}))
|
||||
}
|
||||
}
|
||||
|
||||
@ -1384,4 +1330,86 @@ export function getLibraryPlaylistsProcessor(data){
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Artists
|
||||
**/
|
||||
|
||||
export function getLibraryArtists(){
|
||||
return (dispatch, getState) => {
|
||||
dispatch(uiActions.startProcess('SPOTIFY_GET_LIBRARY_ARTISTS_PROCESSOR','Loading Spotify artists', {next: 'me/following?type=artist&limit=50'}))
|
||||
}
|
||||
}
|
||||
|
||||
export function getLibraryArtistsProcessor(data){
|
||||
return (dispatch, getState) => {
|
||||
sendRequest(dispatch, getState, data.next)
|
||||
.then( response => {
|
||||
|
||||
dispatch({
|
||||
type: 'SPOTIFY_LIBRARY_ARTISTS_LOADED',
|
||||
artists: response.artists.items
|
||||
})
|
||||
|
||||
// Check to see if we've been cancelled
|
||||
if (getState().ui.processes['SPOTIFY_GET_LIBRARY_ARTISTS_PROCESSOR'] !== undefined){
|
||||
var processor = getState().ui.processes['SPOTIFY_GET_LIBRARY_ARTISTS_PROCESSOR']
|
||||
|
||||
if (processor.cancelling){
|
||||
dispatch(uiActions.processFinished('SPOTIFY_GET_LIBRARY_ARTISTS_PROCESSOR'))
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
// We got a next link, so we've got more work to be done
|
||||
if (response.artists.next){
|
||||
dispatch(uiActions.runProcess('SPOTIFY_GET_LIBRARY_ARTISTS_PROCESSOR', {next: response.artists.next}))
|
||||
} else {
|
||||
dispatch(uiActions.processFinished('SPOTIFY_GET_LIBRARY_ARTISTS_PROCESSOR'))
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* ALbums
|
||||
**/
|
||||
|
||||
export function getLibraryAlbums(){
|
||||
return (dispatch, getState) => {
|
||||
dispatch(uiActions.startProcess('SPOTIFY_GET_LIBRARY_ALBUMS_PROCESSOR','Loading Spotify albums', {next: 'me/albums?limit=50'}))
|
||||
}
|
||||
}
|
||||
|
||||
export function getLibraryAlbumsProcessor(data){
|
||||
return (dispatch, getState) => {
|
||||
sendRequest(dispatch, getState, data.next)
|
||||
.then( response => {
|
||||
|
||||
dispatch({
|
||||
type: 'SPOTIFY_LIBRARY_ALBUMS_LOADED',
|
||||
albums: response.items
|
||||
})
|
||||
|
||||
// Check to see if we've been cancelled
|
||||
if (getState().ui.processes['SPOTIFY_GET_LIBRARY_ALBUMS_PROCESSOR'] !== undefined){
|
||||
var processor = getState().ui.processes['SPOTIFY_GET_LIBRARY_ALBUMS_PROCESSOR']
|
||||
|
||||
if (processor.cancelling){
|
||||
dispatch(uiActions.processFinished('SPOTIFY_GET_LIBRARY_ALBUMS_PROCESSOR'))
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
// We got a next link, so we've got more work to be done
|
||||
if (response.next){
|
||||
dispatch(uiActions.runProcess('SPOTIFY_GET_LIBRARY_ALBUMS_PROCESSOR', {next: response.next}))
|
||||
} else {
|
||||
dispatch(uiActions.processFinished('SPOTIFY_GET_LIBRARY_ALBUMS_PROCESSOR'))
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
@ -208,19 +208,22 @@ const SpotifyMiddleware = (function(){
|
||||
playlists: playlists
|
||||
});
|
||||
|
||||
store.dispatch({
|
||||
type: 'LIBRARY_PLAYLISTS_LOADED',
|
||||
uris: helpers.arrayOf('uri',playlists)
|
||||
});
|
||||
// Append our action with the uris. This gets handed down to subsequent middleware and our reducer.
|
||||
action.uris = helpers.arrayOf('uri',playlists)
|
||||
next(action)
|
||||
break
|
||||
|
||||
case 'SPOTIFY_GET_LIBRARY_ARTISTS_PROCESSOR':
|
||||
store.dispatch(spotifyActions.getLibraryArtistsProcessor(action.data))
|
||||
break
|
||||
|
||||
case 'SPOTIFY_LIBRARY_ARTISTS_LOADED':
|
||||
var artists = []
|
||||
for (var i = 0; i < action.data.artists.items.length; i++){
|
||||
for (var i = 0; i < action.artists.length; i++){
|
||||
artists.push(
|
||||
Object.assign(
|
||||
{},
|
||||
action.data.artists.items[i],
|
||||
action.artists[i],
|
||||
{
|
||||
source: 'spotify',
|
||||
in_library: true // assumed because we asked for library items
|
||||
@ -232,12 +235,10 @@ const SpotifyMiddleware = (function(){
|
||||
type: 'ARTISTS_LOADED',
|
||||
artists: artists
|
||||
});
|
||||
store.dispatch({
|
||||
type: 'LIBRARY_ARTISTS_LOADED',
|
||||
uris: helpers.arrayOf('uri',artists),
|
||||
more: action.data.artists.next,
|
||||
total: action.data.artists.total
|
||||
});
|
||||
|
||||
// Append our action with the uris. This gets handed down to subsequent middleware and our reducer.
|
||||
action.uris = helpers.arrayOf('uri',artists)
|
||||
next(action)
|
||||
break
|
||||
|
||||
case 'SPOTIFY_GET_LIBRARY_ALBUMS_PROCESSOR':
|
||||
@ -268,10 +269,9 @@ const SpotifyMiddleware = (function(){
|
||||
albums: albums
|
||||
});
|
||||
|
||||
store.dispatch({
|
||||
type: 'LIBRARY_ALBUMS_LOADED',
|
||||
uris: helpers.arrayOf('uri',albums)
|
||||
});
|
||||
// Append our action with the uris. This gets handed down to subsequent middleware and our reducer.
|
||||
action.uris = helpers.arrayOf('uri',albums)
|
||||
next(action)
|
||||
break
|
||||
|
||||
case 'SPOTIFY_FAVORITES_LOADED':
|
||||
|
||||
@ -73,73 +73,6 @@ export default function reducer(spotify = {}, action){
|
||||
case 'SPOTIFY_ME_LOADED':
|
||||
return Object.assign({}, spotify, { me: action.data })
|
||||
|
||||
case 'SPOTIFY_LIBRARY_ALBUMS_LOADED':
|
||||
if( !action.data ) return Object.assign({}, spotify)
|
||||
var albums = []
|
||||
for( var i = 0; i < action.data.items.length; i++ ){
|
||||
albums.push( Object.assign(
|
||||
{},
|
||||
action.data.items[i].album,
|
||||
{
|
||||
added_at: action.data.items[i].added_at
|
||||
}
|
||||
))
|
||||
}
|
||||
console.log(action)
|
||||
return Object.assign({}, spotify, {
|
||||
library_albums: albums,
|
||||
library_albums_spotify_more: action.data.next
|
||||
})
|
||||
|
||||
case 'SPOTIFY_LIBRARY_ALBUMS_LOADED_MORE':
|
||||
var albums = []
|
||||
for( var i = 0; i < action.data.items.length; i++ ){
|
||||
albums.push( Object.assign(
|
||||
{},
|
||||
action.data.items[i].album,
|
||||
{
|
||||
added_at: action.data.items[i].added_at
|
||||
}
|
||||
))
|
||||
}
|
||||
return Object.assign({}, spotify, {
|
||||
library_albums: [...spotify.library_albums, ...albums ],
|
||||
library_albums_spotify_more: action.data.next
|
||||
})
|
||||
|
||||
case 'SPOTIFY_LIBRARY_TRACKS_LOADED':
|
||||
if( !action.data ) return Object.assign({}, spotify)
|
||||
var tracks = Object.assign([], action.data.items)
|
||||
for( var i = 0; i < tracks.length; i++ ){
|
||||
tracks[i] = Object.assign(
|
||||
{},
|
||||
tracks[i].track,
|
||||
{
|
||||
added_at: tracks[i].added_at
|
||||
}
|
||||
)
|
||||
}
|
||||
return Object.assign({}, spotify, {
|
||||
library_tracks: tracks,
|
||||
library_tracks_more: action.data.next
|
||||
})
|
||||
|
||||
case 'SPOTIFY_LIBRARY_TRACKS_LOADED_MORE':
|
||||
var tracks = Object.assign([], action.data.items)
|
||||
for( var i = 0; i < tracks.length; i++ ){
|
||||
tracks[i] = Object.assign(
|
||||
{},
|
||||
tracks[i].track,
|
||||
{
|
||||
added_at: tracks[i].added_at
|
||||
}
|
||||
)
|
||||
}
|
||||
return Object.assign({}, spotify, {
|
||||
library_tracks: [...spotify.library_tracks, ...tracks],
|
||||
library_tracks_more: action.data.next
|
||||
})
|
||||
|
||||
case 'SPOTIFY_FEATURED_PLAYLISTS_LOADED':
|
||||
return Object.assign({}, spotify, { featured_playlists: action.data })
|
||||
|
||||
@ -212,6 +145,35 @@ export default function reducer(spotify = {}, action){
|
||||
autocomplete_results: autocomplete_results
|
||||
})
|
||||
|
||||
|
||||
/**
|
||||
* Library
|
||||
**/
|
||||
|
||||
case 'SPOTIFY_LIBRARY_PLAYLISTS_LOADED':
|
||||
if (spotify.library_playlists){
|
||||
var uris = [...spotify.library_playlists,...action.uris]
|
||||
} else {
|
||||
var uris = action.uris
|
||||
}
|
||||
return Object.assign({}, spotify, { library_playlists: uris })
|
||||
|
||||
case 'SPOTIFY_LIBRARY_ARTISTS_LOADED':
|
||||
if (spotify.library_artists){
|
||||
var uris = [...spotify.library_artists,...action.uris]
|
||||
} else {
|
||||
var uris = action.uris
|
||||
}
|
||||
return Object.assign({}, spotify, { library_artists: uris })
|
||||
|
||||
case 'SPOTIFY_LIBRARY_ALBUMS_LOADED':
|
||||
if (spotify.library_albums){
|
||||
var uris = [...spotify.library_albums,...action.uris]
|
||||
} else {
|
||||
var uris = action.uris
|
||||
}
|
||||
return Object.assign({}, spotify, { library_albums: uris })
|
||||
|
||||
default:
|
||||
return spotify
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user