LoadMore now getMore with custom action callback; Fixing library re-load on re-render
This commit is contained in:
@ -289,10 +289,7 @@ export function getTrack(uri){
|
||||
|
||||
export function getLibraryTracks(){
|
||||
return (dispatch, getState) => {
|
||||
|
||||
dispatch({ type: 'SPOTIFY_LIBRARY_TRACKS_LOADED', data: false });
|
||||
|
||||
sendRequest(dispatch, getState, 'me/tracks?limit=50' )
|
||||
sendRequest(dispatch, getState, 'me/tracks?limit=50')
|
||||
.then(
|
||||
response => {
|
||||
dispatch({
|
||||
@ -501,24 +498,21 @@ export function getURL(url, action_name, key = false){
|
||||
}
|
||||
}
|
||||
|
||||
export function loadMore(url, loaded_more_action = null, custom_action = null){
|
||||
export function getMore(url, core_action = null, custom_action = null){
|
||||
return (dispatch, getState) => {
|
||||
sendRequest(dispatch, getState, url)
|
||||
.then(
|
||||
response => {
|
||||
if (loaded_more_action){
|
||||
if (core_action){
|
||||
dispatch(coreActions.loadedMore(
|
||||
loaded_more_action.parent_type,
|
||||
loaded_more_action.parent_key,
|
||||
loaded_more_action.records_type,
|
||||
core_action.parent_type,
|
||||
core_action.parent_key,
|
||||
core_action.records_type,
|
||||
response
|
||||
));
|
||||
} else if (custom_action){
|
||||
dispatch({
|
||||
type: custom_action.type,
|
||||
key: custom_action.key,
|
||||
data: response
|
||||
});
|
||||
custom_action.data = response;
|
||||
dispatch(custom_action);
|
||||
} else {
|
||||
dispatch(coreActions.handleException(
|
||||
'No callback handler for loading more items'
|
||||
|
||||
@ -309,12 +309,23 @@ const SpotifyMiddleware = (function(){
|
||||
next(action)
|
||||
break
|
||||
|
||||
case 'SPOTIFY_LIBRARY_TRACKS_LOADED':
|
||||
case 'SPOTIFY_LIBRARY_TRACKS_LOADED_MORE':
|
||||
if (action.data){
|
||||
store.dispatch({
|
||||
type: 'TRACKS_LOADED',
|
||||
tracks: action.data.items
|
||||
});
|
||||
}
|
||||
next(action);
|
||||
break;
|
||||
|
||||
case 'SPOTIFY_TRACK_LOADED':
|
||||
store.dispatch({
|
||||
type: 'TRACK_LOADED',
|
||||
key: action.data.uri,
|
||||
track: action.data
|
||||
type: 'TRACKS_LOADED',
|
||||
tracks: [action.data]
|
||||
});
|
||||
next(action);
|
||||
break
|
||||
|
||||
|
||||
|
||||
@ -210,17 +210,19 @@ export default function reducer(spotify = {}, action){
|
||||
|
||||
case 'SPOTIFY_LIBRARY_TRACKS_LOADED':
|
||||
case 'SPOTIFY_LIBRARY_TRACKS_LOADED_MORE':
|
||||
var tracks = action.data.items
|
||||
var tracks = action.data.items;
|
||||
var uris = [];
|
||||
|
||||
if (tracks){
|
||||
tracks = helpers.formatTracks(tracks);
|
||||
uris = helpers.arrayOf('uri', tracks);
|
||||
if (spotify.library_tracks){
|
||||
tracks = [...spotify.library_tracks,...tracks]
|
||||
uris = [...spotify.library_tracks, ...uris]
|
||||
}
|
||||
}
|
||||
|
||||
return Object.assign({}, spotify, {
|
||||
library_tracks: tracks,
|
||||
library_tracks: helpers.removeDuplicates(uris),
|
||||
library_tracks_more: action.data.next
|
||||
})
|
||||
|
||||
|
||||
Reference in New Issue
Block a user