File size: 760 Bytes
f5071ca
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import { connect } from 'react-redux';
import { withRouter} from 'react-router-dom';
import PostIndex from './post_index';
import { requestWallPosts } from '../../actions/post_actions';

const mapStateToProps = (state, ownProps) => {
  const posts = [];
  const userId = state.entities.userUrls[ownProps.match.params.userUrl];

  for (let postId in state.entities.posts) {
    const post = state.entities.posts[postId];

    if (post.recipientId === userId) {
      posts.push(post);
    }
  }

  return {
    posts,
    userId,
    users: state.entities.users
  }
};

const mapDispatchToProps = dispatch => ({
  requestPosts: userId => dispatch(requestWallPosts(userId))
});

export default withRouter(connect(mapStateToProps, mapDispatchToProps)(PostIndex));