From b816053191e93c83effe3135e1d6d65e51fc1a87 Mon Sep 17 00:00:00 2001 From: okbel Date: Fri, 18 May 2018 14:07:10 -0300 Subject: [PATCH] Updating the cache --- client/coral-admin/src/graphql/index.js | 38 +++++++++++++++++++++++-- 1 file changed, 36 insertions(+), 2 deletions(-) diff --git a/client/coral-admin/src/graphql/index.js b/client/coral-admin/src/graphql/index.js index 3874e6c94..2b5b5d8c0 100644 --- a/client/coral-admin/src/graphql/index.js +++ b/client/coral-admin/src/graphql/index.js @@ -24,6 +24,16 @@ const userRoleFragment = gql` } `; +const toBoolean = value => { + if (value === 0) { + return null; + } else if (value > 0) { + return true; + } else { + return false; + } +}; + export default { mutations: { SetUserRole: ({ variables: { id, role } }) => ({ @@ -156,7 +166,9 @@ export default { } const updated = update(prev, { users: { - nodes: { $apply: nodes => nodes.filter(node => node.id !== id) }, + nodes: { + $apply: nodes => nodes.filter(node => node.id !== id), + }, }, }); return updated; @@ -185,7 +197,9 @@ export default { const updated = update(prev, { ...decrement, flaggedUsers: { - nodes: { $apply: nodes => nodes.filter(node => node.id !== id) }, + nodes: { + $apply: nodes => nodes.filter(node => node.id !== id), + }, }, }); return updated; @@ -295,12 +309,32 @@ export default { updateQueries: { CoralAdmin_UserDetail: prev => { const increment = { + user: { + reliable: { + commenter: { + $set: toBoolean(prev.user.reliable.commenterScore - 1), + }, + commenterScore: { + $apply: count => count - 1, + }, + }, + }, rejectedComments: { $apply: count => (count < prev.totalComments ? count + 1 : count), }, }; const decrement = { + user: { + reliable: { + commenter: { + $set: toBoolean(prev.user.reliable.commenterScore + 1), + }, + commenterScore: { + $apply: count => count + 1, + }, + }, + }, rejectedComments: { $apply: count => (count > 0 ? count - 1 : 0), },