File size: 1,087 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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import React from 'react';
import NewsFeedIndexItem from './news_feed_index_item';
import CreatePostFormContainer from './create_post_form_container';

class NewsFeedIndex extends React.Component {
  constructor(props){
    super(props);
  }


  componentDidMount(){
    this.props.fetchNewsFeed();
  }

  render() {
    const posts = this.props.posts.reverse().map(post => {
      if(post.wall_id === this.props.currentUser.id ||
         this.props.currentUser.friends.includes(post.author_id)){
      return (
        <NewsFeedIndexItem
          key={post.id}
          post= {post}
          user={this.props.user}
          deletePost={this.props.deletePost}
          fetchNewsFeed={this.props.fetchNewsFeed}
          currentUser={this.props.currentUser}
          users={this.props.users}/>
      );
    }else{
      return null;
    }
    });

    return (
      <div>
        <CreatePostFormContainer user={this.props.user}
          currentUser={this.props.currentUser}/>
        <ul>
          {posts}
        </ul>

      </div>
    );
  }
}

export default NewsFeedIndex;