2019-09-17 11:33:18 +02:00
|
|
|
import { connect } from 'react-redux';
|
|
|
|
|
|
2022-05-07 11:27:07 +02:00
|
|
|
import { requestComments } from '../actions/Comment/requestComments';
|
2019-09-17 19:09:38 +02:00
|
|
|
import {
|
|
|
|
|
toggleCommentReply,
|
|
|
|
|
setCommentReplyBody,
|
2022-05-28 11:03:36 +02:00
|
|
|
toggleCommentIsPostUpdateFlag,
|
2022-05-07 11:27:07 +02:00
|
|
|
} from '../actions/Comment/handleCommentReplies';
|
|
|
|
|
import { submitComment } from '../actions/Comment/submitComment';
|
2022-06-22 10:17:42 +02:00
|
|
|
import { updateComment } from '../actions/Comment/updateComment';
|
|
|
|
|
import { deleteComment } from '../actions/Comment/deleteComment';
|
2019-09-17 11:33:18 +02:00
|
|
|
|
|
|
|
|
import { State } from '../reducers/rootReducer';
|
|
|
|
|
|
|
|
|
|
import CommentsP from '../components/Comments/CommentsP';
|
2022-06-22 10:17:42 +02:00
|
|
|
import HttpStatus from '../constants/http_status';
|
2019-09-17 11:33:18 +02:00
|
|
|
|
|
|
|
|
const mapStateToProps = (state: State) => ({
|
|
|
|
|
comments: state.currentPost.comments.items,
|
2019-09-26 18:22:18 +02:00
|
|
|
replyForms: state.currentPost.comments.replyForms,
|
2019-09-17 11:33:18 +02:00
|
|
|
areLoading: state.currentPost.comments.areLoading,
|
|
|
|
|
error: state.currentPost.comments.error,
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
const mapDispatchToProps = (dispatch) => ({
|
2019-09-17 15:03:25 +02:00
|
|
|
requestComments(postId: number) {
|
|
|
|
|
dispatch(requestComments(postId));
|
2019-09-17 11:33:18 +02:00
|
|
|
},
|
2019-09-17 19:09:38 +02:00
|
|
|
|
|
|
|
|
toggleCommentReply(commentId: number) {
|
|
|
|
|
dispatch(toggleCommentReply(commentId));
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
setCommentReplyBody(commentId: number, body: string) {
|
|
|
|
|
dispatch(setCommentReplyBody(commentId, body));
|
|
|
|
|
},
|
2019-09-18 13:40:00 +02:00
|
|
|
|
2022-05-28 11:03:36 +02:00
|
|
|
toggleCommentIsPostUpdateFlag() {
|
|
|
|
|
dispatch(toggleCommentIsPostUpdateFlag(null));
|
|
|
|
|
},
|
|
|
|
|
|
2022-06-22 10:17:42 +02:00
|
|
|
submitComment(
|
2019-10-02 16:43:13 +02:00
|
|
|
postId: number,
|
2022-06-22 10:17:42 +02:00
|
|
|
body: string,
|
|
|
|
|
parentId: number,
|
|
|
|
|
isPostUpdate: boolean,
|
2019-10-02 16:43:13 +02:00
|
|
|
authenticityToken: string,
|
|
|
|
|
) {
|
2022-06-22 10:17:42 +02:00
|
|
|
dispatch(submitComment(postId, body, parentId, isPostUpdate, authenticityToken));
|
2019-10-02 16:43:13 +02:00
|
|
|
},
|
|
|
|
|
|
2022-06-22 10:17:42 +02:00
|
|
|
updateComment(
|
2019-09-18 13:40:00 +02:00
|
|
|
postId: number,
|
2022-06-22 10:17:42 +02:00
|
|
|
commentId: number,
|
2019-09-18 13:40:00 +02:00
|
|
|
body: string,
|
2022-05-28 11:03:36 +02:00
|
|
|
isPostUpdate: boolean,
|
2022-06-22 10:17:42 +02:00
|
|
|
onSuccess: Function,
|
2019-09-18 13:40:00 +02:00
|
|
|
authenticityToken: string,
|
|
|
|
|
) {
|
2022-06-22 10:17:42 +02:00
|
|
|
dispatch(updateComment(postId, commentId, body, isPostUpdate, authenticityToken)).then(res => {
|
|
|
|
|
if (res && res.status === HttpStatus.OK) onSuccess();
|
|
|
|
|
});
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
deleteComment(
|
|
|
|
|
postId: number,
|
|
|
|
|
commentId: number,
|
|
|
|
|
authenticityToken: string,
|
|
|
|
|
) {
|
|
|
|
|
dispatch(deleteComment(postId, commentId, authenticityToken));
|
2019-09-18 13:40:00 +02:00
|
|
|
},
|
2019-09-17 11:33:18 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
export default connect(
|
|
|
|
|
mapStateToProps,
|
|
|
|
|
mapDispatchToProps,
|
|
|
|
|
)(CommentsP);
|