Files
Iris/src/js/bootstrap.js

115 lines
3.4 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 geniusMiddleware from './services/genius/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: {
outputs: [],
2017-11-10 15:56:01 +13:00
queue: [],
queue_metadata: {},
current_track: null,
albums: {},
artists: {},
playlists: {},
users: {},
tracks: {},
http_streaming_enabled: false,
2018-07-02 21:37:24 +12:00
http_streaming_cachebuster: null,
http_streaming_url: "http://"+window.location.hostname+":8000/mopidy"
},
ui: {
2018-08-24 16:10:41 +12:00
theme: 'dark',
shortkeys_enabled: true,
2018-06-18 08:38:03 +12:00
allow_reporting: 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: null,
uri_schemes: [],
library_albums_uri: 'local:directory?type=album',
library_artists_uri: 'local:directory?type=artist'
},
2016-10-27 16:58:11 +13:00
pusher: {
connected: false,
username: null,
2017-02-19 21:27:43 +13:00
connections: {},
version: {
current: '0.0.0'
2018-03-26 10:36:13 +13:00
},
config: {}
2016-10-27 16:58:11 +13:00
},
2016-11-07 21:21:15 +13:00
lastfm: {
me: null,
authorization_url: 'https://jamesbarnsley.co.nz/iris/auth_lastfm.php'
},
2018-06-27 20:30:04 +12:00
genius: {
me: null,
authorization_url: 'https://jamesbarnsley.co.nz/iris/auth_genius.php'
2018-06-26 21:44:51 +12:00
},
spotify: {
me: null,
autocomplete_results: {},
authorization_url: 'https://jamesbarnsley.co.nz/iris/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'));
initialState.genius = Object.assign({}, initialState.genius, helpers.getStorage('genius'));
console.log('Bootstrapping', initialState)
let store = createStore(
reducers,
initialState,
applyMiddleware(thunk, localstorageMiddleware, coreMiddleware, uiMiddleware, mopidyMiddleware, pusherMiddleware, spotifyMiddleware, lastfmMiddleware, geniusMiddleware)
);
2016-10-03 15:22:15 +13:00
export default store;