Skip to content

Commit

Permalink
Not requiring spotipy; Moving core into new service
Browse files Browse the repository at this point in the history
  • Loading branch information
jaedb committed Aug 1, 2017
1 parent fc4780d commit 0c13445
Show file tree
Hide file tree
Showing 38 changed files with 1,309 additions and 1,274 deletions.
1 change: 0 additions & 1 deletion setup.py
Expand Up @@ -22,7 +22,6 @@ def get_version(filename):
install_requires=[
'setuptools >= 3.3',
'pylast >= 1.6.0',
'spotipy >= 2.3.8',
'Mopidy >= 2.0',
'Mopidy-Local-Images >= 1.0',
'ConfigObj >= 5.0.6'
Expand Down
8 changes: 4 additions & 4 deletions src/js/App.js
Expand Up @@ -15,6 +15,7 @@ import Notifications from './components/Notifications'
import DebugInfo from './components/DebugInfo'

import * as helpers from './helpers'
import * as coreActions from './services/core/actions'
import * as uiActions from './services/ui/actions'
import * as pusherActions from './services/pusher/actions'
import * as mopidyActions from './services/mopidy/actions'
Expand Down Expand Up @@ -46,10 +47,8 @@ class App extends React.Component{
}

componentDidMount(){
this.props.pusherActions.connect()
this.props.mopidyActions.connect()
this.props.spotifyActions.connect()
this.props.uiActions.getBroadcasts()
this.props.coreActions.startServices()
this.props.coreActions.getBroadcasts()

if (this.props.spotify_authorized){

Expand Down Expand Up @@ -295,6 +294,7 @@ const mapStateToProps = (state, ownProps) => {

const mapDispatchToProps = (dispatch) => {
return {
coreActions: bindActionCreators(coreActions, dispatch),
uiActions: bindActionCreators(uiActions, dispatch),
pusherActions: bindActionCreators(pusherActions, dispatch),
mopidyActions: bindActionCreators(mopidyActions, dispatch),
Expand Down
45 changes: 27 additions & 18 deletions src/js/bootstrap.js
@@ -1,20 +1,23 @@

import { createStore, applyMiddleware, combineReducers } from 'redux'

import core from './services/core/reducer'
import ui from './services/ui/reducer'
import pusher from './services/pusher/reducer'
import mopidy from './services/mopidy/reducer'
import lastfm from './services/lastfm/reducer'
import spotify from './services/spotify/reducer'

import thunk from 'redux-thunk'
import coreMiddleware from './services/core/middleware'
import uiMiddleware from './services/ui/middleware'
import pusherMiddleware from './services/pusher/middleware'
import mopidyMiddleware from './services/mopidy/middleware'
import spotifyMiddleware from './services/spotify/middleware'
import localstorageMiddleware from './services/localstorage/middleware'

let reducers = combineReducers({
core,
ui,
pusher,
mopidy,
Expand All @@ -25,6 +28,15 @@ let reducers = combineReducers({
// set application defaults
// TODO: Look at using propTypes in the component for these falsy initial states
var initialState = {
core: {
current_tracklist: [],
current_tltrack: false
},
ui: {
slim_mode: false,
selected_tracks: [],
notifications: []
},
mopidy: {
connected: false,
host: window.location.hostname,
Expand All @@ -50,20 +62,23 @@ var initialState = {
spotify: {
connected: false,
me: false,
autocomplete_results: {}
},
ui: {
slim_mode: false,
current_tracklist: [],
current_tltrack: false,
selected_tracks: [],
notifications: [],
config: {
authorization_url: 'https://jamesbarnsley.co.nz/auth_v2.php'
}
autocomplete_results: {},
authorization_url: 'https://jamesbarnsley.co.nz/auth_v2.php'
}
};

// if we've got a stored version of spotify state, load and merge
if( localStorage.getItem('core') ){
var storedCore = JSON.parse( localStorage.getItem('core') );
initialState.core = Object.assign(initialState.core, storedCore );
}

// if we've got a stored version of spotify state, load and merge
if( localStorage.getItem('ui') ){
var storedUi = JSON.parse( localStorage.getItem('ui') );
initialState.ui = Object.assign(initialState.ui, storedUi );
}

// if we've got a stored version of mopidy state, load and merge
if( localStorage.getItem('mopidy') ){
var storedMopidy = JSON.parse( localStorage.getItem('mopidy') );
Expand All @@ -82,18 +97,12 @@ if( localStorage.getItem('spotify') ){
initialState.spotify = Object.assign(initialState.spotify, storedSpotify );
}

// if we've got a stored version of spotify state, load and merge
if( localStorage.getItem('ui') ){
var storedUi = JSON.parse( localStorage.getItem('ui') );
initialState.ui = Object.assign(initialState.ui, storedUi );
}

console.log('Bootstrapping', initialState)

let store = createStore(
reducers,
initialState,
applyMiddleware( thunk, localstorageMiddleware, uiMiddleware, mopidyMiddleware, pusherMiddleware, spotifyMiddleware )
applyMiddleware( thunk, localstorageMiddleware, coreMiddleware, uiMiddleware, mopidyMiddleware, pusherMiddleware, spotifyMiddleware )
);

export default store;
12 changes: 6 additions & 6 deletions src/js/components/ContextMenu.js
Expand Up @@ -575,12 +575,12 @@ class ContextMenu extends React.Component{
const mapStateToProps = (state, ownProps) => {
return {
menu: state.ui.context_menu,
current_track: state.ui.current_track,
current_tracklist: state.ui.current_tracklist,
library_artists: state.ui.library_artists,
library_albums: state.ui.library_albums,
library_playlists: state.ui.library_playlists,
playlists: state.ui.playlists,
current_track: state.core.current_track,
current_tracklist: state.core.current_tracklist,
library_artists: state.core.library_artists,
library_albums: state.core.library_albums,
library_playlists: state.core.library_playlists,
playlists: state.core.playlists,
spotify_authorized: state.spotify.authorized
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/js/components/DebugInfo.js
Expand Up @@ -66,7 +66,7 @@ class DebugInfo extends React.Component{
Playlists: {this.props.ui.playlists ? Object.keys(this.props.ui.playlists).length : '0'}
</div>
<div className="item">
Tracks: {this.props.ui.tracks ? Object.keys(this.props.ui.tracks).length : '0'}
Tracks: {this.props.core.tracks ? Object.keys(this.props.core.tracks).length : '0'}
</div>
<div className="item">
Users: {this.props.ui.users ? Object.keys(this.props.ui.users).length : '0'}
Expand Down
4 changes: 2 additions & 2 deletions src/js/components/FullPlayer.js
Expand Up @@ -145,8 +145,8 @@ class FullPlayer extends React.Component{
const mapStateToProps = (state, ownProps) => {
return {
radio_enabled: (state.ui.radio && state.ui.radio.enabled ? true : false),
tracks: state.ui.tracks,
current_track: (typeof(state.ui.current_track) !== 'undefined' && typeof(state.ui.tracks) !== 'undefined' && typeof(state.ui.tracks[state.ui.current_track.uri]) !== 'undefined' ? state.ui.tracks[state.ui.current_track.uri] : null),
tracks: state.core.tracks,
current_track: (typeof(state.core.current_track) !== 'undefined' && typeof(state.core.tracks) !== 'undefined' && typeof(state.core.tracks[state.core.current_track.uri]) !== 'undefined' ? state.core.tracks[state.core.current_track.uri] : null),
play_state: state.mopidy.play_state,
time_position: state.mopidy.time_position,
consume: state.mopidy.consume,
Expand Down
2 changes: 1 addition & 1 deletion src/js/components/MiniPlayer.js
Expand Up @@ -66,7 +66,7 @@ class MiniPlayer extends React.Component{

const mapStateToProps = (state, ownProps) => {
return {
current_track: (typeof(state.ui.current_track) !== 'undefined' && typeof(state.ui.tracks) !== 'undefined' && typeof(state.ui.tracks[state.ui.current_track.uri]) !== 'undefined' ? state.ui.tracks[state.ui.current_track.uri] : null),
current_track: (typeof(state.core.current_track) !== 'undefined' && typeof(state.core.tracks) !== 'undefined' && typeof(state.core.tracks[state.core.current_track.uri]) !== 'undefined' ? state.core.tracks[state.core.current_track.uri] : null),
play_state: state.mopidy.play_state
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/js/components/Modal/Modal.js
Expand Up @@ -66,14 +66,14 @@ class Modal extends React.Component{

const mapStateToProps = (state, ownProps) => {
return {
current_track: (typeof(state.ui.current_track) !== 'undefined' && typeof(state.ui.tracks) !== 'undefined' && typeof(state.ui.tracks[state.ui.current_track.uri]) !== 'undefined' ? state.ui.tracks[state.ui.current_track.uri] : null),
current_track: (typeof(state.core.current_track) !== 'undefined' && typeof(state.core.tracks) !== 'undefined' && typeof(state.core.tracks[state.core.current_track.uri]) !== 'undefined' ? state.core.tracks[state.core.current_track.uri] : null),
uri_schemes: (state.mopidy.uri_schemes ? state.mopidy.uri_schemes : null),
search_settings: (state.ui.search_settings ? state.ui.search_settings : null),
volume: state.mopidy.volume,
mute: state.mopidy.mute,
modal: state.ui.modal,
radio: state.ui.radio,
tracks: state.ui.tracks,
tracks: state.core.tracks,
artists: state.ui.artists,
playlists: state.ui.playlists,
context_menu: state.ui.context_menu,
Expand Down
2 changes: 1 addition & 1 deletion src/js/components/PlaybackControls.js
Expand Up @@ -143,7 +143,7 @@ class PlaybackControls extends React.Component{

const mapStateToProps = (state, ownProps) => {
return {
current_track: (typeof(state.ui.current_track) !== 'undefined' && typeof(state.ui.tracks) !== 'undefined' && typeof(state.ui.tracks[state.ui.current_track.uri]) !== 'undefined' ? state.ui.tracks[state.ui.current_track.uri] : null),
current_track: (state.core.current_track !== undefined && state.core.tracks !== undefined && state.core.tracks[state.core.current_track.uri] !== undefined ? state.core.tracks[state.core.current_track.uri] : null),
radio_enabled: (state.ui.radio && state.ui.radio.enabled ? true : false),
play_state: state.mopidy.play_state,
time_position: state.mopidy.time_position,
Expand Down
2 changes: 1 addition & 1 deletion src/js/components/ProgressSlider.js
Expand Up @@ -53,7 +53,7 @@ class ProgressSlider extends React.Component{

const mapStateToProps = (state, ownProps) => {
return {
current_track: (typeof(state.ui.current_track) !== 'undefined' && typeof(state.ui.tracks) !== 'undefined' && typeof(state.ui.tracks[state.ui.current_track.uri]) !== 'undefined' ? state.ui.tracks[state.ui.current_track.uri] : null),
current_track: (typeof(state.core.current_track) !== 'undefined' && typeof(state.core.tracks) !== 'undefined' && typeof(state.core.tracks[state.core.current_track.uri]) !== 'undefined' ? state.core.tracks[state.core.current_track.uri] : null),
connected: state.mopidy.connected,
time_position: state.mopidy.time_position,
play_state: state.mopidy.play_state
Expand Down
2 changes: 1 addition & 1 deletion src/js/components/SpotifyAuthenticationFrame.js
Expand Up @@ -146,7 +146,7 @@ class SpotifyAuthenticationFrame extends React.Component{

const mapStateToProps = (state, ownProps) => {
return {
authorization_url: state.ui.config.authorization_url,
authorization_url: state.spotify.authorization_url,
authorized: state.spotify.authorized,
authorizing: state.spotify.authorizing,
refreshing_token: state.spotify.refreshing_token
Expand Down
2 changes: 1 addition & 1 deletion src/js/components/TrackList.js
Expand Up @@ -421,7 +421,7 @@ const mapStateToProps = (state, ownProps) => {
selected_tracks: state.ui.selected_tracks,
slim_mode: state.ui.slim_mode,
dragger: state.ui.dragger,
current_track: state.ui.current_track,
current_track: state.core.current_track,
context_menu: state.ui.context_menu
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/js/helpers.js
Expand Up @@ -97,8 +97,8 @@ export let getTrackIcon = function(current_track = false, ui = false){
if (!ui) return false
if (!current_track) return false
if (typeof(current_track.uri) == 'undefined') return false
if (typeof(ui.tracks[current_track.uri]) === 'undefined') return false
var track = ui.tracks[current_track.uri]
if (typeof(core.tracks[current_track.uri]) === 'undefined') return false
var track = core.tracks[current_track.uri]
if (!track.album) return false
if (!track.album.images) return false
return sizedImages(track.album.images).small
Expand Down

0 comments on commit 0c13445

Please sign in to comment.