Files
astuto/app/javascript/containers/Comments.tsx

77 lines
2.1 KiB
TypeScript
Raw Normal View History

import { connect } from 'react-redux';
2022-05-07 11:27:07 +02:00
import { requestComments } from '../actions/Comment/requestComments';
import {
toggleCommentReply,
setCommentReplyBody,
toggleCommentIsPostUpdateFlag,
2022-05-07 11:27:07 +02:00
} from '../actions/Comment/handleCommentReplies';
import { submitComment } from '../actions/Comment/submitComment';
import { updateComment } from '../actions/Comment/updateComment';
import { deleteComment } from '../actions/Comment/deleteComment';
import { State } from '../reducers/rootReducer';
import CommentsP from '../components/Comments/CommentsP';
import HttpStatus from '../constants/http_status';
const mapStateToProps = (state: State) => ({
comments: state.currentPost.comments.items,
replyForms: state.currentPost.comments.replyForms,
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));
},
toggleCommentReply(commentId: number) {
dispatch(toggleCommentReply(commentId));
},
setCommentReplyBody(commentId: number, body: string) {
dispatch(setCommentReplyBody(commentId, body));
},
2019-09-18 13:40:00 +02:00
toggleCommentIsPostUpdateFlag() {
dispatch(toggleCommentIsPostUpdateFlag(null));
},
submitComment(
postId: number,
body: string,
parentId: number,
isPostUpdate: boolean,
authenticityToken: string,
) {
dispatch(submitComment(postId, body, parentId, isPostUpdate, authenticityToken));
},
updateComment(
2019-09-18 13:40:00 +02:00
postId: number,
commentId: number,
2019-09-18 13:40:00 +02:00
body: string,
isPostUpdate: boolean,
onSuccess: Function,
2019-09-18 13:40:00 +02:00
authenticityToken: string,
) {
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
},
});
export default connect(
mapStateToProps,
mapDispatchToProps,
)(CommentsP);