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' ) {
2018-01-10 03:49:26 +01:00
this . props . onPublishInChannelChange ( false ) ;
2018-01-06 03:26:57 +01:00
} else {
2018-01-10 03:49:26 +01:00
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 {
2018-01-10 03:49:26 +01:00
onPublishInChannelChange : ( value ) => {
2018-01-10 03:25:38 +01:00
dispatch ( setPublishInChannel ( value ) ) ;
} ,
} ;
}
export default connect ( mapStateToProps , mapDispatchToProps ) ( AnonymousOrChannelSelect ) ;