Skip to content

Commit 32c0b0d

Browse files
committed
utilizing es6 syntax
1 parent 17961a3 commit 32c0b0d

File tree

5 files changed

+17
-63
lines changed

5 files changed

+17
-63
lines changed

src/components/Categories.js

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import Category from "./Category";
66

77
class Categories extends Component {
88
componentDidMount() {
9-
this.props.dispatchGetCategories();
9+
this.props.getCategories();
1010
}
1111

1212
render() {
@@ -37,19 +37,13 @@ class Categories extends Component {
3737
);
3838
}
3939
}
40-
const mapDispatchToProps = dispatch => {
41-
return {
42-
dispatchGetCategories: () => {
43-
dispatch(getCategories());
44-
}
45-
};
46-
};
40+
4741
function mapStateToProps({ categories }) {
4842
return {
4943
categories
5044
};
5145
}
5246
export default connect(
5347
mapStateToProps,
54-
mapDispatchToProps
48+
{ getCategories }
5549
)(Categories);

src/components/Comment.js

Lines changed: 3 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import { connect } from "react-redux";
33
import Modal from "react-modal";
44
import * as FontAwesome from "react-icons/lib/fa";
55
import { castVote, deleteComment } from "./../actions/comments";
6-
import { getPostById } from "./../actions/post";
76
import CreateComment from "./CreateComment";
87
import Vote from "./Vote";
98

@@ -20,10 +19,10 @@ class Comment extends Component {
2019

2120
deleteComment = () => {
2221
let id = this.props.comment.id;
23-
this.props.dispatchDeleteComment(id);
22+
this.props.deleteComment(id);
2423
};
2524
castVote = payload => {
26-
this.props.dispatchCastVote(payload);
25+
this.props.castVote(payload);
2726
};
2827

2928
render() {
@@ -62,22 +61,7 @@ class Comment extends Component {
6261
);
6362
}
6463
}
65-
66-
const mapDispatchToProps = dispatch => {
67-
return {
68-
dispatchDeleteComment: id => {
69-
dispatch(deleteComment(id));
70-
},
71-
dispatchCastVote: payload => {
72-
dispatch(castVote(payload));
73-
},
74-
dispatchGetPost: comment => {
75-
dispatch(getPostById(comment));
76-
}
77-
};
78-
};
79-
8064
export default connect(
8165
null,
82-
mapDispatchToProps
66+
{ castVote, deleteComment }
8367
)(Comment);

src/components/CreateComment.js

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,12 @@ class CreateComment extends Component {
3333
deleted: false,
3434
parentDeleted: false
3535
};
36-
this.props.dispatchCreateComment(comment);
36+
this.props.createComment(comment);
3737
} else {
3838
let comment = { ...values, id: this.props.commentId };
39-
this.props.dispatchEditComment(comment);
39+
this.props.editComment(comment);
4040
}
41-
this.props.dispatchGetPost(this.props.parentId);
41+
this.props.getPostById(this.props.parentId);
4242
this.props.close();
4343
};
4444
handleChange = event => {
@@ -88,21 +88,7 @@ class CreateComment extends Component {
8888
}
8989
}
9090

91-
const mapDispatchToProps = dispatch => {
92-
return {
93-
dispatchCreateComment: comment => {
94-
dispatch(createComment(comment));
95-
},
96-
dispatchEditComment: comment => {
97-
dispatch(editComment(comment));
98-
},
99-
dispatchGetPost: id => {
100-
dispatch(getPostById(id));
101-
}
102-
};
103-
};
104-
10591
export default connect(
10692
null,
107-
mapDispatchToProps
93+
{ createComment, editComment, getPostById }
10894
)(CreateComment);

src/components/CreatePost.js

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,14 @@ class CreatePost extends Component {
3030

3131
if (this.state.id) {
3232
let post = { ...values, id: this.state.id };
33-
this.props.dispatchEditPost(post);
33+
this.props.editPost(post);
3434
} else {
3535
let post = {
3636
...values,
3737
id: uuid(),
3838
timestamp: Date.now()
3939
};
40-
this.props.dispatchCreatePost(post);
40+
this.props.createPost(post);
4141
}
4242
this.props.history.goBack();
4343
};
@@ -121,16 +121,6 @@ class CreatePost extends Component {
121121
}
122122
}
123123

124-
const mapDispatchToProps = dispatch => {
125-
return {
126-
dispatchCreatePost: post => {
127-
dispatch(createPost(post));
128-
},
129-
dispatchEditPost: post => {
130-
dispatch(editPost(post));
131-
}
132-
};
133-
};
134124
function mapStateToProps({ posts, categories }) {
135125
return {
136126
posts,
@@ -139,5 +129,5 @@ function mapStateToProps({ posts, categories }) {
139129
}
140130
export default connect(
141131
mapStateToProps,
142-
mapDispatchToProps
132+
{ createPost, editPost }
143133
)(CreatePost);

src/components/PostDetail.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import React, { Component } from "react";
22
import { connect } from "react-redux";
3-
import * as postActions from "./../actions/post";
4-
import * as postsActions from "./../actions/posts";
5-
import * as commentsActions from "./../actions/comments";
3+
import { getPostById } from "./../actions/post";
4+
import { castVote, deletePost } from "./../actions/posts";
5+
import { getCommentsByPostId } from "./../actions/comments";
66
import Comments from "./Comments";
77
import PostManager from "./PostManager";
88
import PostBody from "./PostBody";
@@ -65,5 +65,5 @@ function mapStateToProps({ posts, post, loading, comments }) {
6565

6666
export default connect(
6767
mapStateToProps,
68-
{ postActions, postsActions, commentsActions }
68+
{ getPostById, castVote, deletePost, getCommentsByPostId }
6969
)(PostDetail);

0 commit comments

Comments
 (0)