Handling premod in optimistic comment updates.

This commit is contained in:
David Jay
2017-02-17 11:26:19 -05:00
parent e8f711ff9c
commit a35af36ee1
@@ -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]
}
};
}
}
})