Moving search results into each provider; #181
This commit is contained in:
@ -105,6 +105,7 @@ const CoreMiddleware = (function(){
|
||||
|
||||
case 'SEARCH_STARTED':
|
||||
ReactGA.event({ category: 'Search', action: 'Started', label: action.type+': '+action.query })
|
||||
next(action)
|
||||
|
||||
var state = store.getState()
|
||||
if (state.ui.search_settings){
|
||||
@ -171,7 +172,6 @@ const CoreMiddleware = (function(){
|
||||
}
|
||||
}
|
||||
|
||||
next(action)
|
||||
break
|
||||
|
||||
case 'PLAYLIST_TRACKS_ADDED':
|
||||
|
||||
@ -488,14 +488,10 @@ export default function reducer(core = {}, action){
|
||||
case 'SEARCH_STARTED':
|
||||
return Object.assign({}, core, {
|
||||
search_results: {
|
||||
artists_more: null,
|
||||
artists_uris: [],
|
||||
albums_more: null,
|
||||
albums_uris: [],
|
||||
playlists_more: null,
|
||||
playlists_uris: [],
|
||||
tracks: [],
|
||||
tracks_more: null,
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
@ -480,6 +480,14 @@ const MopidyMiddleware = (function(){
|
||||
**/
|
||||
|
||||
|
||||
case 'SEARCH_STARTED':
|
||||
store.dispatch({
|
||||
type: 'MOPIDY_CLEAR_SEARCH_RESULTS'
|
||||
});
|
||||
next(action)
|
||||
break
|
||||
|
||||
|
||||
case 'MOPIDY_GET_TRACK_SEARCH_RESULTS':
|
||||
instruct( socket, store, 'library.search', {query: {any: [action.query]}, uris: [action.uri_scheme]})
|
||||
.then( response => {
|
||||
@ -488,7 +496,11 @@ const MopidyMiddleware = (function(){
|
||||
|
||||
var tracks = response[0].tracks.splice(0,action.limit)
|
||||
|
||||
store.dispatch({ type: 'SEARCH_RESULTS_LOADED', tracks: tracks });
|
||||
store.dispatch({
|
||||
type: 'MOPIDY_SEARCH_RESULTS_LOADED',
|
||||
context: 'tracks',
|
||||
results: tracks
|
||||
});
|
||||
})
|
||||
break;
|
||||
|
||||
@ -520,7 +532,11 @@ const MopidyMiddleware = (function(){
|
||||
}
|
||||
|
||||
// and plug in their URIs
|
||||
store.dispatch({ type: 'SEARCH_RESULTS_LOADED', artists_uris: artists_uris })
|
||||
store.dispatch({
|
||||
type: 'MOPIDY_SEARCH_RESULTS_LOADED',
|
||||
context: 'artists',
|
||||
results: artists_uris
|
||||
})
|
||||
})
|
||||
break;
|
||||
|
||||
@ -551,7 +567,11 @@ const MopidyMiddleware = (function(){
|
||||
}
|
||||
|
||||
// and plug in their URIs
|
||||
store.dispatch({ type: 'SEARCH_RESULTS_LOADED', albums_uris: albums_uris })
|
||||
store.dispatch({
|
||||
type: 'MOPIDY_SEARCH_RESULTS_LOADED',
|
||||
context: 'albums',
|
||||
results: albums_uris
|
||||
})
|
||||
})
|
||||
break
|
||||
|
||||
@ -576,7 +596,11 @@ const MopidyMiddleware = (function(){
|
||||
}
|
||||
|
||||
// and plug in their URIs
|
||||
store.dispatch({ type: 'SEARCH_RESULTS_LOADED', playlists_uris: playlists_uris })
|
||||
store.dispatch({
|
||||
type: 'MOPIDY_SEARCH_RESULTS_LOADED',
|
||||
context: 'playlists',
|
||||
results: playlists_uris
|
||||
})
|
||||
})
|
||||
break
|
||||
|
||||
|
||||
@ -141,6 +141,31 @@ export default function reducer(mopidy = {}, action){
|
||||
}
|
||||
return Object.assign({}, mopidy, { library_albums: helpers.removeDuplicates(uris) })
|
||||
|
||||
|
||||
/**
|
||||
* Searching
|
||||
**/
|
||||
|
||||
case 'MOPIDY_CLEAR_SEARCH_RESULTS':
|
||||
return Object.assign({}, mopidy, { search_results: {} });
|
||||
|
||||
case 'MOPIDY_SEARCH_RESULTS_LOADED':
|
||||
|
||||
// Fetch or create our container
|
||||
if (mopidy.search_results){
|
||||
var search_results = Object.assign({}, mopidy.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
|
||||
}
|
||||
|
||||
return Object.assign({}, mopidy, { search_results: search_results });
|
||||
|
||||
default:
|
||||
return mopidy
|
||||
}
|
||||
|
||||
@ -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