-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Expand file tree
/
Copy pathCommentActions.js
More file actions
42 lines (38 loc) · 1019 Bytes
/
CommentActions.js
File metadata and controls
42 lines (38 loc) · 1019 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import callApi from '../../util/apiCaller';
export const GET_COMMENTS_BY_POST = 'GET_COMMENTS_BY_POST';
export const ADD_COMMENT = 'ADD_COMMENT';
export const DELETE_COMMENT = 'DELETE_COMMENT';
export const GET_ERRORS = 'GET_ERRORS';
export function deleteComment(cuid) {
return (dispatch) => {
callApi('comments', 'delete', { cuid });
return dispatch({
type: DELETE_COMMENT,
payload: cuid,
});
};
}
export function addComment(post, name, text) {
return (dispatch) => {
return callApi('comments', 'post', { post, name, text }).then(res => dispatch({
type: ADD_COMMENT,
payload: res,
}))
.catch(() => dispatch({
type: GET_ERRORS,
payload: null,
}));
};
}
export function getCommentsByPost(post) {
return (dispatch) => {
return callApi(`comment/${post}`).then(res => dispatch({
type: GET_COMMENTS_BY_POST,
comments: res,
}))
.catch(() => dispatch({
type: GET_COMMENTS_BY_POST,
comments: [],
}));
};
}