import React from 'react'; import { connect } from 'react-redux'; import { bindActionCreators } from 'redux'; import Link from '../../components/Link' import ReactGA from 'react-ga'; import Modal from './Modal'; import Icon from '../../components/Icon'; import SpotifyAuthenticationFrame from '../../components/Fields/SpotifyAuthenticationFrame'; import LastfmAuthenticationFrame from '../../components/Fields/LastfmAuthenticationFrame'; 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'; import * as helpers from '../../helpers'; class InitialSetup extends React.Component{ constructor(props){ super(props); this.state = { username: (this.props.username ? this.props.username : 'Anonymous'), allow_reporting: this.props.allow_reporting, host: this.props.host, port: this.props.port } } componentDidMount(){ this.props.uiActions.setWindowTitle("Welcome to Iris"); } handleSubmit(e){ e.preventDefault(); var self = this; // Force local username change, even if remote connection absent/failed this.props.pusherActions.setUsername(this.state.username, true); this.props.uiActions.set({ initial_setup_complete: true, allow_reporting: this.state.allow_reporting }); this.props.mopidyActions.set({ host: this.state.host, port: this.state.port }); this.setState({saving: true}); // Wait a jiffy to allow changes to apply to store setTimeout(() => { // We've changed a connection setting, so need to reload if (self.state.host !== self.props.host || self.state.port !== self.props.port){ window.location = '/'; // Safe to just close modal } else { self.props.history.push('/'); } }, 200 ); return false; } render(){ return (

Get started

this.handleSubmit(e)}>
Username
this.setState({username: e.target.value.replace(/\W/g, '')})} value={this.state.username } />
A non-unique string used to identify this client (no special characters)
Host
this.setState({host: e.target.value})} value={ this.state.host } />
Port
this.setState({port: e.target.value})} value={ this.state.port } />
{helpers.isHosted() ? null :

This anonymous usage data is important in identifying errors and potential features that make Iris better for everyone. Want to know more? Read the privacy policy{!this.state.allow_reporting ? Are you sure you don't want to support this? : null}.

}
) } } const mapStateToProps = (state, ownProps) => { return { allow_reporting: state.ui.allow_reporting, username: (state.pusher && state.pusher.username ? state.pusher.username : null), host: state.mopidy.host, port: state.mopidy.port } } const mapDispatchToProps = (dispatch) => { return { coreActions: bindActionCreators(coreActions, dispatch), uiActions: bindActionCreators(uiActions, dispatch), pusherActions: bindActionCreators(pusherActions, dispatch), mopidyActions: bindActionCreators(mopidyActions, dispatch) } } export default connect(mapStateToProps, mapDispatchToProps)(InitialSetup)