-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Expand file tree
/
Copy pathCommentActions.js
More file actions
76 lines (65 loc) · 1.58 KB
/
CommentActions.js
File metadata and controls
76 lines (65 loc) · 1.58 KB
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
import callApi from '../../util/apiCaller';
// Export Constants
export const ADD_COMMENT = 'ADD_COMMENT';
export const ADD_COMMENTS = 'ADD_COMMENTS';
export const DELETE_COMMENT = 'DELETE_COMMENT';
export const EDIT_COMMENT = 'EDIT_COMMENT';
export const UPDATE_COMMENT = 'UPDATE_COMMENT';
// Export Actions
export function addComment(comment) {
return {
type: ADD_COMMENT,
comment,
};
}
export function addCommentRequest(comment, postId) {
return dispatch => {
return callApi(`posts/${postId}/comment`, 'post', {
comment: {
author: comment.author,
content: comment.content,
},
}).then(res => dispatch(addComment(res.comment)));
};
}
export function addComments(comments) {
return {
type: ADD_COMMENTS,
comments,
};
}
export function fetchComments(postId) {
return (dispatch) => {
return callApi(`posts/${postId}/comments`).then(res => {
dispatch(addComments(res.comments));
});
};
}
export function deleteComment(cuid) {
return {
type: DELETE_COMMENT,
cuid,
};
}
export function editComment(cuid) {
return {
type: EDIT_COMMENT,
cuid,
};
}
export function updateComment(comment) {
return {
type: UPDATE_COMMENT,
comment,
};
}
export function deleteCommentRequest(cuid) {
return (dispatch) => {
return callApi(`comment/${cuid}`, 'delete').then(() => dispatch(deleteComment(cuid)));
};
}
export function updateCommentRequest(comment) {
return (dispatch) => {
return callApi(`comment/${comment.cuid}`, 'put', { comment }).then(() => dispatch(updateComment(comment)));
};
}