import React from 'react'; import ChannelLoginForm from '../containers/ChannelLoginForm.jsx'; import ChannelCreateForm from '../containers/ChannelCreateForm.jsx'; import { connect } from 'react-redux'; const LOGIN = 'login'; const CREATE = 'create'; class ChannelSelector extends React.Component { constructor (props) { super(props); this.state = { optionState: LOGIN, }; this.handleSelection = this.handleSelection.bind(this); this.selectOption = this.selectOption.bind(this); } componentWillMount () { console.log('ChannelSelector will mount'); if (this.props.loggedInChannelName) { this.selectOption(this.props.loggedInChannelName); } } componentWillReceiveProps ({ loggedInChannelName }) { console.log('ChannelSelector will receive props'); if (loggedInChannelName) { this.selectOption(loggedInChannelName); } } handleSelection (event) { const selectedOption = event.target.selectedOptions[0].value; this.selectOption(selectedOption); } selectOption (option) { this.setState({optionState: option}); } render () { return (
{ this.props.publishInChannel && (

{this.props.channelError}

{ (this.state.optionState === LOGIN) && } { (this.state.optionState === CREATE) && }
)}
); } } const mapStateToProps = state => { return { loggedInChannelName: state.loggedInChannel.name, publishInChannel : state.publishInChannel, }; }; export default connect(mapStateToProps, null)(ChannelSelector);