From ad09ce03a17eef2713e34c27827eea7342d17c20 Mon Sep 17 00:00:00 2001 From: Chi Vinh Le Date: Tue, 18 Jul 2017 17:09:48 +0700 Subject: [PATCH] Prevent double execution of mutation --- plugin-api/beta/client/hocs/withTags.js | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/plugin-api/beta/client/hocs/withTags.js b/plugin-api/beta/client/hocs/withTags.js index 62b50bf36..63001392f 100644 --- a/plugin-api/beta/client/hocs/withTags.js +++ b/plugin-api/beta/client/hocs/withTags.js @@ -115,16 +115,27 @@ export default (tag) => (WrappedComponent) => { }); class WithTags extends React.Component { + loading = false; postTag = () => { const {comment, asset, addNotification} = this.props; + if (this.loading) { + return; + } + + this.loading = true; + this.props.addTag({ id: comment.id, name: Tag.toUpperCase(), assetId: asset.id }) + .then(() => { + this.loading = false; + }) .catch((err) => { + this.loading = false; forEachError(err, ({msg}) => addNotification('error', msg)); }); } @@ -132,12 +143,20 @@ export default (tag) => (WrappedComponent) => { deleteTag = () => { const {comment, asset, addNotification} = this.props; + if (this.loading) { + return; + } + this.props.removeTag({ id: comment.id, name: Tag.toUpperCase(), assetId: asset.id }) + .then(() => { + this.loading = false; + }) .catch((err) => { + this.loading = false; forEachError(err, ({msg}) => addNotification('error', msg)); }); }