From b4b342054978a8785e4e2d4b3c499bb09ab79ddc Mon Sep 17 00:00:00 2001 From: Riley Davis Date: Tue, 20 Dec 2016 12:21:10 -0700 Subject: [PATCH 1/9] remove banUser and create fetchModerationQueueComments actions --- client/coral-admin/src/actions/comments.js | 73 ++++++++++++++++++- client/coral-admin/src/actions/users.js | 18 +++-- client/coral-admin/src/constants/comments.js | 5 ++ .../ModerationQueue/ModerationQueue.js | 16 +++- client/coral-admin/src/reducers/comments.js | 4 +- .../coral-admin/src/services/talk-adapter.js | 65 ----------------- 6 files changed, 100 insertions(+), 81 deletions(-) diff --git a/client/coral-admin/src/actions/comments.js b/client/coral-admin/src/actions/comments.js index d4aee034e..f89cb5dd3 100644 --- a/client/coral-admin/src/actions/comments.js +++ b/client/coral-admin/src/actions/comments.js @@ -1,3 +1,72 @@ +import coralApi from '../../../coral-framework/helpers/response'; +import * as actions from '../constants/comments'; + + +// Get comments to fill each of the three lists on the mod queue +export const fetchModerationQueueComments = () => { + return dispatch => { + + return Promise.all([ + coralApi('/queue/comments/pending'), + coralApi('/comments?status=rejected'), + coralApi('/comments?action_type=flag') + ]) + .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; + }) + .then(all => { + + /* 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}); + + }); + }; +}; + + +// .catch(error => store.dispatch({type: 'COMMENTS_MODERATION_QUEUE_FETCH_FAILED', error})); + +// Update a comment. Now to update a comment we need to send back the whole object + +export const updateComment = (store, comment) => { + coralApi(`/comments/${comment.get('id')}/status`, {method: 'PUT', body: {status: comment.get('status')}}) + .then(res => store.dispatch({type: 'COMMENT_UPDATE_SUCCESS', res})) + .catch(error => store.dispatch({type: 'COMMENT_UPDATE_FAILED', error})); +}; + +// Create a new comment +export const createComment = (name, body) => { + return dispatch => { + const comment = { + status: 'Untouched', + 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})); + }; +}; + + /** * Action disptacher related to comments */ @@ -12,10 +81,6 @@ export const flagComment = id => (dispatch, getState) => { dispatch({type: 'COMMENT_UPDATE', comment: getState().comments.get('byId').get(id)}); }; -export const createComment = (name, body) => dispatch => { - dispatch({type: 'COMMENT_CREATE', name, body}); -}; - // Dialog Actions export const showBanUserDialog = (userId, userName, commentId) => { return dispatch => { diff --git a/client/coral-admin/src/actions/users.js b/client/coral-admin/src/actions/users.js index f2ff37cbd..f1c9e6972 100644 --- a/client/coral-admin/src/actions/users.js +++ b/client/coral-admin/src/actions/users.js @@ -1,14 +1,20 @@ +import coralApi from '../../../coral-framework/helpers/response'; /** * Action disptacher related to users */ -// -// export const banUser = (status, author_id) => (dispatch) => { -// dispatch({type: 'USER_STATUS_UPDATE', author_id, status}); +// export const banUser = (status, userId, commentId) => { +// return dispatch => { +// dispatch({type: 'USER_BAN', status, userId, commentId}); +// dispatch({type: 'COMMENTS_MODERATION_QUEUE_FETCH'}); +// }; // }; -export const banUser = (status, userId, commentId) => { + +// change status of a user +export const userStatusUpdate = (status, userId, commentId) => { return dispatch => { - dispatch({type: 'USER_BAN', status, userId, commentId}); - dispatch({type: 'COMMENTS_MODERATION_QUEUE_FETCH'}); + return coralApi(`/users/${userId}/status`, {method: 'POST', body: {status: status, comment_id: commentId}}) + .then(res => dispatch({type: 'USER_BAN_SUCESS', res})) + .catch(error => dispatch({type: 'USER_BAN_FAILED', error})); }; }; diff --git a/client/coral-admin/src/constants/comments.js b/client/coral-admin/src/constants/comments.js index 856f619d0..db954ad2c 100644 --- a/client/coral-admin/src/constants/comments.js +++ b/client/coral-admin/src/constants/comments.js @@ -1,3 +1,8 @@ export const SHOW_BANUSER_DIALOG = 'SHOW_BANUSER_DIALOG'; export const HIDE_BANUSER_DIALOG = 'HIDE_BANUSER_DIALOG'; export const USER_BAN_SUCESS = 'USER_BAN_SUCESS'; +export const USERS_MODERATION_QUEUE_FETCH_SUCCESS = 'USERS_MODERATION_QUEUE_FETCH_SUCCESS'; +export const COMMENTS_MODERATION_QUEUE_FETCH_SUCCESS = 'COMMENTS_MODERATION_QUEUE_FETCH_SUCCESS'; +export const COMMENT_CREATE_SUCCESS = 'COMMENT_CREATE_SUCCESS'; +export const COMMENT_CREATE_FAILED = 'COMMENT_CREATE_FAILED'; +export const COMMENT_STREAM_FETCH_SUCCESS = 'COMMENT_STREAM_FETCH_SUCCESS'; diff --git a/client/coral-admin/src/containers/ModerationQueue/ModerationQueue.js b/client/coral-admin/src/containers/ModerationQueue/ModerationQueue.js index e0e3c636f..3df0d210b 100644 --- a/client/coral-admin/src/containers/ModerationQueue/ModerationQueue.js +++ b/client/coral-admin/src/containers/ModerationQueue/ModerationQueue.js @@ -6,8 +6,13 @@ import ModerationKeysModal from 'components/ModerationKeysModal'; import CommentList from 'components/CommentList'; import BanUserDialog from 'components/BanUserDialog'; -import {updateStatus, showBanUserDialog, hideBanUserDialog} from 'actions/comments'; -import {banUser} from 'actions/users'; +import { + updateStatus, + showBanUserDialog, + hideBanUserDialog, + fetchModerationQueueComments +} from 'actions/comments'; +import {userStatusUpdate} from 'actions/users'; import styles from './ModerationQueue.css'; import I18n from 'coral-framework/modules/i18n/i18n'; @@ -31,7 +36,7 @@ class ModerationQueue extends React.Component { // Fetch comments and bind singleView key before render componentWillMount () { - this.props.dispatch({type: 'COMMENTS_MODERATION_QUEUE_FETCH'}); + this.props.dispatch(fetchModerationQueueComments()); key('s', () => this.setState({singleView: !this.state.singleView})); key('shift+/', () => this.setState({modalOpen: true})); key('esc', () => this.setState({modalOpen: false})); @@ -67,7 +72,10 @@ class ModerationQueue extends React.Component { } banUser (userId, commentId) { - this.props.dispatch(banUser('banned', userId, commentId)); + this.props.dispatch(userStatusUpdate('banned', userId, commentId)) + .then(() => { + this.props.dispatch(fetchModerationQueueComments()); + }); } onTabClick (activeTab) { diff --git a/client/coral-admin/src/reducers/comments.js b/client/coral-admin/src/reducers/comments.js index dca726b5e..b9f77692e 100644 --- a/client/coral-admin/src/reducers/comments.js +++ b/client/coral-admin/src/reducers/comments.js @@ -28,8 +28,8 @@ export default (state = initialState, action) => { case 'COMMENTS_MODERATION_QUEUE_FAILED': return state.set('loading', false); case 'COMMENT_STATUS_UPDATE': return updateStatus(state, action); case 'COMMENT_FLAG': return flag(state, action); - case 'COMMENT_CREATE_SUCCESS': return addComment(state, action); - case 'COMMENT_STREAM_FETCH_SUCCESS': return replaceComments(action, state); + case actions.COMMENT_CREATE_SUCCESS: return addComment(state, action); + case actions.COMMENT_STREAM_FETCH_SUCCESS: return replaceComments(action, state); case actions.SHOW_BANUSER_DIALOG: return setBanUser(state, true, action); case actions.HIDE_BANUSER_DIALOG: return setBanUser(state, false, action); case actions.USER_BAN_SUCESS: return setBanUser(state, false, action); diff --git a/client/coral-admin/src/services/talk-adapter.js b/client/coral-admin/src/services/talk-adapter.js index 7c9bc968f..6c9f3978c 100644 --- a/client/coral-admin/src/services/talk-adapter.js +++ b/client/coral-admin/src/services/talk-adapter.js @@ -12,59 +12,14 @@ import coralApi from '../../../coral-framework/helpers/response'; export default store => next => action => { switch (action.type) { - case 'COMMENTS_MODERATION_QUEUE_FETCH': - fetchModerationQueueComments(store); - break; case 'COMMENT_UPDATE': updateComment(store, action.comment); break; - case 'COMMENT_CREATE': - createComment(store, action.name, action.body); - break; - case 'USER_BAN': - userStatusUpdate(store, action.status, action.userId, action.commentId); - break; } next(action); }; -// Get comments to fill each of the three lists on the mod queue -const fetchModerationQueueComments = store => - -Promise.all([ - coralApi('/queue/comments/pending'), - coralApi('/comments?status=rejected'), - coralApi('/comments?action_type=flag') -]) -.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; -}) -.then(all => { - - /* Post comments and users to redux store. Actions will be posted when they are needed. */ - store.dispatch({type: 'USERS_MODERATION_QUEUE_FETCH_SUCCESS', - users: all.users}); - store.dispatch({type: 'COMMENTS_MODERATION_QUEUE_FETCH_SUCCESS', - comments: all.comments}); - -}); - // .catch(error => store.dispatch({type: 'COMMENTS_MODERATION_QUEUE_FETCH_FAILED', error})); // Update a comment. Now to update a comment we need to send back the whole object @@ -74,23 +29,3 @@ const updateComment = (store, comment) => { .then(res => store.dispatch({type: 'COMMENT_UPDATE_SUCCESS', res})) .catch(error => store.dispatch({type: 'COMMENT_UPDATE_FAILED', error})); }; - -// Create a new comment -const createComment = (store, name, comment) => { - const body = { - status: 'Untouched', - body: comment, - name: name, - createdAt: Date.now() - }; - return coralApi('/comments', {method: 'POST', body}) - .then(res => store.dispatch({type: 'COMMENT_CREATE_SUCCESS', comment: res})) - .catch(error => store.dispatch({type: 'COMMENT_CREATE_FAILED', error})); -}; - -// Ban a user -const userStatusUpdate = (store, status, userId, commentId) => { - return coralApi(`/users/${userId}/status`, {method: 'POST', body: {status: status, comment_id: commentId}}) - .then(res => store.dispatch({type: 'USER_BAN_SUCESS', res})) - .catch(error => store.dispatch({type: 'USER_BAN_FAILED', error})); -}; From 11d8b2cd915b7d46cfe917a1a01bb15d68851558 Mon Sep 17 00:00:00 2001 From: Riley Davis Date: Tue, 20 Dec 2016 12:39:57 -0700 Subject: [PATCH 2/9] update a comment's status --- client/coral-admin/src/actions/comments.js | 22 +++++-------- client/coral-admin/src/actions/users.js | 7 ----- client/coral-admin/src/components/Comment.js | 2 +- client/coral-admin/src/constants/comments.js | 3 ++ .../ModerationQueue/ModerationQueue.js | 10 +++--- client/coral-admin/src/services/store.js | 3 +- .../coral-admin/src/services/talk-adapter.js | 31 ------------------- 7 files changed, 18 insertions(+), 60 deletions(-) delete mode 100644 client/coral-admin/src/services/talk-adapter.js diff --git a/client/coral-admin/src/actions/comments.js b/client/coral-admin/src/actions/comments.js index f89cb5dd3..79af56fd0 100644 --- a/client/coral-admin/src/actions/comments.js +++ b/client/coral-admin/src/actions/comments.js @@ -41,17 +41,6 @@ export const fetchModerationQueueComments = () => { }; }; - -// .catch(error => store.dispatch({type: 'COMMENTS_MODERATION_QUEUE_FETCH_FAILED', error})); - -// Update a comment. Now to update a comment we need to send back the whole object - -export const updateComment = (store, comment) => { - coralApi(`/comments/${comment.get('id')}/status`, {method: 'PUT', body: {status: comment.get('status')}}) - .then(res => store.dispatch({type: 'COMMENT_UPDATE_SUCCESS', res})) - .catch(error => store.dispatch({type: 'COMMENT_UPDATE_FAILED', error})); -}; - // Create a new comment export const createComment = (name, body) => { return dispatch => { @@ -71,9 +60,14 @@ export const createComment = (name, body) => { * Action disptacher related to comments */ -export const updateStatus = (status, id) => (dispatch, getState) => { - dispatch({type: 'COMMENT_STATUS_UPDATE', id, status}); - dispatch({type: 'COMMENT_UPDATE', comment: getState().comments.get('byId').get(id)}); +// 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}); + return coralApi(`/comments/${comment.id}/status`, {method: 'PUT', body: {status: comment.status}}) + .then(res => dispatch({type: actions.COMMENT_UPDATE_SUCCESS, res})) + .catch(error => dispatch({type: actions.COMMENT_UPDATE_FAILED, error})); + }; }; export const flagComment = id => (dispatch, getState) => { diff --git a/client/coral-admin/src/actions/users.js b/client/coral-admin/src/actions/users.js index f1c9e6972..07d7dff3a 100644 --- a/client/coral-admin/src/actions/users.js +++ b/client/coral-admin/src/actions/users.js @@ -3,13 +3,6 @@ import coralApi from '../../../coral-framework/helpers/response'; /** * Action disptacher related to users */ -// export const banUser = (status, userId, commentId) => { -// return dispatch => { -// dispatch({type: 'USER_BAN', status, userId, commentId}); -// dispatch({type: 'COMMENTS_MODERATION_QUEUE_FETCH'}); -// }; -// }; - // change status of a user export const userStatusUpdate = (status, userId, commentId) => { return dispatch => { diff --git a/client/coral-admin/src/components/Comment.js b/client/coral-admin/src/components/Comment.js index 84c0e0541..291825c71 100644 --- a/client/coral-admin/src/components/Comment.js +++ b/client/coral-admin/src/components/Comment.js @@ -79,7 +79,7 @@ const getActionButton = (action, i, props) => { cStyle={action} icon={props.actionsMap[action].icon} key={i} - onClick={() => props.onClickAction(props.actionsMap[action].status, comment.id)} + onClick={() => props.onClickAction(props.actionsMap[action].status, comment)} /> ); }; diff --git a/client/coral-admin/src/constants/comments.js b/client/coral-admin/src/constants/comments.js index db954ad2c..7e6c46fb1 100644 --- a/client/coral-admin/src/constants/comments.js +++ b/client/coral-admin/src/constants/comments.js @@ -6,3 +6,6 @@ export const COMMENTS_MODERATION_QUEUE_FETCH_SUCCESS = 'COMMENTS_MODERATION_QUEU export const COMMENT_CREATE_SUCCESS = 'COMMENT_CREATE_SUCCESS'; export const COMMENT_CREATE_FAILED = 'COMMENT_CREATE_FAILED'; export const COMMENT_STREAM_FETCH_SUCCESS = 'COMMENT_STREAM_FETCH_SUCCESS'; +export const COMMENT_UPDATE_SUCCESS = 'COMMENT_UPDATE_SUCCESS'; +export const COMMENT_UPDATE_FAILED = 'COMMENT_UPDATE_FAILED'; +export const COMMENT_STATUS_UPDATE = 'COMMENT_STATUS_UPDATE'; diff --git a/client/coral-admin/src/containers/ModerationQueue/ModerationQueue.js b/client/coral-admin/src/containers/ModerationQueue/ModerationQueue.js index 3df0d210b..40d8d9dce 100644 --- a/client/coral-admin/src/containers/ModerationQueue/ModerationQueue.js +++ b/client/coral-admin/src/containers/ModerationQueue/ModerationQueue.js @@ -58,9 +58,9 @@ class ModerationQueue extends React.Component { } // Dispatch the update status action - onCommentAction (action, id) { + onCommentAction (action, comment) { // If not banning then change the status to approved or flagged as action = status - this.props.dispatch(updateStatus(action, id)); + this.props.dispatch(updateStatus(action, comment)); } showBanUserDialog (userId, userName, commentId) { @@ -109,7 +109,7 @@ class ModerationQueue extends React.Component { commentIds={premodIds} comments={comments.byId} users={users.byId} - onClickAction={(action, commentId) => this.onCommentAction(action, commentId)} + onClickAction={(action, comment) => this.onCommentAction(action, comment)} onClickShowBanDialog={(userId, userName, commentId) => this.showBanUserDialog(userId, userName, commentId)} actions={['reject', 'approve', 'ban']} loading={comments.loading} /> @@ -126,7 +126,7 @@ class ModerationQueue extends React.Component { commentIds={rejectedIds} comments={comments.byId} users={users.byId} - onClickAction={(action, id) => this.onCommentAction(action, id)} + onClickAction={(action, comment) => this.onCommentAction(action, comment)} actions={['approve']} loading={comments.loading} /> @@ -137,7 +137,7 @@ class ModerationQueue extends React.Component { commentIds={flaggedIds} comments={comments.byId} users={users.byId} - onClickAction={(action, id) => this.onCommentAction(action, id)} + onClickAction={(action, comment) => this.onCommentAction(action, comment)} actions={['reject', 'approve']} loading={comments.loading} /> diff --git a/client/coral-admin/src/services/store.js b/client/coral-admin/src/services/store.js index 88b2650e0..0700dc579 100644 --- a/client/coral-admin/src/services/store.js +++ b/client/coral-admin/src/services/store.js @@ -2,7 +2,6 @@ import {createStore, applyMiddleware} from 'redux'; import thunk from 'redux-thunk'; import mainReducer from 'reducers'; -import talkAdapter from 'services/talk-adapter'; /** * Create the store by merging the app reducers with @@ -14,5 +13,5 @@ import talkAdapter from 'services/talk-adapter'; export default createStore( mainReducer, window.devToolsExtension && window.devToolsExtension(), - applyMiddleware(thunk, talkAdapter) + applyMiddleware(thunk) ); diff --git a/client/coral-admin/src/services/talk-adapter.js b/client/coral-admin/src/services/talk-adapter.js deleted file mode 100644 index 6c9f3978c..000000000 --- a/client/coral-admin/src/services/talk-adapter.js +++ /dev/null @@ -1,31 +0,0 @@ -import coralApi from '../../../coral-framework/helpers/response'; - -/** - * The adapter is a redux middleware that interecepts the actions that need - * to interface with the backend, do the job and return the results. - * The idea is that if we expose the required actions to handle to devs, the - * moderation app can be platform agnostic. This same client could work not only - * for the coral but also for wordpress comments, disqus and many more. - */ - -// Intercept redux actions and act over the ones we are interested -export default store => next => action => { - - switch (action.type) { - case 'COMMENT_UPDATE': - updateComment(store, action.comment); - break; - } - - next(action); -}; - -// .catch(error => store.dispatch({type: 'COMMENTS_MODERATION_QUEUE_FETCH_FAILED', error})); - -// Update a comment. Now to update a comment we need to send back the whole object - -const updateComment = (store, comment) => { - coralApi(`/comments/${comment.get('id')}/status`, {method: 'PUT', body: {status: comment.get('status')}}) - .then(res => store.dispatch({type: 'COMMENT_UPDATE_SUCCESS', res})) - .catch(error => store.dispatch({type: 'COMMENT_UPDATE_FAILED', error})); -}; From 268f6616a5da0faf92440768f7832e04f5cdd67e Mon Sep 17 00:00:00 2001 From: Riley Davis Date: Tue, 20 Dec 2016 12:45:30 -0700 Subject: [PATCH 3/9] update the status correctly --- client/coral-admin/src/actions/comments.js | 4 ++-- client/coral-admin/src/constants/comments.js | 1 + client/coral-admin/src/reducers/comments.js | 4 ++-- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/client/coral-admin/src/actions/comments.js b/client/coral-admin/src/actions/comments.js index 79af56fd0..9d2fb525f 100644 --- a/client/coral-admin/src/actions/comments.js +++ b/client/coral-admin/src/actions/comments.js @@ -64,14 +64,14 @@ export const createComment = (name, body) => { export const updateStatus = (status, comment) => { return dispatch => { dispatch({type: actions.COMMENT_STATUS_UPDATE, id: comment.id, status}); - return coralApi(`/comments/${comment.id}/status`, {method: 'PUT', body: {status: comment.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})); }; }; export const flagComment = id => (dispatch, getState) => { - dispatch({type: 'COMMENT_FLAG', id}); + dispatch({type: actions.COMMENT_FLAG, id}); dispatch({type: 'COMMENT_UPDATE', comment: getState().comments.get('byId').get(id)}); }; diff --git a/client/coral-admin/src/constants/comments.js b/client/coral-admin/src/constants/comments.js index 7e6c46fb1..e95cb12c1 100644 --- a/client/coral-admin/src/constants/comments.js +++ b/client/coral-admin/src/constants/comments.js @@ -9,3 +9,4 @@ export const COMMENT_STREAM_FETCH_SUCCESS = 'COMMENT_STREAM_FETCH_SUCCESS'; export const COMMENT_UPDATE_SUCCESS = 'COMMENT_UPDATE_SUCCESS'; export const COMMENT_UPDATE_FAILED = 'COMMENT_UPDATE_FAILED'; export const COMMENT_STATUS_UPDATE = 'COMMENT_STATUS_UPDATE'; +export const COMMENT_FLAG = 'COMMENT_FLAG'; diff --git a/client/coral-admin/src/reducers/comments.js b/client/coral-admin/src/reducers/comments.js index b9f77692e..caa356e57 100644 --- a/client/coral-admin/src/reducers/comments.js +++ b/client/coral-admin/src/reducers/comments.js @@ -26,8 +26,8 @@ export default (state = initialState, action) => { case 'COMMENTS_MODERATION_QUEUE_FETCH': return state.set('loading', true); case 'COMMENTS_MODERATION_QUEUE_FETCH_SUCCESS': return replaceComments(action, state); case 'COMMENTS_MODERATION_QUEUE_FAILED': return state.set('loading', false); - case 'COMMENT_STATUS_UPDATE': return updateStatus(state, action); - case 'COMMENT_FLAG': return flag(state, action); + case actions.COMMENT_STATUS_UPDATE: return updateStatus(state, action); + case actions.COMMENT_FLAG: return flag(state, action); case actions.COMMENT_CREATE_SUCCESS: return addComment(state, action); case actions.COMMENT_STREAM_FETCH_SUCCESS: return replaceComments(action, state); case actions.SHOW_BANUSER_DIALOG: return setBanUser(state, true, action); From 0a19a284ab379c5c701737019e3c564927ad520d Mon Sep 17 00:00:00 2001 From: Riley Davis Date: Tue, 20 Dec 2016 12:47:23 -0700 Subject: [PATCH 4/9] simplify banUser dialog action creators --- client/coral-admin/src/actions/comments.js | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/client/coral-admin/src/actions/comments.js b/client/coral-admin/src/actions/comments.js index 9d2fb525f..20ff326e9 100644 --- a/client/coral-admin/src/actions/comments.js +++ b/client/coral-admin/src/actions/comments.js @@ -77,13 +77,9 @@ export const flagComment = id => (dispatch, getState) => { // Dialog Actions export const showBanUserDialog = (userId, userName, commentId) => { - return dispatch => { - dispatch({type: 'SHOW_BANUSER_DIALOG', userId, userName, commentId}); - }; + return {type: 'SHOW_BANUSER_DIALOG', userId, userName, commentId}; }; export const hideBanUserDialog = (showDialog) => { - return dispatch => { - dispatch({type: 'HIDE_BANUSER_DIALOG', showDialog}); - }; + return {type: 'HIDE_BANUSER_DIALOG', showDialog}; }; From 96ed008b96b9b3876a6b10e65700c33467ce2884 Mon Sep 17 00:00:00 2001 From: Riley Davis Date: Tue, 20 Dec 2016 12:50:12 -0700 Subject: [PATCH 5/9] remove some more string literals --- client/coral-admin/src/actions/comments.js | 1 + client/coral-admin/src/constants/comments.js | 1 + client/coral-admin/src/reducers/comments.js | 6 +++--- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/client/coral-admin/src/actions/comments.js b/client/coral-admin/src/actions/comments.js index 20ff326e9..2b8f431ec 100644 --- a/client/coral-admin/src/actions/comments.js +++ b/client/coral-admin/src/actions/comments.js @@ -6,6 +6,7 @@ import * as actions from '../constants/comments'; export const fetchModerationQueueComments = () => { return dispatch => { + dispatch({type: actions.COMMENTS_MODERATION_QUEUE_FETCH}); return Promise.all([ coralApi('/queue/comments/pending'), coralApi('/comments?status=rejected'), diff --git a/client/coral-admin/src/constants/comments.js b/client/coral-admin/src/constants/comments.js index e95cb12c1..c75911587 100644 --- a/client/coral-admin/src/constants/comments.js +++ b/client/coral-admin/src/constants/comments.js @@ -2,6 +2,7 @@ export const SHOW_BANUSER_DIALOG = 'SHOW_BANUSER_DIALOG'; export const HIDE_BANUSER_DIALOG = 'HIDE_BANUSER_DIALOG'; export const USER_BAN_SUCESS = 'USER_BAN_SUCESS'; export const USERS_MODERATION_QUEUE_FETCH_SUCCESS = 'USERS_MODERATION_QUEUE_FETCH_SUCCESS'; +export const COMMENTS_MODERATION_QUEUE_FETCH = 'COMMENTS_MODERATION_QUEUE_FETCH'; export const COMMENTS_MODERATION_QUEUE_FETCH_SUCCESS = 'COMMENTS_MODERATION_QUEUE_FETCH_SUCCESS'; export const COMMENT_CREATE_SUCCESS = 'COMMENT_CREATE_SUCCESS'; export const COMMENT_CREATE_FAILED = 'COMMENT_CREATE_FAILED'; diff --git a/client/coral-admin/src/reducers/comments.js b/client/coral-admin/src/reducers/comments.js index caa356e57..1ab341595 100644 --- a/client/coral-admin/src/reducers/comments.js +++ b/client/coral-admin/src/reducers/comments.js @@ -23,9 +23,9 @@ const initialState = Map({ // Handle the comment actions export default (state = initialState, action) => { switch (action.type) { - case 'COMMENTS_MODERATION_QUEUE_FETCH': return state.set('loading', true); - case 'COMMENTS_MODERATION_QUEUE_FETCH_SUCCESS': return replaceComments(action, state); - case 'COMMENTS_MODERATION_QUEUE_FAILED': return state.set('loading', false); + case actions.COMMENTS_MODERATION_QUEUE_FETCH: return state.set('loading', true); + case actions.COMMENTS_MODERATION_QUEUE_FETCH_SUCCESS: return replaceComments(action, state); + case actions.COMMENTS_MODERATION_QUEUE_FAILED: return state.set('loading', false); case actions.COMMENT_STATUS_UPDATE: return updateStatus(state, action); case actions.COMMENT_FLAG: return flag(state, action); case actions.COMMENT_CREATE_SUCCESS: return addComment(state, action); From 7a1c3e730bbbde547d642273ac1fadf623832eaa Mon Sep 17 00:00:00 2001 From: Riley Davis Date: Tue, 20 Dec 2016 12:56:44 -0700 Subject: [PATCH 6/9] fix lint --- client/coral-admin/src/actions/comments.js | 2 -- client/coral-admin/src/containers/Configure/CommentSettings.js | 1 + .../src/containers/ModerationQueue/ModerationQueue.js | 2 ++ 3 files changed, 3 insertions(+), 2 deletions(-) diff --git a/client/coral-admin/src/actions/comments.js b/client/coral-admin/src/actions/comments.js index 2b8f431ec..448bba48a 100644 --- a/client/coral-admin/src/actions/comments.js +++ b/client/coral-admin/src/actions/comments.js @@ -1,7 +1,6 @@ import coralApi from '../../../coral-framework/helpers/response'; import * as actions from '../constants/comments'; - // Get comments to fill each of the three lists on the mod queue export const fetchModerationQueueComments = () => { return dispatch => { @@ -56,7 +55,6 @@ export const createComment = (name, body) => { }; }; - /** * Action disptacher related to comments */ diff --git a/client/coral-admin/src/containers/Configure/CommentSettings.js b/client/coral-admin/src/containers/Configure/CommentSettings.js index 050432743..6bcf1194b 100644 --- a/client/coral-admin/src/containers/Configure/CommentSettings.js +++ b/client/coral-admin/src/containers/Configure/CommentSettings.js @@ -71,6 +71,7 @@ const updateClosedTimeout = (updateSettings, ts, isMeasure) => (event) => { const CommentSettings = ({fetchingSettings, updateSettings, settingsError, settings, errors}) => { if (fetchingSettings) { + /* maybe a spinner here at some point */ return

Loading settings...

; } diff --git a/client/coral-admin/src/containers/ModerationQueue/ModerationQueue.js b/client/coral-admin/src/containers/ModerationQueue/ModerationQueue.js index 40d8d9dce..5e0bfd3a3 100644 --- a/client/coral-admin/src/containers/ModerationQueue/ModerationQueue.js +++ b/client/coral-admin/src/containers/ModerationQueue/ModerationQueue.js @@ -52,6 +52,7 @@ class ModerationQueue extends React.Component { // Hack for dynamic mdl tabs componentDidMount () { if (typeof componentHandler !== 'undefined') { + // FIXME: fix this hack componentHandler.upgradeAllRegistered(); // eslint-disable-line no-undef } @@ -59,6 +60,7 @@ class ModerationQueue extends React.Component { // Dispatch the update status action onCommentAction (action, comment) { + // If not banning then change the status to approved or flagged as action = status this.props.dispatch(updateStatus(action, comment)); } From 96141d8abc75deda8e14c72dbca70b179035c529 Mon Sep 17 00:00:00 2001 From: Riley Davis Date: Tue, 20 Dec 2016 13:23:36 -0700 Subject: [PATCH 7/9] remove status from new comment --- client/coral-admin/src/actions/comments.js | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/client/coral-admin/src/actions/comments.js b/client/coral-admin/src/actions/comments.js index 448bba48a..a2a5965e2 100644 --- a/client/coral-admin/src/actions/comments.js +++ b/client/coral-admin/src/actions/comments.js @@ -44,11 +44,7 @@ export const fetchModerationQueueComments = () => { // Create a new comment export const createComment = (name, body) => { return dispatch => { - const comment = { - status: 'Untouched', - body, - name - }; + 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})); From 55c5f6d5bec9b482089ac894d32467c2238dc7ad Mon Sep 17 00:00:00 2001 From: Riley Davis Date: Tue, 20 Dec 2016 13:25:21 -0700 Subject: [PATCH 8/9] 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}; }; From 7351aecade0d08c7c1ff7ce957c10e9b1e0449ff Mon Sep 17 00:00:00 2001 From: Riley Davis Date: Tue, 20 Dec 2016 13:48:00 -0700 Subject: [PATCH 9/9] update user constants --- client/coral-admin/src/actions/comments.js | 2 +- client/coral-admin/src/actions/users.js | 6 ++++-- client/coral-admin/src/constants/user.js | 3 +++ client/coral-admin/src/reducers/comments.js | 3 ++- 4 files changed, 10 insertions(+), 4 deletions(-) create mode 100644 client/coral-admin/src/constants/user.js diff --git a/client/coral-admin/src/actions/comments.js b/client/coral-admin/src/actions/comments.js index 89cd87d89..e755f1ed1 100644 --- a/client/coral-admin/src/actions/comments.js +++ b/client/coral-admin/src/actions/comments.js @@ -20,7 +20,7 @@ export const fetchModerationQueueComments = () => { actions: [...pending.actions, ...rejected.actions, ...flagged.actions] }; }) - .then(({comments, users, actions}) => { + .then(({comments, users}) => { /* Post comments and users to redux store. Actions will be posted when they are needed. */ dispatch({type: commentActions.USERS_MODERATION_QUEUE_FETCH_SUCCESS, users}); diff --git a/client/coral-admin/src/actions/users.js b/client/coral-admin/src/actions/users.js index 07d7dff3a..bc42a7a4c 100644 --- a/client/coral-admin/src/actions/users.js +++ b/client/coral-admin/src/actions/users.js @@ -1,4 +1,5 @@ import coralApi from '../../../coral-framework/helpers/response'; +import * as actions from '../constants/user'; /** * Action disptacher related to users @@ -6,8 +7,9 @@ import coralApi from '../../../coral-framework/helpers/response'; // change status of a user export const userStatusUpdate = (status, userId, commentId) => { return dispatch => { + dispatch({type: actions.UPDATE_STATUS_REQUEST}); return coralApi(`/users/${userId}/status`, {method: 'POST', body: {status: status, comment_id: commentId}}) - .then(res => dispatch({type: 'USER_BAN_SUCESS', res})) - .catch(error => dispatch({type: 'USER_BAN_FAILED', error})); + .then(res => dispatch({type: actions.UPDATE_STATUS_SUCCESS, res})) + .catch(error => dispatch({type: actions.UPDATE_STATUS_FAILURE, error})); }; }; diff --git a/client/coral-admin/src/constants/user.js b/client/coral-admin/src/constants/user.js new file mode 100644 index 000000000..8c0563237 --- /dev/null +++ b/client/coral-admin/src/constants/user.js @@ -0,0 +1,3 @@ +export const UPDATE_STATUS_REQUEST = 'UPDATE_STATUS_REQUEST'; +export const UPDATE_STATUS_SUCCESS = 'UPDATE_STATUS_SUCCESS'; +export const UPDATE_STATUS_FAILURE = 'UPDATE_STATUS_FAILURE'; diff --git a/client/coral-admin/src/reducers/comments.js b/client/coral-admin/src/reducers/comments.js index 1ab341595..2856b0a34 100644 --- a/client/coral-admin/src/reducers/comments.js +++ b/client/coral-admin/src/reducers/comments.js @@ -1,4 +1,5 @@ import * as actions from '../constants/comments'; +import * as userActions from '../constants/user'; import {Map, List, fromJS} from 'immutable'; /** @@ -32,7 +33,7 @@ export default (state = initialState, action) => { case actions.COMMENT_STREAM_FETCH_SUCCESS: return replaceComments(action, state); case actions.SHOW_BANUSER_DIALOG: return setBanUser(state, true, action); case actions.HIDE_BANUSER_DIALOG: return setBanUser(state, false, action); - case actions.USER_BAN_SUCESS: return setBanUser(state, false, action); + case userActions.UPDATE_STATUS_SUCCESS: return setBanUser(state, false, action); default: return state; } };