spee.ch/react/containers/ChannelSelect.jsx

49 lines
1.6 KiB
React
Raw Normal View History

2018-01-06 03:26:57 +01:00
import React from 'react';
import { setPublishInChannel } from '../actions/index';
2018-01-10 03:25:38 +01:00
import { connect } from 'react-redux';
2018-01-06 03:26:57 +01:00
2018-01-17 00:55:29 +01:00
class channelSelect extends React.Component {
2018-01-06 03:26:57 +01:00
constructor (props) {
super(props);
this.toggleAnonymousPublish = this.toggleAnonymousPublish.bind(this);
}
toggleAnonymousPublish (event) {
const value = event.target.value;
if (value === 'anonymous') {
this.props.onPublishInChannelChange(false);
2018-01-06 03:26:57 +01:00
} else {
this.props.onPublishInChannelChange(true);
2018-01-06 03:26:57 +01:00
}
}
render () {
return (
2018-01-10 20:26:01 +01:00
<form>
<div className="column column--3 column--med-10">
<input type="radio" name="anonymous-or-channel" id="anonymous-radio" className="input-radio" value="anonymous" checked={!this.props.publishInChannel} onChange={this.toggleAnonymousPublish}/>
<label className="label label--pointer" htmlFor="anonymous-radio">Anonymous</label>
2018-01-06 03:26:57 +01:00
</div>
2018-01-10 20:26:01 +01:00
<div className="column column--7 column--med-10">
<input type="radio" name="anonymous-or-channel" id="channel-radio" className="input-radio" value="in a channel" checked={this.props.publishInChannel} onChange={this.toggleAnonymousPublish}/>
<label className="label label--pointer" htmlFor="channel-radio">In a channel</label>
</div>
</form>
2018-01-06 03:26:57 +01:00
);
}
}
2018-01-10 03:25:38 +01:00
const mapStateToProps = state => {
return {
publishInChannel: state.publishInChannel,
};
};
const mapDispatchToProps = dispatch => {
return {
onPublishInChannelChange: (value) => {
2018-01-10 03:25:38 +01:00
dispatch(setPublishInChannel(value));
},
};
}
2018-01-17 00:55:29 +01:00
export default connect(mapStateToProps, mapDispatchToProps)(channelSelect);