2016-10-17 10:39:11 +13:00
|
|
|
|
|
|
|
|
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'
|
2016-10-23 23:48:06 +13:00
|
|
|
import Header from '../components/Header'
|
2016-10-17 10:39:11 +13:00
|
|
|
|
|
|
|
|
import * as mopidyActions from '../services/mopidy/actions'
|
|
|
|
|
import * as spotifyActions from '../services/spotify/actions'
|
|
|
|
|
|
|
|
|
|
class Settings extends React.Component{
|
|
|
|
|
|
|
|
|
|
constructor(props) {
|
|
|
|
|
super(props);
|
2016-10-18 08:56:53 +13:00
|
|
|
|
|
|
|
|
this.state = {
|
|
|
|
|
mopidy_host: this.props.mopidy.host,
|
2016-10-18 21:57:29 +13:00
|
|
|
mopidy_port: this.props.mopidy.port,
|
2016-10-27 16:58:11 +13:00
|
|
|
pusher_port: this.props.pusher.port,
|
2016-10-18 21:57:29 +13:00
|
|
|
spotify_country: this.props.spotify.country,
|
|
|
|
|
spotify_locale: this.props.spotify.locale
|
2016-10-18 08:56:53 +13:00
|
|
|
};
|
2016-10-17 10:39:11 +13:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
resetAllSettings(){
|
2016-10-17 14:27:48 +13:00
|
|
|
localStorage.clear();
|
|
|
|
|
window.location.reload(true);
|
2016-10-17 10:39:11 +13:00
|
|
|
}
|
|
|
|
|
|
2016-10-18 21:57:29 +13:00
|
|
|
setMopidyConfig(){
|
|
|
|
|
this.props.mopidyActions.setConfig({ host: this.state.mopidy_host, port: this.state.mopidy_port });
|
2016-10-18 08:56:53 +13:00
|
|
|
window.location.reload(true);
|
|
|
|
|
}
|
|
|
|
|
|
2016-10-18 21:57:29 +13:00
|
|
|
setSpotifyConfig(){
|
|
|
|
|
this.props.spotifyActions.setConfig({ country: this.state.spotify_country, locale: this.state.spotify_locale });
|
|
|
|
|
}
|
|
|
|
|
|
2016-10-27 16:58:11 +13:00
|
|
|
setPusherConfig(){
|
|
|
|
|
this.props.pusherActions.setConfig({ port: this.state.pusher_port });
|
|
|
|
|
}
|
|
|
|
|
|
2016-10-17 10:39:11 +13:00
|
|
|
render(){
|
|
|
|
|
return (
|
2016-10-26 16:55:47 +13:00
|
|
|
<div className="view settings-view">
|
2016-10-23 23:48:06 +13:00
|
|
|
<Header
|
|
|
|
|
icon="cog"
|
|
|
|
|
title="Settings"
|
|
|
|
|
/>
|
2016-10-18 21:57:29 +13:00
|
|
|
|
2016-10-25 14:09:53 +13:00
|
|
|
<section>
|
|
|
|
|
|
2016-10-25 17:01:37 +13:00
|
|
|
<h3 className="underline">Mopidy</h3>
|
2016-10-25 14:09:53 +13:00
|
|
|
<form onSubmit={() => this.setMopidyConfig()}>
|
|
|
|
|
<label>
|
|
|
|
|
<span className="label">Host</span>
|
2016-10-26 21:20:48 +13:00
|
|
|
<input
|
|
|
|
|
type="text"
|
|
|
|
|
onChange={ e => this.setState({ mopidy_host: e.target.value })}
|
|
|
|
|
value={ this.state.mopidy_host } />
|
2016-10-25 14:09:53 +13:00
|
|
|
</label>
|
|
|
|
|
<label>
|
|
|
|
|
<span className="label">Port</span>
|
2016-10-26 21:20:48 +13:00
|
|
|
<input
|
|
|
|
|
type="text"
|
|
|
|
|
onChange={ e => this.setState({ mopidy_port: e.target.value })}
|
|
|
|
|
value={ this.state.mopidy_port } />
|
2016-10-25 14:09:53 +13:00
|
|
|
</label>
|
2016-10-27 16:58:11 +13:00
|
|
|
<button type="submit" className="secondary">Apply</button>
|
|
|
|
|
</form>
|
|
|
|
|
|
|
|
|
|
<h3 className="underline">Pusher</h3>
|
|
|
|
|
<form onSubmit={() => this.setPusherConfig()}>
|
|
|
|
|
<label>
|
|
|
|
|
<span className="label">Port</span>
|
|
|
|
|
<input
|
|
|
|
|
type="text"
|
|
|
|
|
onChange={ e => this.setState({ pusher_port: e.target.value })}
|
|
|
|
|
value={ this.state.pusher_port } />
|
|
|
|
|
</label>
|
|
|
|
|
<button type="submit" className="secondary">Apply</button>
|
2016-10-25 14:09:53 +13:00
|
|
|
</form>
|
|
|
|
|
|
2016-10-25 17:01:37 +13:00
|
|
|
<h3 className="underline">Spotify</h3>
|
2016-10-25 14:09:53 +13:00
|
|
|
<form onSubmit={() => this.setSpotifyConfig()}>
|
|
|
|
|
<label>
|
|
|
|
|
<span className="label">Country</span>
|
2016-10-26 21:20:48 +13:00
|
|
|
<input
|
|
|
|
|
type="text"
|
|
|
|
|
onChange={ e => this.setState({ spotify_country: e.target.value })}
|
|
|
|
|
value={ this.state.spotify_country } />
|
2016-10-25 14:09:53 +13:00
|
|
|
</label>
|
|
|
|
|
<label>
|
|
|
|
|
<span className="label">Locale</span>
|
2016-10-26 21:20:48 +13:00
|
|
|
<input
|
|
|
|
|
type="text"
|
|
|
|
|
onChange={ e => this.setState({ spotify_locale: e.target.value })}
|
|
|
|
|
value={ this.state.spotify_locale } />
|
2016-10-25 14:09:53 +13:00
|
|
|
</label>
|
2016-10-27 16:58:11 +13:00
|
|
|
<button type="submit" className="secondary">Apply</button>
|
2016-10-25 14:09:53 +13:00
|
|
|
</form>
|
|
|
|
|
|
|
|
|
|
<SpotifyAuthenticationFrame />
|
|
|
|
|
|
|
|
|
|
<ConfirmationButton content="Reset all settings" confirmingContent="Are you sure?" onConfirm={() => this.resetAllSettings()} />
|
|
|
|
|
|
|
|
|
|
</section>
|
2016-10-17 10:39:11 +13:00
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Export our component
|
|
|
|
|
*
|
|
|
|
|
* We also integrate our global store, using connect()
|
|
|
|
|
**/
|
|
|
|
|
|
|
|
|
|
const mapStateToProps = (state, ownProps) => {
|
|
|
|
|
return state;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const mapDispatchToProps = (dispatch) => {
|
|
|
|
|
return {
|
|
|
|
|
mopidyActions: bindActionCreators(mopidyActions, dispatch),
|
|
|
|
|
spotifyActions: bindActionCreators(spotifyActions, dispatch)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export default connect(mapStateToProps, mapDispatchToProps)(Settings)
|