import React, { PropTypes } from 'react' import { connect } from 'react-redux' import { bindActionCreators } from 'redux' import FontAwesome from 'react-fontawesome' import SpotifyAuthenticationFrame from '../components/SpotifyAuthenticationFrame' import ConfirmationButton from '../components/ConfirmationButton' import PusherConnectionList from '../components/PusherConnectionList' import URISchemesList from '../components/URISchemesList' import VersionManager from '../components/VersionManager' import Header from '../components/Header' import * as pusherActions from '../services/pusher/actions' import * as mopidyActions from '../services/mopidy/actions' import * as spotifyActions from '../services/spotify/actions' class Settings extends React.Component{ constructor(props) { super(props); this.state = { mopidy_host: this.props.mopidy.host, mopidy_port: this.props.mopidy.port, pusher_username: this.props.pusher.username, pusher_port: this.props.pusher.port, spotify_country: this.props.spotify.country, spotify_locale: this.props.spotify.locale }; } resetAllSettings(){ localStorage.clear(); window.location.reload(true); return false; } setMopidyConfig(e){ e.preventDefault(); this.props.mopidyActions.setConfig({ host: this.state.mopidy_host, port: this.state.mopidy_port }); window.location.reload(true); return false; } setSpotifyConfig(e){ e.preventDefault(); this.props.spotifyActions.setConfig({ country: this.state.spotify_country, locale: this.state.spotify_locale }); return false; } componentWillReceiveProps(newProps){ if( this.state.pusher_username != newProps.pusher.username ){ this.setState({ pusher_username: newProps.pusher.username }) } } renderConnectionStatus(service){ if( this.props[service].connected ){ return (   Connected ) }else if( this.props[service].connecting ){ return (   Connecting ) }else{ return (   Not connected ) } } render(){ return (

Mopidy

this.setMopidyConfig(e)}>
Status
{ this.renderConnectionStatus('mopidy') }
Host
this.setState({ mopidy_host: e.target.value })} value={ this.state.mopidy_host } />
Port
this.setState({ mopidy_port: e.target.value })} value={ this.state.mopidy_port } />

Pusher

Status
{ this.renderConnectionStatus('pusher') }
Username
this.setState({ pusher_username: e.target.value }) } onBlur={ e => this.props.pusherActions.changeUsername( this.state.pusher_username ) } value={ this.state.pusher_username } />
Port
this.setState({ pusher_port: e.target.value })} onBlur={ e => this.props.pusherActions.setPort( this.state.pusher_port ) } value={ this.state.pusher_port } />

Spotify

this.setSpotifyConfig(e)}>
Status
{ this.renderConnectionStatus('spotify') }
Country
this.setState({ spotify_country: e.target.value })} onBlur={ e => this.setSpotifyConfig(e) } value={ this.state.spotify_country } />
Locale
this.setState({ spotify_locale: e.target.value })} onBlur={ e => this.setSpotifyConfig(e) } value={ this.state.spotify_locale } />

Advanced

Connections
Backends
Version
this.resetAllSettings()} />
); } } /** * Export our component * * We also integrate our global store, using connect() **/ const mapStateToProps = (state, ownProps) => { return state; } const mapDispatchToProps = (dispatch) => { return { pusherActions: bindActionCreators(pusherActions, dispatch), mopidyActions: bindActionCreators(mopidyActions, dispatch), spotifyActions: bindActionCreators(spotifyActions, dispatch) } } export default connect(mapStateToProps, mapDispatchToProps)(Settings)