import React from 'react'; import PropTypes from 'prop-types'; import { connect } from 'react-redux'; import ChannelLoginForm from '../containers/ChannelLoginForm.jsx'; import ChannelCreateForm from '../containers/ChannelCreateForm.jsx'; const LOGIN = 'Existing'; const CREATE = 'New'; class ChannelSelector extends React.Component { constructor (props) { super(props); this.state = { selectedOption: 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 }) { if (loggedInChannelName) { this.selectOption(loggedInChannelName); } } handleSelection (event) { const selectedOption = event.target.selectedOptions[0].value; this.selectOption(selectedOption); } selectOption (option) { this.setState({selectedOption: option}); } render () { return (
{ this.props.publishInChannel && (

{this.props.channelError}

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