Support preSubmit return input

This commit is contained in:
Chi Vinh Le
2018-03-21 13:54:10 +01:00
parent bd2fcf837a
commit f6e661090c
3 changed files with 14 additions and 5 deletions
@@ -65,9 +65,12 @@ class CommentBox extends React.Component {
};
// Execute preSubmit Hooks
this.state.hooks.preSubmit.forEach(hook =>
hook(input, this.handleBodyChange)
);
this.state.hooks.preSubmit.forEach(hook => {
const result = hook(input);
if (result) {
input = result;
}
});
this.setState({ loadingState: 'loading' });
postComment(input, 'comments')
@@ -15,8 +15,11 @@ export default class CheckSpamHook extends React.Component {
// If we haven't check the spam yet, make sure to include `checkSpam=true` in the mutation.
// Otherwise post comment without checking the spam.
if (!this.checked) {
input.checkSpam = true;
this.checked = true;
return {
...input,
checkSpam: true,
};
}
});
@@ -15,8 +15,11 @@ export default class CheckToxicityHook extends React.Component {
// If we haven't check the toxicity yet, make sure to include `checkToxicity=true` in the mutation.
// Otherwise post comment without checking the toxicity.
if (!this.checked) {
input.checkToxicity = true;
this.checked = true;
return {
...input,
checkToxicity: true,
};
}
});