Config includes spotify-user for rendering in Settings

This commit is contained in:
James Barnsley
2017-02-06 13:00:21 +13:00
parent 94c947e90e
commit 93eabe59c2
8 changed files with 35 additions and 26 deletions

View File

@ -192,10 +192,11 @@ class IrisFrontend(pykka.ThreadingActor, CoreListener):
# get our config values
def get_config( self ):
iris = self.config['iris']
all_config = self.config
config = {
"country": iris['country'],
"locale": iris['locale']
"spotify_user": all_config['spotify']['username'],
"country": all_config['iris']['country'],
"locale": all_config['iris']['locale']
}
return config

View File

@ -116,19 +116,23 @@ const PusherMiddleware = (function(){
request({ action: 'get_config' })
.then(
response => {
store.dispatch({ type: 'CONFIG', data: response.data })
store.dispatch({ type: 'CONFIG', config: response.data.config })
var spotify = store.getState().spotify
if (!spotify.country || !spotify.locale){
store.dispatch({ type: 'SPOTIFY_SET_CONFIG', config: response.data.config })
}
}
)
request({ action: 'get_version' })
.then(
response => {
store.dispatch({ type: 'VERSION', data: response.data })
store.dispatch({ type: 'VERSION', version: response.data.version })
}
)
request({ action: 'get_radio' })
.then(
response => {
store.dispatch({ type: 'RADIO', data: response.data })
store.dispatch({ type: 'RADIO', radio: response.data.radio })
}
)
return next(action);
@ -147,7 +151,7 @@ const PusherMiddleware = (function(){
}else{
store.dispatch( uiActions.createNotification('Upgrade failed, please upgrade manually','bad') )
}
store.dispatch({ type: 'VERSION', data: response.data })
store.dispatch({ type: 'VERSION', version: response.data.version })
}
)
return next(action);

View File

@ -39,7 +39,7 @@ export default function reducer(pusher = {}, action){
case 'VERSION':
return Object.assign({}, pusher, {
version: action.data.version,
version: action.version,
upgrading: false
});

View File

@ -100,6 +100,7 @@ function refreshToken( dispatch, getState ){
},
error => {
dispatch({ type: 'SPOTIFY_DISCONNECTED' })
dispatch(uiActions.createNotification('Could not refresh token','bad'))
console.error('Could not refresh token', error)
reject(error)
}
@ -126,6 +127,7 @@ function refreshToken( dispatch, getState ){
},
error => {
dispatch({ type: 'SPOTIFY_DISCONNECTED' })
dispatch(uiActions.createNotification('Could not refresh token','bad'))
console.error('Could not refresh token', error)
reject(error)
}

View File

@ -13,20 +13,10 @@ const SpotifyMiddleware = (function(){
switch(action.type){
case 'CONFIG':
if (!state.spotify.country || !state.spotify.locale){
store.dispatch( spotifyActions.setConfig(action.data.config) )
}
break
case 'SPOTIFY_CONNECT':
store.dispatch( spotifyActions.getMe() )
break
case 'SPOTIFY_DISCONNECTED':
store.dispatch( uiActions.createNotification('Spotify disconnected','bad') )
break
case 'SPOTIFY_CREATE_PLAYLIST':
if( !store.getState().spotify.authorized ){
store.dispatch( uiActions.createNotification( "Must be logged in to Spotify to do that", 'bad' ) )
@ -103,8 +93,8 @@ const SpotifyMiddleware = (function(){
next(action)
// only resolve if radio is enabled
if( action.data.radio.enabled ){
store.dispatch(spotifyActions.resolveRadioSeeds(action.data.radio))
if( action.radio.enabled ){
store.dispatch(spotifyActions.resolveRadioSeeds(action.radio))
}
break

View File

@ -202,9 +202,9 @@ const UIMiddleware = (function(){
next(action)
break
case 'PUSHER_VERSION':
if( action.data.version.upgrade_available )
store.dispatch( uiActions.createNotification( 'Version '+action.data.version.latest+' is available. See settings to upgrade.' ) )
case 'VERSION':
if( action.version.upgrade_available )
store.dispatch( uiActions.createNotification( 'Version '+action.version.latest+' is available. See settings to upgrade.' ) )
next( action )
break

View File

@ -13,6 +13,9 @@ export default function reducer(ui = {}, action){
case 'UI_SET':
return Object.assign({}, ui, action.data)
case 'CONFIG':
return Object.assign({}, ui, { config: action.config })
case 'TOGGLE_SIDEBAR':
var new_state = !ui.sidebar_open
if( typeof(action.new_state) !== 'undefined' ) new_state = action.new_state
@ -118,7 +121,7 @@ export default function reducer(ui = {}, action){
case 'RADIO':
case 'START_RADIO':
return Object.assign({}, ui, { seeds_resolved: false }, { radio: action.data.radio })
return Object.assign({}, ui, { seeds_resolved: false }, { radio: action.radio })
case 'RADIO_SEEDS_RESOLVED':
var radio = Object.assign({}, ui.radio, { resolved_seeds: action.resolved_seeds })

View File

@ -81,7 +81,7 @@ class Settings extends React.Component{
}
renderSpotifyUser(){
if( this.props.spotify.me && this.props.spotify.authorized ){
if (this.props.spotify.me && this.props.spotify.authorized){
return (
<Link className="user" to={global.baseURL+'user/'+this.props.spotify.me.uri}>
<Thumbnail circle={true} size="small" images={this.props.spotify.me.images} />
@ -90,7 +90,16 @@ class Settings extends React.Component{
</span>
</Link>
)
}else{
} else if (this.props.ui.config && this.props.ui.config.spotify_user){
return (
<Link className="user" to={global.baseURL+'user/spotify:user:'+this.props.ui.config.spotify_user}>
<Thumbnail circle={true} size="small" />
<span className="user-name">
{this.props.ui.config.spotify_user} <span className="grey-text">(As defined in mopidy.config)</span>
</span>
</Link>
)
} else {
return (
<Link className="user">
<Thumbnail circle={true} size="small" />