2018-01-04 23:14:03 +01:00
|
|
|
import React from 'react';
|
2018-01-16 19:45:17 +01:00
|
|
|
import { connect } from 'react-redux';
|
2018-01-11 20:41:12 +01:00
|
|
|
import ChannelLoginForm from '../containers/ChannelLoginForm.jsx';
|
|
|
|
import ChannelCreateForm from '../containers/ChannelCreateForm.jsx';
|
2018-01-04 23:14:03 +01:00
|
|
|
|
2018-01-16 19:45:17 +01:00
|
|
|
const LOGIN = 'Existing';
|
|
|
|
const CREATE = 'New';
|
2018-01-05 01:10:25 +01:00
|
|
|
|
2018-01-04 23:14:03 +01:00
|
|
|
class ChannelSelector extends React.Component {
|
2018-01-05 01:10:25 +01:00
|
|
|
constructor (props) {
|
|
|
|
super(props);
|
|
|
|
this.state = {
|
2018-01-16 19:45:17 +01:00
|
|
|
selectedOption: LOGIN,
|
2018-01-05 01:10:25 +01:00
|
|
|
};
|
2018-01-06 00:11:45 +01:00
|
|
|
this.handleSelection = this.handleSelection.bind(this);
|
|
|
|
this.selectOption = this.selectOption.bind(this);
|
2018-01-05 01:10:25 +01:00
|
|
|
}
|
2018-01-05 22:59:25 +01:00
|
|
|
componentWillMount () {
|
2018-01-11 20:41:12 +01:00
|
|
|
console.log('ChannelSelector will mount');
|
2018-01-05 22:59:25 +01:00
|
|
|
if (this.props.loggedInChannelName) {
|
2018-01-10 20:26:01 +01:00
|
|
|
this.selectOption(this.props.loggedInChannelName);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
componentWillReceiveProps ({ loggedInChannelName }) {
|
|
|
|
if (loggedInChannelName) {
|
|
|
|
this.selectOption(loggedInChannelName);
|
2018-01-05 22:59:25 +01:00
|
|
|
}
|
|
|
|
}
|
2018-01-06 00:11:45 +01:00
|
|
|
handleSelection (event) {
|
2018-01-05 01:10:25 +01:00
|
|
|
const selectedOption = event.target.selectedOptions[0].value;
|
2018-01-06 00:11:45 +01:00
|
|
|
this.selectOption(selectedOption);
|
|
|
|
}
|
|
|
|
selectOption (option) {
|
2018-01-16 19:45:17 +01:00
|
|
|
this.setState({selectedOption: option});
|
2018-01-06 00:11:45 +01:00
|
|
|
}
|
2018-01-04 23:14:03 +01:00
|
|
|
render () {
|
|
|
|
return (
|
|
|
|
<div>
|
2018-01-10 03:49:26 +01:00
|
|
|
{ this.props.publishInChannel && (
|
2018-01-10 20:26:01 +01:00
|
|
|
<div>
|
2018-01-05 01:10:25 +01:00
|
|
|
<p id="input-error-channel-select" className="info-message-placeholder info-message--failure">{this.props.channelError}</p>
|
|
|
|
<div className="column column--3">
|
|
|
|
<label className="label" htmlFor="channel-name-select">Channel:</label>
|
|
|
|
</div><div className="column column--7">
|
2018-01-16 19:45:17 +01:00
|
|
|
<select type="text" id="channel-name-select" className="select select--arrow" value={this.state.selectedOption} onChange={this.handleSelection}>
|
2018-01-05 20:09:32 +01:00
|
|
|
{ this.props.loggedInChannelName && <option value={this.props.loggedInChannelName} id="publish-channel-select-channel-option">{this.props.loggedInChannelName}</option> }
|
2018-01-16 19:45:17 +01:00
|
|
|
<option value={LOGIN}>Existing</option>
|
|
|
|
<option value={CREATE}>New</option>
|
2018-01-05 01:10:25 +01:00
|
|
|
</select>
|
|
|
|
</div>
|
|
|
|
|
2018-01-16 19:45:17 +01:00
|
|
|
{ (this.state.selectedOption === LOGIN) && <ChannelLoginForm /> }
|
2018-01-10 20:26:01 +01:00
|
|
|
|
2018-01-16 19:45:17 +01:00
|
|
|
{ (this.state.selectedOption === CREATE) && <ChannelCreateForm /> }
|
2018-01-05 01:10:25 +01:00
|
|
|
|
|
|
|
</div>
|
|
|
|
)}
|
2018-01-04 23:14:03 +01:00
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-01-10 03:49:26 +01:00
|
|
|
const mapStateToProps = state => {
|
|
|
|
return {
|
|
|
|
loggedInChannelName: state.loggedInChannel.name,
|
|
|
|
publishInChannel : state.publishInChannel,
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
export default connect(mapStateToProps, null)(ChannelSelector);
|