File size: 865 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 |
import React from 'react';
import PostIndexItem from './post_index_item';
class PostIndex extends React.Component {
componentDidMount() {
this.props.requestPosts(this.props.userId)
}
componentDidUpdate(prevProps) {
if (prevProps.match.params.userUrl !== this.props.match.params.userUrl) {
this.props.requestPosts(this.props.userId);
}
}
render() {
let posts = this.props.posts.map(post => {
const author = this.props.users[post.authorId];
const recipient = this.props.users[post.recipientId];
return (
<PostIndexItem
post={post}
author={author}
recipient={recipient}
key={post.id}
/>
);
});
return (
<div className="post-list">
<ul>
{posts.reverse()}
</ul>
</div>
)
}
}
export default PostIndex; |