mirror of
https://github.com/wassname/talk.git
synced 2026-08-20 12:50:41 +08:00
Adding and testing function to fetch assets in talk reducer.
This commit is contained in:
@@ -1,3 +1,3 @@
|
||||
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 USER_BAN_SUCCESS = 'USER_BAN_SUCCESS';
|
||||
|
||||
@@ -32,7 +32,7 @@ export default (state = initialState, action) => {
|
||||
case '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 actions.USER_BAN_SUCCESS: return setBanUser(state, false, action);
|
||||
default: return state;
|
||||
}
|
||||
};
|
||||
|
||||
@@ -11,22 +11,20 @@ import coralApi from '../../../coral-framework/helpers/response';
|
||||
// Intercept redux actions and act over the ones we are interested
|
||||
export default store => next => action => {
|
||||
|
||||
next(action);
|
||||
|
||||
switch (action.type) {
|
||||
case 'COMMENTS_MODERATION_QUEUE_FETCH':
|
||||
fetchModerationQueueComments(store);
|
||||
break;
|
||||
return fetchModerationQueueComments(store);
|
||||
case 'COMMENT_UPDATE':
|
||||
updateComment(store, action.comment);
|
||||
break;
|
||||
return updateComment(store, action.comment);
|
||||
case 'COMMENT_CREATE':
|
||||
createComment(store, action.name, action.body);
|
||||
break;
|
||||
return createComment(store, action.name, action.body);
|
||||
case 'USER_BAN':
|
||||
userStatusUpdate(store, action.status, action.userId, action.commentId);
|
||||
break;
|
||||
return userStatusUpdate(store, action.status, action.userId, action.commentId);
|
||||
case 'ASSETS_FETCH':
|
||||
return fetchAssets(store, action);
|
||||
}
|
||||
|
||||
next(action);
|
||||
};
|
||||
|
||||
// Get comments to fill each of the three lists on the mod queue
|
||||
@@ -88,6 +86,20 @@ const createComment = (store, name, comment) => {
|
||||
// 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}))
|
||||
.then(res => store.dispatch({type: 'USER_BAN_SUCCESS', res}))
|
||||
.catch(error => store.dispatch({type: 'USER_BAN_FAILED', error}));
|
||||
};
|
||||
|
||||
// Fetch a page of assets
|
||||
// Get comments to fill each of the three lists on the mod queue
|
||||
const fetchAssets = (store, action) => {
|
||||
const {skip, limit, search} = action;
|
||||
return coralApi(`/assets?skip=${skip}&limit=${limit}&search=${search}`)
|
||||
.then(({result, count}) =>
|
||||
/* Post comments and users to redux store. Actions will be posted when they are needed. */
|
||||
store.dispatch({type: 'ASSETS_FETCH_SUCCESS',
|
||||
assets: result,
|
||||
count
|
||||
}))
|
||||
.catch(error => store.dispatch({type: 'ASSETS_FETCH_FAILED', error}));
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user