mirror of
https://github.com/wassname/talk.git
synced 2026-07-03 01:10:05 +08:00
Merge pull request #49 from coralproject/actions-working
add(coral-admin): Working actions
This commit is contained in:
@@ -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>
|
||||
|
||||
@@ -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'}
|
||||
};
|
||||
|
||||
|
||||
@@ -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()));
|
||||
};
|
||||
|
||||
@@ -7,8 +7,12 @@
|
||||
* 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 => {
|
||||
|
||||
switch (action.type) {
|
||||
case 'COMMENTS_MODERATION_QUEUE_FETCH':
|
||||
fetchModerationQueueComments(store);
|
||||
@@ -41,14 +45,16 @@ 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', {
|
||||
method: 'POST',
|
||||
body: JSON.stringify({status: comment.status})
|
||||
})
|
||||
const updateComment = (store, comment) => {
|
||||
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) =>
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -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) => {
|
||||
|
||||
Reference in New Issue
Block a user