Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- export function pushVotePost(option, postId) {
- const request = API.postVotePost(option, postId)
- return dispatch => {
- request.then(({ data }) => {
- dispatch({ type: POST_VOTE_POST, payload: data, meta: postId })
- })
- }
- }
- import {
- POSTS_GET_POSTS,
- POST_VOTE_POST,
- POSTS_GET_POST,
- } from '../actions/actionConstants'
- const posts = (state = [], action) => {
- const { payload } = action
- switch (action.type) {
- case POST_VOTE_POST:
- return [...state.filter(item => item.id !== payload.id), payload]
- case POSTS_GET_POST:
- return payload
- case POSTS_GET_POSTS:
- return payload
- default:
- return state
- }
- }
- export default posts
- componentDidMount() {
- const { getPosts } = this.props
- getPosts()
- }
- return _.map(posts, post => {
- return (
- <div className="post-container" key={post.id}>
- <PostComponent
- key={post.id}
- postId={post.id}
- title={post.title}
- body={false}
- readirect
- author={post.author}
- voteScore={post.voteScore}
- category={post.category}
- timestamp={post.timestamp}
- />
- </div>
- )
- })
- export default connect(
- state => ({
- posts: _.filter(state.posts, ['deleted', false]),
- }),
- {
- getPosts,
- }
- )(Posts)
- componentDidMount() {
- const { getPost, getComments, match } = this.props
- this.props.getPost(match.params.postId)
- this.props.getComments(match.params.postId)
- }
- const mapStateToProps = (state, ownProps) => {
- const { posts } = state
- return {
- comments: state.comments[ownProps.match.params.postId],
- posts,
- }
- }
- const { posts } = this.props
- return (
- <PostComponent
- key={posts.id}
- postId={this.props.match.params.postId}
- title={posts.title}
- body={posts.body}
- readirect={false}
- author={posts.author}
- voteScore={posts.voteScore}
- category={posts.category}
- timestamp={posts.timestamp}
- />
- )
- export default connect(mapStateToProps, { getPost, getComments })(PostDetails)
Add Comment
Please, Sign In to add comment