Compressing variables from postAction into single object.

This commit is contained in:
David Jay
2016-12-08 14:27:31 -05:00
parent f8923aa283
commit fc96c1ee91
5 changed files with 18 additions and 12 deletions
@@ -268,13 +268,13 @@ const mapStateToProps = state => ({
});
const mapDispatchToProps = (dispatch) => ({
addItem: (item, itemType) => dispatch(addItem(item, itemType)),
addItem: (args) => dispatch(addItem.apply(args)),
updateItem: (id, property, value, itemType) => dispatch(updateItem(id, property, value, itemType)),
postItem: (data, type, id) => dispatch(postItem(data, type, id)),
getStream: (rootId) => dispatch(getStream(rootId)),
addNotification: (type, text) => dispatch(addNotification(type, text)),
clearNotification: () => dispatch(clearNotification()),
postAction: (item, action, itemType, field, detail) => dispatch(postAction(item, action, itemType, field, detail)),
postAction: (item, itemType, action) => dispatch(postAction(item, itemType, action)),
showSignInDialog: () => dispatch(showSignInDialog()),
deleteAction: (item, action, user, itemType) => dispatch(deleteAction(item, action, user, itemType)),
appendItemArray: (item, property, value, addToFront, itemType) => dispatch(appendItemArray(item, property, value, addToFront, itemType)),
+1 -7
View File
@@ -217,14 +217,8 @@ export function postItem (item, type, id) {
*
*/
export function postAction (item_id, action_type, item_type, field, detail) {
export function postAction (item_id, item_type, action) {
return () => {
const action = {
action_type,
field,
detail
};
return coralApi(`/${item_type}/${item_id}/actions`, {method: 'POST', body: action});
};
}
+6 -1
View File
@@ -34,7 +34,12 @@ export default class FlagButton extends Component {
console.log('OtherText', otherText);
const updatedDetail = otherText || detail;
const item_id = itemType === 'comments' ? id : author_id;
postAction(item_id, 'flag', itemType, field, updatedDetail)
const action = {
action_type: 'flag',
field,
detail: updatedDetail
};
postAction(item_id, itemType, action)
.then((action) => {
let id = `${action.action_type}_${action.item_id}`;
addItem({id, current_user: action, count: flag ? flag.count + 1 : 1}, 'actions');
+4 -1
View File
@@ -12,7 +12,10 @@ const LikeButton = ({like, id, postAction, deleteAction, addItem, showSignInDial
return;
}
if (!liked) {
postAction(id, 'like', currentUser.id, 'comments')
const action = {
action_type: 'like'
};
postAction(id, 'comments', action)
.then((action) => {
let id = `${action.action_type}_${action.item_id}`;
addItem({id, current_user: action, count: like ? like.count + 1 : 1}, 'actions');
@@ -155,7 +155,11 @@ describe('itemActions', () => {
describe('postAction', () => {
it ('should post an action', () => {
fetchMock.post('*', {id: '456'});
return actions.postAction('abc', 'flag', 'comments', 'Comment smells funny')(store.dispatch)
const action = {
action_type: 'flag',
detail: 'Comment smells funny'
};
return actions.postAction('abc', 'comments', action)(store.dispatch)
.then(response => {
expect(fetchMock.calls().matched[0][0]).to.equal('/api/v1/comments/abc/actions');
expect(response).to.deep.equal({id:'456'});