2019-09-17 11:33:18 +02:00
|
|
|
import { connect } from 'react-redux';
|
|
|
|
|
|
|
|
|
|
import { requestComments } from '../actions/requestComments';
|
2019-09-17 19:09:38 +02:00
|
|
|
import {
|
|
|
|
|
toggleCommentReply,
|
|
|
|
|
setCommentReplyBody,
|
|
|
|
|
} from '../actions/handleCommentReplies';
|
2019-10-02 16:43:13 +02:00
|
|
|
import { toggleCommentIsUpdate } from '../actions/updateComment';
|
2019-09-18 13:40:00 +02:00
|
|
|
import { submitComment } from '../actions/submitComment';
|
2019-09-17 11:33:18 +02:00
|
|
|
|
|
|
|
|
import { State } from '../reducers/rootReducer';
|
|
|
|
|
|
|
|
|
|
import CommentsP from '../components/Comments/CommentsP';
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
2019-10-02 16:43:13 +02:00
|
|
|
toggleCommentIsPostUpdate(
|
|
|
|
|
postId: number,
|
|
|
|
|
commentId: number,
|
|
|
|
|
currentIsPostUpdate: boolean,
|
|
|
|
|
authenticityToken: string,
|
|
|
|
|
) {
|
|
|
|
|
dispatch(toggleCommentIsUpdate(postId, commentId, currentIsPostUpdate, authenticityToken));
|
|
|
|
|
},
|
|
|
|
|
|
2019-09-18 13:40:00 +02:00
|
|
|
submitComment(
|
|
|
|
|
postId: number,
|
|
|
|
|
body: string,
|
|
|
|
|
parentId: number,
|
|
|
|
|
authenticityToken: string,
|
|
|
|
|
) {
|
|
|
|
|
dispatch(submitComment(postId, body, parentId, authenticityToken));
|
|
|
|
|
},
|
2019-09-17 11:33:18 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
export default connect(
|
|
|
|
|
mapStateToProps,
|
|
|
|
|
mapDispatchToProps,
|
|
|
|
|
)(CommentsP);
|