From e8d9f8aab833b67df7039f7e49e7543a8ae888a7 Mon Sep 17 00:00:00 2001 From: Belen Curcio Date: Wed, 12 Apr 2017 16:51:41 -0300 Subject: [PATCH] fix createComment Mutations --- .../graphql/mutations/index.js | 21 +++++++++---------- client/coral-plugin-commentbox/CommentBox.js | 1 - out.gif | 0 3 files changed, 10 insertions(+), 12 deletions(-) create mode 100644 out.gif diff --git a/client/coral-framework/graphql/mutations/index.js b/client/coral-framework/graphql/mutations/index.js index a67b728e6..16bac9b1a 100644 --- a/client/coral-framework/graphql/mutations/index.js +++ b/client/coral-framework/graphql/mutations/index.js @@ -14,14 +14,12 @@ export const postComment = graphql(POST_COMMENT, { fragments: commentView }), props: ({ownProps, mutate}) => ({ - postItem: ({asset_id, body, parent_id}) => - mutate({ + postItem: comment => { + const {asset_id, body, parent_id, tags = []} = comment; + + return mutate({ variables: { - comment: { - asset_id, - body, - parent_id - } + comment }, optimisticResponse: { createComment: { @@ -35,14 +33,14 @@ export const postComment = graphql(POST_COMMENT, { parent_id, asset_id, action_summaries: [], - tags: [], + tags, status: null, id: 'pending' } } }, updateQueries: { - AssetQuery: (oldData, {mutationResult:{data:{createComment:{comment}}}}) => { + AssetQuery: (oldData, {mutationResult: {data: {createComment: {comment}}}}) => { if (oldData.asset.settings.moderation === 'PRE' || comment.status === 'PREMOD' || comment.status === 'REJECTED') { return oldData; @@ -58,8 +56,8 @@ export const postComment = graphql(POST_COMMENT, { ...oldData.asset, comments: oldData.asset.comments.map((oldComment) => { return oldComment.id === parent_id - ? {...oldComment, replies: [...oldComment.replies, comment]} - : oldComment; + ? {...oldComment, replies: [...oldComment.replies, comment]} + : oldComment; }) } }; @@ -80,6 +78,7 @@ export const postComment = graphql(POST_COMMENT, { } } }) + } }), }); diff --git a/client/coral-plugin-commentbox/CommentBox.js b/client/coral-plugin-commentbox/CommentBox.js index bde684d2c..e2a139146 100644 --- a/client/coral-plugin-commentbox/CommentBox.js +++ b/client/coral-plugin-commentbox/CommentBox.js @@ -45,7 +45,6 @@ class CommentBox extends Component { let comment = { body: this.state.body, asset_id: assetId, - author_id: authorId, parent_id: parentId }; diff --git a/out.gif b/out.gif new file mode 100644 index 000000000..e69de29bb