Playlist list... not sure if cleanest way to build components

This commit is contained in:
James Barnsley
2016-10-21 23:27:50 +13:00
parent 667efba1f7
commit 5b7f4f5831
13 changed files with 259 additions and 80 deletions

View File

@ -22,6 +22,19 @@ export function disconnect(){
}
}
export function instruct( call, value ){
return {
type: 'MOPIDY_INSTRUCT',
call: call,
value: value
}
}
/**
* Playback-oriented actions
**/
export function changeTrack( tlid ){
return {
type: 'MOPIDY_INSTRUCT',
@ -56,14 +69,6 @@ export function removeTracks( tlids ){
}
}
export function instruct( call, value ){
return {
type: 'MOPIDY_INSTRUCT',
call: call,
value: value
}
}
export function play(){
return instruct('playback.play');
}
@ -79,3 +84,14 @@ export function next(){
export function previous(){
return instruct('playback.previous');
}
/**
* Asset-oriented actions
**/
export function getPlaylists(){
return { type: 'MOPIDY_PLAYLISTS' }
}

View File

@ -154,6 +154,13 @@ const MopidyMiddleware = (function(){
})
break;
case 'MOPIDY_PLAYLISTS':
instruct( socket, store, 'playlists.asList' )
.then( response => {
store.dispatch({ type: 'MOPIDY_PLAYLISTS_LOADED', data: response });
})
break;
// This action is irrelevant to us, pass it on to the next middleware
default:
return next(action);

View File

@ -31,6 +31,11 @@ export default function reducer(mopidy = {}, action){
}
return Object.assign({}, mopidy, { tracks: mopidy.tracks });
case 'MOPIDY_PLAYLISTS_LOADED':
if( !action.data ) return mopidy;
return Object.assign({}, mopidy, { playlists: action.data });
/**
* Websocket-initiated actions
**/