From 95aa89faed81ed5b1530d19f5ffb1a7acae877ec Mon Sep 17 00:00:00 2001 From: David Jay Date: Tue, 7 Mar 2017 14:16:44 -0500 Subject: [PATCH] Switching premod status update to updateQueries function. --- .../src/graphql/mutations/index.js | 43 ++++++++++++++++++- 1 file changed, 41 insertions(+), 2 deletions(-) diff --git a/client/coral-admin/src/graphql/mutations/index.js b/client/coral-admin/src/graphql/mutations/index.js index fe3a1faf9..884e30e0c 100644 --- a/client/coral-admin/src/graphql/mutations/index.js +++ b/client/coral-admin/src/graphql/mutations/index.js @@ -22,7 +22,26 @@ export const setCommentStatus = graphql(SET_COMMENT_STATUS, { commentId, status: 'ACCEPTED' }, - refetchQueries: ['ModQueue'] + updateQueries: { + ModQueue: (oldData) => { + const premod = oldData.premod.filter(c => c.id !== commentId); + const flagged = oldData.flagged.filter(c => c.id !== commentId); + const rejected = oldData.rejected.filter(c => c.id !== commentId); + const premodCount = premod.length < oldData.premod.length ? oldData.premodCount - 1 : oldData.premodCount; + const flaggedCount = flagged.length < oldData.flagged.length ? oldData.flaggedCount - 1 : oldData.flaggedCount; + const rejectedCount = rejected.length < oldData.rejected.length ? oldData.rejectedCount - 1 : oldData.rejectedCount; + + return { + ...oldData, + premodCount, + flaggedCount, + rejectedCount, + premod, + flagged, + rejected, + }; + } + } }); }, rejectComment: ({commentId}) => { @@ -31,7 +50,27 @@ export const setCommentStatus = graphql(SET_COMMENT_STATUS, { commentId, status: 'REJECTED' }, - refetchQueries: ['ModQueue'] + updateQueries: { + ModQueue: (oldData) => { + const comment = oldData.premod.concat(oldData.flagged).filter(c => c.id === commentId)[0]; + const rejected = [comment].concat(oldData.rejected); + const premod = oldData.premod.filter(c => c.id !== commentId); + const flagged = oldData.flagged.filter(c => c.id !== commentId); + const premodCount = premod.length < oldData.premod.length ? oldData.premodCount - 1 : oldData.premodCount; + const flaggedCount = flagged.length < oldData.flagged.length ? oldData.flaggedCount - 1 : oldData.flaggedCount; + const rejectedCount = oldData.rejectedCount + 1; + + return { + ...oldData, + premodCount, + flaggedCount, + rejectedCount, + premod, + flagged, + rejected + }; + } + } }); } })