From a234eeb3ba4967841034a08269b535538d1e88a4 Mon Sep 17 00:00:00 2001 From: David Erwin Date: Thu, 10 Nov 2016 10:49:55 -0500 Subject: [PATCH] Add json header, update status, and lint --- client/coral-admin/src/components/CommentList.js | 4 ++-- client/coral-admin/src/services/talk-adapter.js | 16 ++++++++++------ routes/api/comments/index.js | 11 ++++++----- 3 files changed, 18 insertions(+), 13 deletions(-) diff --git a/client/coral-admin/src/components/CommentList.js b/client/coral-admin/src/components/CommentList.js index ae74272e7..819de62b0 100644 --- a/client/coral-admin/src/components/CommentList.js +++ b/client/coral-admin/src/components/CommentList.js @@ -7,8 +7,8 @@ import Comment from 'components/Comment'; // Each action has different meaning and configuration const actions = { - 'reject': {status: 'Rejected', icon: 'close', key: 'r'}, - 'approve': {status: 'Approved', icon: 'done', key: 't'}, + 'reject': {status: 'rejected', icon: 'close', key: 'r'}, + 'approve': {status: 'accepted', icon: 'done', key: 't'}, 'flag': {status: 'flagged', icon: 'flag', filter: 'Untouched'} }; diff --git a/client/coral-admin/src/services/talk-adapter.js b/client/coral-admin/src/services/talk-adapter.js index 3f0c8b567..ba8ec369b 100644 --- a/client/coral-admin/src/services/talk-adapter.js +++ b/client/coral-admin/src/services/talk-adapter.js @@ -7,6 +7,9 @@ * for the coral but also for wordpress comments, disqus and many more. */ +// Default headers for json payloads. +const jsonHeader = new Headers({'Content-Type': 'application/json'}); + // Intercept redux actions and act over the ones we are interested export default store => next => action => { @@ -18,7 +21,6 @@ export default store => next => action => { // fetchCommentStream(store); // break; case 'COMMENT_UPDATE': - console.log('asdadasd') updateComment(store, action.comment); break; case 'COMMENT_CREATE': @@ -44,14 +46,16 @@ Promise.all([fetch('/api/v1/comments/status/pending'), fetch('/api/v1/comments/s // Update a comment. Now to update a comment we need to send back the whole object const updateComment = (store, comment) => { -fetch(`/api/v1/comments/${comment.get('id')}/status`, { - method: 'POST', - body: JSON.stringify({status: comment.get('status')}) -}) + fetch(`/api/v1/comments/${comment.get('id')}/status`, { + method: 'POST', + headers: jsonHeader, + body: JSON.stringify({status: comment.get('status')}) + }) .then(res => res.json()) .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) => fetch('/api/v1/comments', { diff --git a/routes/api/comments/index.js b/routes/api/comments/index.js index 73ae3dea3..a2e77b417 100644 --- a/routes/api/comments/index.js +++ b/routes/api/comments/index.js @@ -94,11 +94,12 @@ router.post('/:comment_id', (req, res, next) => { }); router.post('/:comment_id/status', (req, res, next) => { - Comment.changeStatus(req.params.comment_id, req.body.status).then((comment) => { - res.status(200).send(comment); - }).catch(error => { - next(error); - }); + + Comment + .changeStatus(req.params.comment_id, req.body.status) + .then(comment => res.status(200).send(comment)) + .catch(error => next(error)); + }); router.post('/:comment_id/actions', (req, res, next) => {