File size: 659 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
import { connect } from 'react-redux';
import PostIndex from './post_index';
import { fetchUser } from '../../actions/session_actions';
import { fetchAllPosts, deletePost } from '../../actions/post_actions';

const mapStateToProps = (state,ownProps) => {
  let currentUserId = state.session.id;
  return {
  posts: Object.values(state.entities.posts),
  currentUser:state.entities.users[currentUserId],
  users:state.entities.users
  };
};

const mapDispatchToProps = dispatch => ({
  fetchAllPosts: ()=>dispatch(fetchAllPosts()),
  deletePost: id => dispatch(deletePost(id))
});

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