File size: 1,341 Bytes
f5071ca |
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 |
import * as CommentApiUtil from "../util/comment_api_util";
import {fetchPost} from '../actions/post_actions';
export const RECEIVE_COMMENTS = "RECEIVE_COMMENTS";
export const RECEIVE_COMMENT = "RECEIVE_COMMENT";
export const REMOVE_COMMENT = "REMOVE_COMMENT";
const receiveComments = comments => ({
type: RECEIVE_COMMENTS,
comments,
});
const receiveComment = comment => ({
type: RECEIVE_COMMENT,
comment,
});
const removeComment = commentId => ({
type: REMOVE_COMMENT,
commentId,
});
export const fetchComments = postId => dispatch => {
CommentApiUtil.fetchAllComments(postId).
then( comments => dispatch(receiveComments(comments)));
};
export const fetchComment = (postId, commentId) => dispatch => {
CommentApiUtil.fetchComment(postId, commentId).
then( comment => dispatch(receiveComment(comment)));
};
export const postComment = (postId, comment) => dispatch => {
CommentApiUtil.postComment(postId, comment).
then( post => dispatch(fetchPost(post.id)));
};
export const updateComment = (postId, comment) => dispatch => {
CommentApiUtil.patchComment(postId, comment).
then( newComment => dispatch(receiveComment(newComment)));
};
export const destroyComment = (postId, commentId) => dispatch => {
CommentApiUtil.deleteComment(postId, commentId).
then( post => dispatch(fetchPost(post.id)));
};
|