From 55c5f6d5bec9b482089ac894d32467c2238dc7ad Mon Sep 17 00:00:00 2001 From: Riley Davis Date: Tue, 20 Dec 2016 13:25:21 -0700 Subject: [PATCH] use spread operator. update action constants --- client/coral-admin/src/actions/comments.js | 49 +++++++++------------- 1 file changed, 19 insertions(+), 30 deletions(-) diff --git a/client/coral-admin/src/actions/comments.js b/client/coral-admin/src/actions/comments.js index a2a5965e2..89cd87d89 100644 --- a/client/coral-admin/src/actions/comments.js +++ b/client/coral-admin/src/actions/comments.js @@ -1,11 +1,10 @@ import coralApi from '../../../coral-framework/helpers/response'; -import * as actions from '../constants/comments'; +import * as commentActions from '../constants/comments'; // Get comments to fill each of the three lists on the mod queue export const fetchModerationQueueComments = () => { return dispatch => { - - dispatch({type: actions.COMMENTS_MODERATION_QUEUE_FETCH}); + dispatch({type: commentActions.COMMENTS_MODERATION_QUEUE_FETCH}); return Promise.all([ coralApi('/queue/comments/pending'), coralApi('/comments?status=rejected'), @@ -14,28 +13,18 @@ export const fetchModerationQueueComments = () => { .then(([pending, rejected, flagged]) => { /* Combine seperate calls into a single object */ - let all = {}; - all.comments = pending.comments - .concat(rejected.comments) - .concat(flagged.comments.map(comment => { - comment.flagged = true; - return comment; - })); - all.users = pending.users - .concat(rejected.users) - .concat(flagged.users); - all.actions = pending.actions - .concat(rejected.actions) - .concat(flagged.actions); - return all; + flagged.comments.forEach(comment => comment.flagged = true); + return { + comments: [...pending.comments, ...rejected.comments, ...flagged.comments], + users: [...pending.users, ...rejected.users, ...flagged.users], + actions: [...pending.actions, ...rejected.actions, ...flagged.actions] + }; }) - .then(all => { + .then(({comments, users, actions}) => { /* Post comments and users to redux store. Actions will be posted when they are needed. */ - dispatch({type: actions.USERS_MODERATION_QUEUE_FETCH_SUCCESS, - users: all.users}); - dispatch({type: actions.COMMENTS_MODERATION_QUEUE_FETCH_SUCCESS, - comments: all.comments}); + dispatch({type: commentActions.USERS_MODERATION_QUEUE_FETCH_SUCCESS, users}); + dispatch({type: commentActions.COMMENTS_MODERATION_QUEUE_FETCH_SUCCESS, comments}); }); }; @@ -46,8 +35,8 @@ export const createComment = (name, body) => { return dispatch => { const comment = {body, name}; return coralApi('/comments', {method: 'POST', comment}) - .then(res => dispatch({type: actions.COMMENT_CREATE_SUCCESS, comment: res})) - .catch(error => dispatch({type: actions.COMMENT_CREATE_FAILED, error})); + .then(res => dispatch({type: commentActions.COMMENT_CREATE_SUCCESS, comment: res})) + .catch(error => dispatch({type: commentActions.COMMENT_CREATE_FAILED, error})); }; }; @@ -58,23 +47,23 @@ export const createComment = (name, body) => { // Update a comment. Now to update a comment we need to send back the whole object export const updateStatus = (status, comment) => { return dispatch => { - dispatch({type: actions.COMMENT_STATUS_UPDATE, id: comment.id, status}); + dispatch({type: commentActions.COMMENT_STATUS_UPDATE, id: comment.id, status}); return coralApi(`/comments/${comment.id}/status`, {method: 'PUT', body: {status}}) - .then(res => dispatch({type: actions.COMMENT_UPDATE_SUCCESS, res})) - .catch(error => dispatch({type: actions.COMMENT_UPDATE_FAILED, error})); + .then(res => dispatch({type: commentActions.COMMENT_UPDATE_SUCCESS, res})) + .catch(error => dispatch({type: commentActions.COMMENT_UPDATE_FAILED, error})); }; }; export const flagComment = id => (dispatch, getState) => { - dispatch({type: actions.COMMENT_FLAG, id}); + dispatch({type: commentActions.COMMENT_FLAG, id}); dispatch({type: 'COMMENT_UPDATE', comment: getState().comments.get('byId').get(id)}); }; // Dialog Actions export const showBanUserDialog = (userId, userName, commentId) => { - return {type: 'SHOW_BANUSER_DIALOG', userId, userName, commentId}; + return {type: commentActions.SHOW_BANUSER_DIALOG, userId, userName, commentId}; }; export const hideBanUserDialog = (showDialog) => { - return {type: 'HIDE_BANUSER_DIALOG', showDialog}; + return {type: commentActions.HIDE_BANUSER_DIALOG, showDialog}; };