From 8c215e08612dbe6ce870434620ff1c5fb14f312c Mon Sep 17 00:00:00 2001 From: Dan Zajdband Date: Tue, 8 Nov 2016 17:15:57 -0500 Subject: [PATCH] api-adapt(coral-admin): Get flagging mod queue working with the backend --- client/coral-admin/src/reducers/comments.js | 2 +- client/coral-admin/src/services/talk-adapter.js | 8 ++++++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/client/coral-admin/src/reducers/comments.js b/client/coral-admin/src/reducers/comments.js index 4fd14673a..e75079ce4 100644 --- a/client/coral-admin/src/reducers/comments.js +++ b/client/coral-admin/src/reducers/comments.js @@ -39,7 +39,7 @@ const updateStatus = (state, action) => { // Flag a comment const flag = (state, action) => { const byId = state.get('byId') - const data = byId.get(action.id).get('data').set('flagged', true) + const data = byId.get(action.id).set('flagged', true) const comment = byId.get(action.id).set('data', data) return state.set('byId', byId.set(action.id, comment)) } diff --git a/client/coral-admin/src/services/talk-adapter.js b/client/coral-admin/src/services/talk-adapter.js index 2336e0cfd..0772bb24a 100644 --- a/client/coral-admin/src/services/talk-adapter.js +++ b/client/coral-admin/src/services/talk-adapter.js @@ -29,8 +29,12 @@ export default store => next => action => { // Get comments to fill each of the three lists on the mod queue const fetchModerationQueueComments = store => -fetch(`/api/v1/queue`) -.then(res => res.json()) +Promise.all([fetch(`/api/v1/comments/status/pending`), fetch(`/api/v1/comments/status/rejected`), fetch(`/api/v1/comments/action/flag`)]) +.then(res => Promise.all(res.map(r => r.json()))) +.then(res => { + res[2] = res[2].map(comment => { comment.flagged = true; return comment; }) + return res.reduce((prev, curr) => prev.concat(curr), []) +}) .then(res => store.dispatch({ type: 'COMMENTS_MODERATION_QUEUE_FETCH_SUCCESS', comments: res })) .catch(error => store.dispatch({ type: 'COMMENTS_MODERATION_QUEUE_FETCH_FAILED', error }))