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,
};
@@ -0,0 +1,9 @@
import {bindActionCreators} from 'redux';
import {connect} from 'plugin-api/beta/client/hocs';
import {notify} from 'plugin-api/beta/client/actions/notification';
import CheckToxicityHook from '../components/CheckToxicityHook';
const mapDispatchToProps = (dispatch) =>
bindActionCreators({notify}, dispatch);
export default connect(null, mapDispatchToProps)(CheckToxicityHook);
@@ -1,5 +1,5 @@
import translations from './translations.yml';
import CheckToxicityHook from './components/CheckToxicityHook';
import CheckToxicityHook from './containers/CheckToxicityHook';
export default {
translations,
@@ -3,4 +3,8 @@ en:
COMMENT_IS_TOXIC: |
Are you sure? The language in this comment might violate our community guidelines.
You can edit the comment or submit it for moderator review.
talk-plugin-toxic-comments:
still_toxic: |
This edited comment might still violate our community guidelines.
Our moderation team will review your comment shortly.
es: