Moving search results into each provider; #181

This commit is contained in:
James Barnsley
2017-08-31 21:13:10 +12:00
parent 0ac9717ba2
commit 80077ea01d
9 changed files with 190 additions and 67 deletions

View File

@ -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

View File

@ -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
}