From 354b51b4fe51f0670834af3c50d9c31149170be4 Mon Sep 17 00:00:00 2001 From: riley Date: Wed, 3 May 2017 11:14:21 -0600 Subject: [PATCH] use a reduce instead --- .../src/graphql/mutations/index.js | 20 +++++++------------ 1 file changed, 7 insertions(+), 13 deletions(-) diff --git a/client/coral-admin/src/graphql/mutations/index.js b/client/coral-admin/src/graphql/mutations/index.js index 9c72d184a..fdb82db9a 100644 --- a/client/coral-admin/src/graphql/mutations/index.js +++ b/client/coral-admin/src/graphql/mutations/index.js @@ -44,6 +44,7 @@ export const suspendUser = graphql(SUSPEND_USER, { }) }); +const views = ['all', 'premod', 'flagged', 'accepted', 'rejected']; export const setCommentStatus = graphql(SET_COMMENT_STATUS, { props: ({mutate}) => ({ acceptComment: ({commentId}) => { @@ -54,12 +55,9 @@ export const setCommentStatus = graphql(SET_COMMENT_STATUS, { }, updateQueries: { ModQueue: (oldData) => { - let comment = [ - ...oldData.all, - ...oldData.premod, - ...oldData.flagged, - ...oldData.rejected - ].find(c => c.id === commentId); + const comment = views.reduce((comment, view) => { + return comment ? comment : oldData[view].find(c => c.id === commentId); + }, null); let accepted; let acceptedCount = oldData.acceptedCount; @@ -102,13 +100,9 @@ export const setCommentStatus = graphql(SET_COMMENT_STATUS, { }, updateQueries: { ModQueue: (oldData) => { - let comment = [ - ...oldData.all, - ...oldData.premod, - ...oldData.flagged, - ...oldData.accepted - ].find(c => c.id === commentId); - + const comment = views.reduce((comment, view) => { + return comment ? comment : oldData[view].find(c => c.id === commentId); + }, null); let rejected; let rejectedCount = oldData.rejectedCount;