add(coral-admin): Working actions

This commit is contained in:
Dan Zajdband
2016-11-09 17:27:44 -05:00
parent c80bd19b85
commit 99f0e77ce1
4 changed files with 3577 additions and 9 deletions
+1 -1
View File
@@ -19,7 +19,7 @@ export default props => (
<div className={styles.actions}>
{props.actions.map(action => canShowAction(action, props.comment) ? (
<Button className={styles.actionButton}
onClick={() => props.onClickAction(props.actionsMap[action].status, props.comment.get('_id'))}
onClick={() => props.onClickAction(props.actionsMap[action].status, props.comment.get('id'))}
fab colored>
<Icon name={props.actionsMap[action].icon} />
</Button>
+3 -4
View File
@@ -31,9 +31,8 @@ export default (state = initialState, action) => {
// Update a comment status
const updateStatus = (state, action) => {
const byId = state.get('byId');
const data = byId.get(action.id).get('data').set('status', action.status);
const comment = byId.get(action.id).set('data', data);
return state.set('byId', byId.set(action.id, comment));
const data = byId.get(action.id).set('status', action.status.toLowerCase());
return state.set('byId', byId.set(action.id, data));
};
// Flag a comment
@@ -46,7 +45,7 @@ const flag = (state, action) => {
// Replace the comment list with a new one
const replaceComments = (action, state) => {
const comments = fromJS(action.comments.reduce((prev, curr) => { prev[curr._id] = curr; return prev; }, {}));
const comments = fromJS(action.comments.reduce((prev, curr) => { prev[curr.id] = curr; return prev; }, {}));
return state.set('byId', comments).set('loading', false)
.set('ids', List(comments.keys()));
};
@@ -9,6 +9,7 @@
// Intercept redux actions and act over the ones we are interested
export default store => next => action => {
switch (action.type) {
case 'COMMENTS_MODERATION_QUEUE_FETCH':
fetchModerationQueueComments(store);
@@ -17,6 +18,7 @@ export default store => next => action => {
// fetchCommentStream(store);
// break;
case 'COMMENT_UPDATE':
console.log('asdadasd')
updateComment(store, action.comment);
break;
case 'COMMENT_CREATE':
@@ -41,15 +43,15 @@ Promise.all([fetch('/api/v1/comments/status/pending'), fetch('/api/v1/comments/s
.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) =>
fetch('/api/v1/comments/${comment._id}/status', {
const updateComment = (store, comment) => {
fetch(`/api/v1/comments/${comment.get('id')}/status`, {
method: 'POST',
body: JSON.stringify({status: comment.status})
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', {
File diff suppressed because it is too large Load Diff