2016-10-14 22:42:45 +13:00
|
|
|
|
2017-08-16 12:40:27 +12:00
|
|
|
import * as helpers from '../../helpers'
|
|
|
|
|
|
2016-10-14 22:42:45 +13:00
|
|
|
export default function reducer(mopidy = {}, action){
|
2017-10-10 13:05:28 +13:00
|
|
|
switch (action.type){
|
2016-10-14 22:42:45 +13:00
|
|
|
|
2016-11-06 15:47:37 +13:00
|
|
|
case 'MOPIDY_CONNECT':
|
|
|
|
|
case 'MOPIDY_CONNECTING':
|
|
|
|
|
return Object.assign({}, mopidy, { connected: false, connecting: true });
|
|
|
|
|
|
2018-04-17 15:58:39 +12:00
|
|
|
case 'MOPIDY_RESTART_STARTED':
|
|
|
|
|
return Object.assign({}, mopidy, { restarting: true });
|
2018-04-16 15:51:35 +12:00
|
|
|
|
2018-04-17 15:58:39 +12:00
|
|
|
case 'MOPIDY_UPGRADE_STARTED':
|
2018-04-16 21:58:38 +12:00
|
|
|
return Object.assign({}, mopidy, { upgrading: true });
|
|
|
|
|
|
2016-10-16 12:37:37 +13:00
|
|
|
case 'MOPIDY_CONNECTED':
|
2018-04-16 21:58:38 +12:00
|
|
|
return Object.assign({}, mopidy, { connected: true, connecting: false, restarting: false, upgrading: false });
|
2016-10-14 22:42:45 +13:00
|
|
|
|
2016-10-16 12:37:37 +13:00
|
|
|
case 'MOPIDY_DISCONNECTED':
|
2016-10-14 22:42:45 +13:00
|
|
|
return Object.assign({}, mopidy, { connected: false, connecting: false });
|
|
|
|
|
|
2016-10-18 08:56:53 +13:00
|
|
|
case 'MOPIDY_SET_CONFIG':
|
|
|
|
|
return Object.assign({}, mopidy, {
|
2017-11-27 16:38:33 +13:00
|
|
|
host: action.config.host,
|
|
|
|
|
port: action.config.port,
|
|
|
|
|
ssl: action.config.ssl
|
2016-10-18 08:56:53 +13:00
|
|
|
});
|
|
|
|
|
|
2016-10-16 12:37:37 +13:00
|
|
|
case 'MOPIDY_CHANGE_TRACK':
|
|
|
|
|
return Object.assign({}, mopidy, {
|
2016-10-21 09:56:07 +13:00
|
|
|
tlid: action.tlid
|
2016-10-16 12:37:37 +13:00
|
|
|
});
|
|
|
|
|
|
2018-02-26 10:25:56 +13:00
|
|
|
case 'MOPIDY_URI_SCHEMES':
|
2016-11-06 18:29:49 +13:00
|
|
|
return Object.assign({}, mopidy, {
|
2018-02-26 10:25:56 +13:00
|
|
|
uri_schemes: action.uri_schemes
|
2016-11-06 18:29:49 +13:00
|
|
|
});
|
2016-10-21 23:27:50 +13:00
|
|
|
|
|
|
|
|
|
2016-10-16 12:37:37 +13:00
|
|
|
/**
|
2016-11-06 18:29:49 +13:00
|
|
|
* State-oriented actions
|
2016-10-16 12:37:37 +13:00
|
|
|
**/
|
2018-02-26 10:25:56 +13:00
|
|
|
case 'MOPIDY_PLAY_STATE':
|
2016-10-14 22:42:45 +13:00
|
|
|
return Object.assign({}, mopidy, {
|
2018-02-26 10:25:56 +13:00
|
|
|
play_state: action.play_state
|
2016-10-14 22:42:45 +13:00
|
|
|
});
|
|
|
|
|
|
2016-10-20 21:38:01 +13:00
|
|
|
case 'MOPIDY_CONSUME':
|
2016-10-14 22:42:45 +13:00
|
|
|
return Object.assign({}, mopidy, {
|
2018-02-26 10:25:56 +13:00
|
|
|
consume: action.consume
|
2016-10-14 22:42:45 +13:00
|
|
|
});
|
|
|
|
|
|
2016-10-20 21:38:01 +13:00
|
|
|
case 'MOPIDY_RANDOM':
|
2016-10-14 22:42:45 +13:00
|
|
|
return Object.assign({}, mopidy, {
|
2018-02-26 10:25:56 +13:00
|
|
|
random: action.random
|
2016-10-14 22:42:45 +13:00
|
|
|
});
|
|
|
|
|
|
2016-10-20 21:38:01 +13:00
|
|
|
case 'MOPIDY_REPEAT':
|
2016-10-14 22:42:45 +13:00
|
|
|
return Object.assign({}, mopidy, {
|
2018-02-26 10:25:56 +13:00
|
|
|
repeat: action.repeat
|
2016-10-14 22:42:45 +13:00
|
|
|
});
|
|
|
|
|
|
2016-11-06 18:29:49 +13:00
|
|
|
case 'MOPIDY_VOLUME':
|
|
|
|
|
return Object.assign({}, mopidy, {
|
2018-02-26 10:25:56 +13:00
|
|
|
volume: action.volume
|
2016-11-06 18:29:49 +13:00
|
|
|
});
|
|
|
|
|
|
2017-05-19 11:33:06 +12:00
|
|
|
case 'MOPIDY_MUTE':
|
|
|
|
|
return Object.assign({}, mopidy, {
|
2018-02-26 10:25:56 +13:00
|
|
|
mute: action.mute
|
2017-05-19 11:33:06 +12:00
|
|
|
});
|
|
|
|
|
|
2018-02-26 10:25:56 +13:00
|
|
|
case 'MOPIDY_TIME_POSITION':
|
2016-11-06 18:29:49 +13:00
|
|
|
return Object.assign({}, mopidy, {
|
2018-02-26 10:25:56 +13:00
|
|
|
time_position: action.time_position
|
2016-11-06 18:29:49 +13:00
|
|
|
});
|
|
|
|
|
|
2018-03-02 08:07:30 +13:00
|
|
|
case 'MOPIDY_QUEUE_HISTORY':
|
|
|
|
|
var history = [];
|
|
|
|
|
for (var i = 0; i < action.tracks.length; i++){
|
2017-02-10 09:06:41 +13:00
|
|
|
history.push(Object.assign(
|
|
|
|
|
{},
|
2018-03-02 08:07:30 +13:00
|
|
|
action.tracks[i][1],
|
2017-02-10 09:06:41 +13:00
|
|
|
{
|
2018-03-02 08:07:30 +13:00
|
|
|
played_at: action.tracks[i][0],
|
2017-02-10 09:06:41 +13:00
|
|
|
type: 'history'
|
|
|
|
|
}
|
|
|
|
|
))
|
|
|
|
|
}
|
|
|
|
|
return Object.assign({}, mopidy, {
|
|
|
|
|
queue_history: history
|
|
|
|
|
});
|
|
|
|
|
|
2016-11-06 18:29:49 +13:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Asset-oriented actions
|
|
|
|
|
**/
|
|
|
|
|
|
2016-11-02 16:51:00 +13:00
|
|
|
case 'MOPIDY_DIRECTORY_LOADED':
|
2016-11-01 07:37:18 +13:00
|
|
|
return Object.assign({}, mopidy, {
|
2016-11-02 16:51:00 +13:00
|
|
|
directory: action.data
|
2016-11-01 07:37:18 +13:00
|
|
|
});
|
|
|
|
|
|
2017-08-12 23:01:55 +12:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Library
|
|
|
|
|
**/
|
|
|
|
|
|
|
|
|
|
case 'MOPIDY_LIBRARY_PLAYLISTS_LOADED':
|
|
|
|
|
if (mopidy.library_playlists){
|
|
|
|
|
var uris = [...mopidy.library_playlists,...action.uris]
|
|
|
|
|
} else {
|
|
|
|
|
var uris = action.uris
|
|
|
|
|
}
|
2017-08-16 12:40:27 +12:00
|
|
|
return Object.assign({}, mopidy, { library_playlists: helpers.removeDuplicates(uris) })
|
2017-08-12 23:01:55 +12:00
|
|
|
|
2017-09-14 21:05:55 +12:00
|
|
|
case 'MOPIDY_LIBRARY_PLAYLISTS_LOADED_ALL':
|
|
|
|
|
return Object.assign({}, mopidy, { library_playlists_loaded_all: true })
|
|
|
|
|
|
2017-08-22 20:44:36 +12:00
|
|
|
case 'MOPIDY_LIBRARY_PLAYLIST_CREATED':
|
|
|
|
|
var library_playlists = []
|
|
|
|
|
if (mopidy.library_playlists){
|
|
|
|
|
library_playlists = Object.assign([], mopidy.library_playlists)
|
|
|
|
|
library_playlists.push(action.key)
|
|
|
|
|
}
|
|
|
|
|
return Object.assign({}, mopidy, { library_playlists: library_playlists })
|
|
|
|
|
|
|
|
|
|
case 'MOPIDY_LIBRARY_PLAYLIST_DELETED':
|
|
|
|
|
var library_playlists = []
|
|
|
|
|
if (mopidy.library_playlists){
|
|
|
|
|
library_playlists = Object.assign([], mopidy.library_playlists)
|
|
|
|
|
library_playlists.splice(library_playlists.indexOf(action.uri), 1)
|
|
|
|
|
}
|
|
|
|
|
return Object.assign({}, mopidy, { library_playlists: library_playlists })
|
|
|
|
|
|
2017-08-12 23:01:55 +12:00
|
|
|
case 'MOPIDY_LIBRARY_ARTISTS_LOADED':
|
|
|
|
|
if (mopidy.library_artists){
|
|
|
|
|
var uris = [...mopidy.library_artists,...action.uris]
|
|
|
|
|
} else {
|
|
|
|
|
var uris = action.uris
|
|
|
|
|
}
|
2017-08-16 12:40:27 +12:00
|
|
|
return Object.assign({}, mopidy, { library_artists: helpers.removeDuplicates(uris) })
|
2017-08-12 23:01:55 +12:00
|
|
|
|
|
|
|
|
case 'MOPIDY_LIBRARY_ALBUMS_LOADED':
|
|
|
|
|
if (mopidy.library_albums){
|
|
|
|
|
var uris = [...mopidy.library_albums,...action.uris]
|
|
|
|
|
} else {
|
|
|
|
|
var uris = action.uris
|
|
|
|
|
}
|
2017-08-16 12:40:27 +12:00
|
|
|
return Object.assign({}, mopidy, { library_albums: helpers.removeDuplicates(uris) })
|
2017-08-15 16:36:50 +12:00
|
|
|
|
2017-08-31 21:13:10 +12:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 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 = {}
|
|
|
|
|
}
|
|
|
|
|
|
2017-09-04 21:04:11 +12:00
|
|
|
if (search_results[action.context]){
|
2017-08-31 21:13:10 +12:00
|
|
|
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 });
|
|
|
|
|
|
2016-10-14 22:42:45 +13:00
|
|
|
default:
|
|
|
|
|
return mopidy
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|