addClassNames, removeClassNames, reducers and actions for Comment Component

This commit is contained in:
Belen Curcio
2017-06-06 11:15:35 -03:00
parent 3ad3b3af1c
commit 9e001f5ce9
9 changed files with 108 additions and 26 deletions
@@ -1,5 +1,37 @@
import React from 'react';
import styles from './styles.css';
import {connect} from 'react-redux';
import {bindActionCreators} from 'redux';
import {addClassName, removeClassName} from 'coral-embed-stream/src/actions/comment';
export default () => (
<span><input type="checkbox"/>Hide Off-Topic Comments</span>
);
class OffTopicFilter extends React.Component {
className = 'OFF_TOPIC';
handleChange = (e) => {
if (e.target.checked) {
this.props.addClassName(this.className);
} else {
const idx = this.props.comment.classNames.indexOf(this.className);
this.props.removeClassName(idx);
}
}
render() {
return (
<div className={styles.viewingOption}>
<label>
<input type="checkbox" onChange={this.handleChange}/>
Hide Off-Topic Comments
</label>
</div>
);
}
}
const mapStateToProps = ({comment}) => ({comment});
const mapDispatchToProps = (dispatch) =>
bindActionCreators({addClassName, removeClassName}, dispatch);
export default connect(mapStateToProps, mapDispatchToProps)(OffTopicFilter);
@@ -18,4 +18,8 @@
border-radius: 2px;
}
.viewingOption {
padding: 5px 0;
}