Using universal tracks index instead of current_track

This commit is contained in:
James Barnsley
2017-06-07 08:28:54 +12:00
parent bc1d173ab2
commit 065d4e0a63
5 changed files with 19 additions and 7 deletions

View File

@ -146,7 +146,7 @@ const mapStateToProps = (state, ownProps) => {
return {
radio_enabled: (state.ui.radio && state.ui.radio.enabled ? true : false),
tracks: state.ui.tracks,
current_track: state.ui.current_track,
current_track: (typeof(state.ui.current_track) !== 'undefined' && typeof(state.ui.tracks) !== 'undefined' && typeof(state.ui.tracks[state.ui.current_track]) !== 'undefined' ? state.ui.tracks[state.ui.current_track] : null),
play_state: state.mopidy.play_state,
time_position: state.mopidy.time_position,
consume: state.mopidy.consume,

View File

@ -59,7 +59,7 @@ class MiniPlayer extends React.Component{
const mapStateToProps = (state, ownProps) => {
return {
current_track: state.ui.current_track,
current_track: (typeof(state.ui.current_track) !== 'undefined' && typeof(state.ui.tracks) !== 'undefined' && typeof(state.ui.tracks[state.ui.current_track]) !== 'undefined' ? state.ui.tracks[state.ui.current_track] : null),
play_state: state.mopidy.play_state
}
}

View File

@ -112,8 +112,8 @@ const mapStateToProps = (state, ownProps) => {
mopidy_connected: state.mopidy.connected,
pusher_connected: state.pusher.connected,
spotify_connected: state.spotify.connected,
spotify_authorized: state.spotify.authorized,
current_track: state.ui.current_track,
spotify_authorized: state.spotify.authorized,
current_track: (typeof(state.ui.current_track) !== 'undefined' && typeof(state.ui.tracks) !== 'undefined' && typeof(state.ui.tracks[state.ui.current_track]) !== 'undefined' ? state.ui.tracks[state.ui.current_track] : null),
dragger: state.ui.dragger
}
}

View File

@ -14,7 +14,18 @@ const localstorageMiddleware = (function(){
window._store = store
// if debug enabled
if (store.getState().ui.log_actions) console.log(action)
if (store.getState().ui.log_actions){
var ignored_actions = [
'START_LOADING',
'STOP_LOADING'
]
// Show non-ignored actions
if (!ignored_actions.includes(action.type)){
console.log(action)
}
}
switch( action.type ){

View File

@ -118,8 +118,7 @@ export default function reducer(ui = {}, action){
)
}
var current_track = action.data.track
Object.assign(current_track, { tlid: action.data.tlid })
var current_track = action.data.track.uri
return Object.assign({}, ui, {
current_track: current_track
@ -410,6 +409,8 @@ export default function reducer(ui = {}, action){
**/
case 'TRACK_LOADED':
if (!action.key || !action.track) return ui
var tracks = Object.assign({}, ui.tracks)
if (tracks[action.key]){