Bugfixes and show different notification for toxic comments

Bugfixes:
- Toxic comment flag was not added
- GraphQL warnings for missing fields
This commit is contained in:
Chi Vinh Le
2017-09-19 19:20:38 +07:00
parent 262213a520
commit b5deac7b48
7 changed files with 56 additions and 15 deletions
@@ -1,4 +1,6 @@
import React from 'react';
import PropTypes from 'prop-types';
import {t} from 'plugin-api/beta/client/services';
/**
* CheckToxicityHook adds hooks to the `commentBox`
@@ -20,7 +22,11 @@ export default class CheckToxicityHook extends React.Component {
}
});
this.toxicityPostHook = this.props.registerHook('postSubmit', () => {
this.toxicityPostHook = this.props.registerHook('postSubmit', (result) => {
const actions = result.createComment.comment && result.createComment.comment.actions;
if (actions && actions.some(({reason}) => reason === 'TOXIC_COMMENT')) {
this.props.notify('error', t('talk-plugin-toxic-comments.still_toxic'));
}
// Reset `checked` after comment was successfully posted.
this.checked = false;
@@ -36,3 +42,9 @@ export default class CheckToxicityHook extends React.Component {
return null;
}
}
CheckToxicityHook.propTypes = {
notify: PropTypes.func.isRequired,
registerHook: PropTypes.func.isRequired,
unregisterHook: PropTypes.func.isRequired,
};