Files
Iris/src/js/bootstrap.js

107 lines
3.0 KiB
JavaScript
Raw Normal View History

2016-10-03 15:22:15 +13:00
import { createStore, applyMiddleware, combineReducers } from 'redux'
import * as helpers from './helpers'
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'
import mopidy from './services/mopidy/reducer'
2016-11-07 21:21:15 +13:00
import lastfm from './services/lastfm/reducer'
import spotify from './services/spotify/reducer'
import genius from './services/genius/reducer'
import thunk from 'redux-thunk'
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'
import mopidyMiddleware from './services/mopidy/middleware'
import lastfmMiddleware from './services/lastfm/middleware'
import spotifyMiddleware from './services/spotify/middleware'
import localstorageMiddleware from './services/localstorage/middleware'
let reducers = combineReducers({
core,
2016-10-27 10:02:12 +13:00
ui,
2016-10-27 16:58:11 +13:00
pusher,
mopidy,
2016-11-07 21:21:15 +13:00
lastfm,
genius,
spotify
});
2016-10-03 15:22:15 +13:00
2016-10-18 08:56:53 +13:00
// set application defaults
// TODO: Look at using propTypes in the component for these falsy initial states
2016-10-18 08:56:53 +13:00
var initialState = {
core: {
2017-11-10 15:56:01 +13:00
queue: [],
queue_metadata: {},
current_track_uri: null,
albums: {},
artists: {},
playlists: {},
users: {},
tracks: {},
http_streaming_enabled: false,
2018-02-02 08:39:37 +13:00
http_streaming_encoding: 'mpeg',
http_streaming_url: "http://"+window.location.hostname+":8000/mopidy"
},
ui: {
2018-02-01 08:06:40 +13:00
show_initial_setup: true,
slim_mode: false,
selected_tracks: [],
notifications: [],
processes: {}
},
2016-10-18 08:56:53 +13:00
mopidy: {
connected: false,
2016-10-18 08:56:53 +13:00
host: window.location.hostname,
port: (window.location.port ? window.location.port : (window.location.protocol === 'https:' ? '443' : '80')),
ssl: (window.location.protocol === 'https:' ? true : false),
2017-05-19 11:33:06 +12:00
mute: false,
volume: 0,
progress: 0,
play_state: false
},
2016-10-27 16:58:11 +13:00
pusher: {
connected: false,
2018-02-01 08:06:40 +13:00
username: false,
2017-02-19 21:27:43 +13:00
connections: {},
version: {
current: '0.0.0'
}
2016-10-27 16:58:11 +13:00
},
2016-11-07 21:21:15 +13:00
lastfm: {
2017-11-02 21:20:56 +13:00
connected: false,
me: false,
authorization_url: 'https://jamesbarnsley.co.nz/auth_lastfm.php'
},
genius: {
connected: false
2016-11-07 21:21:15 +13:00
},
spotify: {
connected: false,
2017-05-12 05:22:57 +12:00
me: false,
autocomplete_results: {},
2017-11-02 21:20:56 +13:00
authorization_url: 'https://jamesbarnsley.co.nz/auth_spotify.php'
2016-10-18 08:56:53 +13:00
}
};
2017-11-23 17:43:29 +13:00
// load all our stored values from LocalStorage
initialState.core = Object.assign({}, initialState.core, helpers.getStorage('core'));
initialState.ui = Object.assign({}, initialState.ui, helpers.getStorage('ui'));
initialState.mopidy = Object.assign({}, initialState.mopidy, helpers.getStorage('mopidy'));
initialState.pusher = Object.assign({}, initialState.pusher, helpers.getStorage('pusher'));
initialState.spotify = Object.assign({}, initialState.spotify, helpers.getStorage('spotify'));
initialState.lastfm = Object.assign({}, initialState.lastfm, helpers.getStorage('lastfm'));
console.log('Bootstrapping', initialState)
let store = createStore(
reducers,
initialState,
applyMiddleware(thunk, localstorageMiddleware, coreMiddleware, uiMiddleware, mopidyMiddleware, pusherMiddleware, spotifyMiddleware, lastfmMiddleware )
);
2016-10-03 15:22:15 +13:00
export default store;