From a35af36ee1eaf06aee7ca8a121e8d82952cf7c1d Mon Sep 17 00:00:00 2001 From: David Jay Date: Fri, 17 Feb 2017 11:26:19 -0500 Subject: [PATCH] Handling premod in optimistic comment updates. --- .../coral-framework/graphql/mutations/index.js | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/client/coral-framework/graphql/mutations/index.js b/client/coral-framework/graphql/mutations/index.js index b67343521..cdc57e73e 100644 --- a/client/coral-framework/graphql/mutations/index.js +++ b/client/coral-framework/graphql/mutations/index.js @@ -25,7 +25,7 @@ export const postComment = graphql(POST_COMMENT, { id: ownProps.auth.user.id, name: ownProps.auth.user.username }, - created_at: new Date(), + created_at: new Date().toString(), body, parent_id, asset_id, @@ -37,17 +37,22 @@ export const postComment = graphql(POST_COMMENT, { } }, updateQueries: { - AssetQuery: (oldData, {mutationResult:{data:{createComment:{comment}}}}) => + AssetQuery: (oldData, {mutationResult:{data:{createComment:{comment}}}}) => { + + if (oldData.asset.moderation === 'PRE') { + return oldData; + } // If posting a reply - parent_id ? { + return parent_id ? { ...oldData, asset: { ...oldData.asset, - comments: oldData.asset.comments.map((oldComment) => - oldComment.id === parent_id + comments: oldData.asset.comments.map((oldComment) => { + return oldComment.id === parent_id ? {...oldComment, replies: [...oldComment.replies, comment]} - : oldComment) + : oldComment; + }) } } @@ -59,6 +64,7 @@ export const postComment = graphql(POST_COMMENT, { commentCount: oldData.asset.commentCount + 1, comments: [comment, ...oldData.asset.comments] } + }; } } })