11import React , { Component } from "react" ;
22import { connect } from "react-redux" ;
3- import { getPostById } from "./../actions/post" ;
4- import { castVote , deletePost } from "./../actions/posts" ;
5- import { getCommentsByPostId } from "./../actions/comments" ;
3+ import * as postActions from "./../actions/post" ;
4+ import * as postsActions from "./../actions/posts" ;
5+ import * as commentsActions from "./../actions/comments" ;
66import Comments from "./Comments" ;
77import PostManager from "./PostManager" ;
88import PostBody from "./PostBody" ;
@@ -11,19 +11,19 @@ import GenericNotFound from "./GenericNotFound";
1111class PostDetail extends Component {
1212 componentDidMount ( ) {
1313 let id = this . props . match . params . id ;
14- this . props . dispatchGetPostById ( id ) ;
15- this . props . dispatchGetCommentsByPostId ( id ) ;
14+ this . props . getPostById ( id ) ;
15+ this . props . getCommentsByPostId ( id ) ;
1616 }
1717
1818 deletePost = ( ) => {
1919 let id = this . props . match . params . id ;
20- this . props . dispatchDeletePost ( id ) ;
20+ this . props . deletePost ( id ) ;
2121 this . props . history . push ( "/" ) ;
2222 } ;
2323 votePost = payload => {
2424 let id = this . props . match . params . id ;
25- this . props . dispatchCastVote ( payload ) ;
26- this . props . dispatchGetPostById ( id ) ;
25+ this . props . castVote ( payload ) ;
26+ this . props . getPostById ( id ) ;
2727 } ;
2828
2929 render ( ) {
@@ -63,17 +63,7 @@ function mapStateToProps({ posts, post, loading, comments }) {
6363 } ;
6464}
6565
66- const mapDispatchToProps = dispatch => {
67- return {
68- dispatchGetPostById : id => {
69- dispatch ( getPostById ( id ) ) ;
70- } ,
71- dispatchGetCommentsByPostId : id => dispatch ( getCommentsByPostId ( id ) ) ,
72- dispatchDeletePost : id => dispatch ( deletePost ( id ) ) ,
73- dispatchCastVote : payload => dispatch ( castVote ( payload ) )
74- } ;
75- } ;
7666export default connect (
7767 mapStateToProps ,
78- mapDispatchToProps
68+ { postActions , postsActions , commentsActions }
7969) ( PostDetail ) ;
0 commit comments