Moving search results into each provider; #181
This commit is contained in:
@ -482,15 +482,31 @@ export function getSearchResults(query, type = 'album,artist,playlist,track', li
|
||||
});
|
||||
|
||||
dispatch({
|
||||
type: 'SEARCH_RESULTS_LOADED',
|
||||
playlists_uris: helpers.arrayOf('uri',playlists),
|
||||
playlists_more: response.playlists.next,
|
||||
artists_uris: helpers.arrayOf('uri',response.artists.items),
|
||||
artists_more: response.artists.next,
|
||||
albums_uris: helpers.arrayOf('uri',response.albums.items),
|
||||
albums_more: response.albums.next,
|
||||
tracks: response.tracks.items,
|
||||
tracks_more: response.tracks.next
|
||||
type: 'SPOTIFY_SEARCH_RESULTS_LOADED',
|
||||
context: 'playlists',
|
||||
results: helpers.arrayOf('uri',playlists),
|
||||
more: response.playlists.next
|
||||
});
|
||||
|
||||
dispatch({
|
||||
type: 'SPOTIFY_SEARCH_RESULTS_LOADED',
|
||||
context: 'artists',
|
||||
results: helpers.arrayOf('uri',response.artists.items),
|
||||
more: response.artists.next,
|
||||
});
|
||||
|
||||
dispatch({
|
||||
type: 'SPOTIFY_SEARCH_RESULTS_LOADED',
|
||||
context: 'albums',
|
||||
results: helpers.arrayOf('uri',response.albums.items),
|
||||
more: response.albums.next,
|
||||
});
|
||||
|
||||
dispatch({
|
||||
type: 'SPOTIFY_SEARCH_RESULTS_LOADED',
|
||||
context: 'tracks',
|
||||
results: response.tracks.items,
|
||||
more: response.tracks.next,
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
@ -300,11 +300,25 @@ const SpotifyMiddleware = (function(){
|
||||
});
|
||||
break
|
||||
|
||||
|
||||
/**
|
||||
* Searching
|
||||
* More results are lazy-loaded on demand, based on the _more URL
|
||||
**/
|
||||
|
||||
case 'SEARCH_STARTED':
|
||||
store.dispatch({
|
||||
type: 'SPOTIFY_CLEAR_SEARCH_RESULTS'
|
||||
});
|
||||
next(action)
|
||||
break
|
||||
|
||||
case 'SPOTIFY_SEARCH_RESULTS_LOADED_MORE_TRACKS':
|
||||
store.dispatch({
|
||||
type: 'SEARCH_RESULTS_LOADED',
|
||||
tracks: action.data.tracks.items,
|
||||
tracks_more: action.data.tracks.next
|
||||
type: 'SPOTIFY_SEARCH_RESULTS_LOADED',
|
||||
context: 'tracks',
|
||||
results: action.data.tracks.items,
|
||||
more: action.data.tracks.next
|
||||
});
|
||||
break
|
||||
|
||||
@ -316,9 +330,10 @@ const SpotifyMiddleware = (function(){
|
||||
});
|
||||
|
||||
store.dispatch({
|
||||
type: 'SEARCH_RESULTS_LOADED',
|
||||
playlists_uris: helpers.arrayOf('uri',action.data.playlists.items),
|
||||
playlists_more: action.data.playlists.next
|
||||
type: 'SPOTIFY_SEARCH_RESULTS_LOADED',
|
||||
context: 'artists',
|
||||
results: helpers.arrayOf('uri',action.data.playlists.items),
|
||||
more: action.data.playlists.next
|
||||
});
|
||||
break
|
||||
|
||||
@ -330,9 +345,10 @@ const SpotifyMiddleware = (function(){
|
||||
});
|
||||
|
||||
store.dispatch({
|
||||
type: 'SEARCH_RESULTS_LOADED',
|
||||
albums_uris: helpers.arrayOf('uri',action.data.albums.items),
|
||||
albums_more: action.data.albums.next
|
||||
type: 'SPOTIFY_SEARCH_RESULTS_LOADED',
|
||||
context: 'playlists',
|
||||
results: helpers.arrayOf('uri',action.data.albums.items),
|
||||
more: action.data.albums.next
|
||||
});
|
||||
break
|
||||
|
||||
@ -355,12 +371,14 @@ const SpotifyMiddleware = (function(){
|
||||
});
|
||||
|
||||
store.dispatch({
|
||||
type: 'SEARCH_RESULTS_LOADED',
|
||||
playlists_uris: helpers.arrayOf('uri',action.data.playlists.items),
|
||||
playlists_more: action.data.playlists.next
|
||||
type: 'SPOTIFY_SEARCH_RESULTS_LOADED',
|
||||
context: 'playlists',
|
||||
results: helpers.arrayOf('uri',action.data.playlists.items),
|
||||
more: action.data.playlists.next
|
||||
});
|
||||
break
|
||||
|
||||
|
||||
case 'SPOTIFY_ME_LOADED':
|
||||
|
||||
// We've loaded 'me' and we are Anonymous currently
|
||||
|
||||
@ -240,6 +240,36 @@ export default function reducer(spotify = {}, action){
|
||||
}
|
||||
return Object.assign({}, spotify, { library_playlists: items });
|
||||
|
||||
|
||||
/**
|
||||
* Searching
|
||||
**/
|
||||
|
||||
case 'SPOTIFY_CLEAR_SEARCH_RESULTS':
|
||||
return Object.assign({}, spotify, { search_results: {} });
|
||||
|
||||
case 'SPOTIFY_SEARCH_RESULTS_LOADED':
|
||||
|
||||
// Fetch or create our container
|
||||
if (spotify.search_results){
|
||||
var search_results = Object.assign({}, spotify.search_results)
|
||||
} else {
|
||||
var search_results = {}
|
||||
}
|
||||
|
||||
if (search_results.results){
|
||||
search_results[action.context] = [...search_results[action.context], ...action.results]
|
||||
} else {
|
||||
search_results[action.context] = action.results
|
||||
}
|
||||
|
||||
if (action.more){
|
||||
search_results[action.context+'_more'] = action.more
|
||||
} else {
|
||||
search_results[action.context+'_more'] = null
|
||||
}
|
||||
return Object.assign({}, spotify, { search_results: search_results });
|
||||
|
||||
default:
|
||||
return spotify
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user