Clearing tags and naming convention

This commit is contained in:
Belen Curcio
2017-06-07 10:04:52 -03:00
parent 4725f07757
commit 456eedfd31
4 changed files with 21 additions and 9 deletions
@@ -1,5 +1,5 @@
import {TOGGLE_CHECKBOX} from './constants';
import {OFFTOPIC_TOGGLE_CHECKBOX} from './constants';
export const toggleCheckbox = () => ({
type: TOGGLE_CHECKBOX
type: OFFTOPIC_TOGGLE_CHECKBOX
});
@@ -7,12 +7,24 @@ export default class OffTopicCheckbox extends React.Component {
label = 'OFF_TOPIC';
handleChange = (e) => {
if (e.target.checked) {
this.props.addTag(this.label);
} else {
componentDidMount() {
this.clearTagsHook = this.props.registerHook('postSubmit', () => {
const idx = this.props.commentBox.tags.indexOf(this.label);
this.props.removeTag(idx);
});
}
componentWillUnmount() {
this.props.unregisterHook(this.clearTagsHook);
}
handleChange = (e) => {
const {addTag, removeTag} = this.props;
if (e.target.checked) {
addTag(this.label);
} else {
const idx = this.props.commentBox.tags.indexOf(this.label);
removeTag(idx);
}
}
@@ -1 +1 @@
export const TOGGLE_CHECKBOX = 'TOGGLE_CHECKBOX';
export const OFFTOPIC_TOGGLE_CHECKBOX = 'OFFTOPIC_TOGGLE_CHECKBOX';
@@ -1,4 +1,4 @@
import {TOGGLE_CHECKBOX} from './constants';
import {OFFTOPIC_TOGGLE_CHECKBOX} from './constants';
const initialState = {
checked: false
@@ -6,7 +6,7 @@ const initialState = {
export default function offTopic (state = initialState, action) {
switch (action.type) {
case TOGGLE_CHECKBOX: {
case OFFTOPIC_TOGGLE_CHECKBOX: {
return {
...state,
checked: !state.checked