spee.ch/react/components/AnonymousOrChannelSelect.jsx

53 lines
1.8 KiB
React
Raw Normal View History

2018-01-06 03:26:57 +01:00
import React from 'react';
2018-01-10 03:25:38 +01:00
import { setPublishInChannel } from '../actions';
import { connect } from 'react-redux';
2018-01-06 03:26:57 +01:00
class AnonymousOrChannelSelect extends React.Component {
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 (
<div className="row row--padded row--short row--wide">
<div className="column column--10">
<form>
<div className="column column--3 column--med-10">
2018-01-10 03:25:38 +01:00
<input type="radio" name="anonymous-or-channel" id="anonymous-radio" className="input-radio" value="anonymous" checked={!this.props.publishInChannel} onChange={this.toggleAnonymousPublish}/>
2018-01-06 03:26:57 +01:00
<label className="label label--pointer" htmlFor="anonymous-radio">Anonymous</label>
</div>
<div className="column column--7 column--med-10">
2018-01-10 03:25:38 +01:00
<input type="radio" name="anonymous-or-channel" id="channel-radio" className="input-radio" value="in a channel" checked={this.props.publishInChannel} onChange={this.toggleAnonymousPublish}/>
2018-01-06 03:26:57 +01:00
<label className="label label--pointer" htmlFor="channel-radio">In a channel</label>
</div>
</form>
</div>
</div>
);
}
}
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));
},
};
}
export default connect(mapStateToProps, mapDispatchToProps)(AnonymousOrChannelSelect);