2016-10-03 15:22:15 +13:00
|
|
|
|
2016-10-16 12:37:37 +13:00
|
|
|
import { createStore, applyMiddleware, combineReducers } from 'redux'
|
|
|
|
|
|
2017-08-02 10:53:30 +12:00
|
|
|
import core from './services/core/reducer'
|
2016-10-27 10:02:12 +13:00
|
|
|
import ui from './services/ui/reducer'
|
2016-10-27 16:58:11 +13:00
|
|
|
import pusher from './services/pusher/reducer'
|
2016-10-16 12:37:37 +13:00
|
|
|
import mopidy from './services/mopidy/reducer'
|
2016-11-07 21:21:15 +13:00
|
|
|
import lastfm from './services/lastfm/reducer'
|
2016-10-16 12:37:37 +13:00
|
|
|
import spotify from './services/spotify/reducer'
|
2017-10-04 16:47:15 +13:00
|
|
|
import genius from './services/genius/reducer'
|
2016-10-16 12:37:37 +13:00
|
|
|
|
2016-10-14 22:42:45 +13:00
|
|
|
import thunk from 'redux-thunk'
|
2017-08-02 10:53:30 +12:00
|
|
|
import coreMiddleware from './services/core/middleware'
|
2016-11-11 16:47:32 +13:00
|
|
|
import uiMiddleware from './services/ui/middleware'
|
2016-10-27 16:58:11 +13:00
|
|
|
import pusherMiddleware from './services/pusher/middleware'
|
2016-10-14 22:42:45 +13:00
|
|
|
import mopidyMiddleware from './services/mopidy/middleware'
|
2016-10-16 12:37:37 +13:00
|
|
|
import spotifyMiddleware from './services/spotify/middleware'
|
2016-10-17 22:00:29 +13:00
|
|
|
import localstorageMiddleware from './services/localstorage/middleware'
|
2016-10-16 12:37:37 +13:00
|
|
|
|
|
|
|
|
let reducers = combineReducers({
|
2017-08-02 10:53:30 +12:00
|
|
|
core,
|
2016-10-27 10:02:12 +13:00
|
|
|
ui,
|
2016-10-27 16:58:11 +13:00
|
|
|
pusher,
|
2016-10-16 12:37:37 +13:00
|
|
|
mopidy,
|
2016-11-07 21:21:15 +13:00
|
|
|
lastfm,
|
2017-10-04 16:47:15 +13:00
|
|
|
genius,
|
2016-10-16 12:37:37 +13:00
|
|
|
spotify
|
|
|
|
|
});
|
2016-10-03 15:22:15 +13:00
|
|
|
|
2016-10-18 08:56:53 +13:00
|
|
|
// set application defaults
|
2016-10-28 09:14:29 +13:00
|
|
|
// TODO: Look at using propTypes in the component for these falsy initial states
|
2016-10-18 08:56:53 +13:00
|
|
|
var initialState = {
|
2017-08-02 10:53:30 +12:00
|
|
|
core: {
|
|
|
|
|
current_tracklist: [],
|
2017-08-10 12:00:08 +12:00
|
|
|
current_tltrack: false,
|
|
|
|
|
albums: {},
|
2017-09-25 20:22:48 +13:00
|
|
|
artists: {},
|
2017-08-10 12:00:08 +12:00
|
|
|
playlists: {},
|
2017-09-25 20:22:48 +13:00
|
|
|
users: {},
|
|
|
|
|
tracks: {}
|
2017-08-02 10:53:30 +12:00
|
|
|
},
|
|
|
|
|
ui: {
|
|
|
|
|
slim_mode: false,
|
|
|
|
|
selected_tracks: [],
|
2017-08-10 12:00:08 +12:00
|
|
|
notifications: [],
|
|
|
|
|
processes: {}
|
2017-08-02 10:53:30 +12:00
|
|
|
},
|
2016-10-18 08:56:53 +13:00
|
|
|
mopidy: {
|
2016-10-28 09:14:29 +13:00
|
|
|
connected: false,
|
2016-10-18 08:56:53 +13:00
|
|
|
host: window.location.hostname,
|
2017-06-11 20:39:31 +12:00
|
|
|
port: (window.location.port ? window.location.port : (window.location.protocol === 'https:' ? '443' : '80')),
|
2017-05-19 11:33:06 +12:00
|
|
|
mute: false,
|
2016-10-20 17:40:18 +13:00
|
|
|
volume: 0,
|
2016-11-09 13:18:03 +13:00
|
|
|
progress: 0,
|
|
|
|
|
play_state: false
|
2016-10-18 21:57:29 +13:00
|
|
|
},
|
2016-10-27 16:58:11 +13:00
|
|
|
pusher: {
|
2016-10-28 09:14:29 +13:00
|
|
|
connected: false,
|
2017-01-04 15:24:13 +13:00
|
|
|
username: 'Anonymous',
|
2017-02-19 21:27:43 +13:00
|
|
|
connections: {},
|
2016-10-29 22:40:02 +13:00
|
|
|
version: {
|
|
|
|
|
current: '0.0.0'
|
|
|
|
|
}
|
2016-10-27 16:58:11 +13:00
|
|
|
},
|
2016-11-07 21:21:15 +13:00
|
|
|
lastfm: {
|
2017-10-04 16:47:15 +13:00
|
|
|
connected: false
|
|
|
|
|
},
|
|
|
|
|
genius: {
|
|
|
|
|
connected: false
|
2016-11-07 21:21:15 +13:00
|
|
|
},
|
2016-10-18 21:57:29 +13:00
|
|
|
spotify: {
|
2016-10-28 09:14:29 +13:00
|
|
|
connected: false,
|
2017-05-12 05:22:57 +12:00
|
|
|
me: false,
|
2017-08-02 10:53:30 +12:00
|
|
|
autocomplete_results: {},
|
|
|
|
|
authorization_url: 'https://jamesbarnsley.co.nz/auth_v2.php'
|
2016-10-18 08:56:53 +13:00
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2017-08-02 10:53:30 +12:00
|
|
|
// if we've got a stored version of spotify state, load and merge
|
2017-10-10 13:05:28 +13:00
|
|
|
if (localStorage.getItem('core')){
|
|
|
|
|
var storedCore = JSON.parse(localStorage.getItem('core') );
|
2017-08-02 10:53:30 +12:00
|
|
|
initialState.core = Object.assign(initialState.core, storedCore );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// if we've got a stored version of spotify state, load and merge
|
2017-10-10 13:05:28 +13:00
|
|
|
if (localStorage.getItem('ui')){
|
|
|
|
|
var storedUi = JSON.parse(localStorage.getItem('ui') );
|
2017-08-02 10:53:30 +12:00
|
|
|
initialState.ui = Object.assign(initialState.ui, storedUi );
|
|
|
|
|
}
|
|
|
|
|
|
2016-10-18 08:56:53 +13:00
|
|
|
// if we've got a stored version of mopidy state, load and merge
|
2017-10-10 13:05:28 +13:00
|
|
|
if (localStorage.getItem('mopidy')){
|
|
|
|
|
var storedMopidy = JSON.parse(localStorage.getItem('mopidy') );
|
2016-10-19 14:09:34 +13:00
|
|
|
initialState.mopidy = Object.assign(initialState.mopidy, storedMopidy );
|
2016-10-17 10:39:11 +13:00
|
|
|
}
|
|
|
|
|
|
2016-10-27 16:58:11 +13:00
|
|
|
// if we've got a stored version of pusher state, load and merge
|
2017-10-10 13:05:28 +13:00
|
|
|
if (localStorage.getItem('pusher')){
|
|
|
|
|
var storedPusher = JSON.parse(localStorage.getItem('pusher') );
|
2016-10-27 16:58:11 +13:00
|
|
|
initialState.pusher = Object.assign(initialState.pusher, storedPusher );
|
|
|
|
|
}
|
|
|
|
|
|
2016-10-18 16:53:33 +13:00
|
|
|
// if we've got a stored version of spotify state, load and merge
|
2017-10-10 13:05:28 +13:00
|
|
|
if (localStorage.getItem('spotify')){
|
|
|
|
|
var storedSpotify = JSON.parse(localStorage.getItem('spotify') );
|
2016-10-19 14:09:34 +13:00
|
|
|
initialState.spotify = Object.assign(initialState.spotify, storedSpotify );
|
2016-10-18 16:53:33 +13:00
|
|
|
}
|
|
|
|
|
|
2016-11-07 18:09:42 +13:00
|
|
|
console.log('Bootstrapping', initialState)
|
|
|
|
|
|
2016-10-14 22:42:45 +13:00
|
|
|
let store = createStore(
|
2016-10-16 12:37:37 +13:00
|
|
|
reducers,
|
2016-10-17 10:39:11 +13:00
|
|
|
initialState,
|
2017-10-10 13:05:28 +13:00
|
|
|
applyMiddleware(thunk, localstorageMiddleware, coreMiddleware, uiMiddleware, mopidyMiddleware, pusherMiddleware, spotifyMiddleware )
|
2016-10-14 22:42:45 +13:00
|
|
|
);
|
2016-10-03 16:55:33 +13:00
|
|
|
|
2016-10-03 15:22:15 +13:00
|
|
|
export default store;
|