Last active
June 4, 2018 15:54
-
-
Save jamesattard/a497350cef489b5b725dd388efadf40b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
... | |
class PostList extends Component { | |
async componentDidMount() { | |
const { fetchPostsAndData } = this.props; | |
await fetchPostsAndData(); | |
} | |
renderPosts = () => { | |
const postList = this.props.postList; | |
const posts = postList.map(post => ( | |
<Typography variant="display1">{post.name}</Typography> | |
<div>{this.renderPostComments(post)}</div> | |
)); | |
return posts; | |
}; | |
renderPostComments = post => { | |
if (this.props.commentsPerPost[post._id]) { | |
const postsArr = this.props.commentsPerPost[post._id]; | |
return <div>{this.renderPostComment(postsArr)}</div>; | |
} else { | |
return <span>Loading...</span>; | |
} | |
}; | |
renderPostComment = postsArr => { | |
if (postsArr.commentsCount === 0) { | |
return <Typography>No comments.</Typography>; | |
} else { | |
const comments = postsArr.comments.map(comment => ( | |
<div> | |
<Typography>{comment._userId.name}</Typography> | |
<br /> | |
<Typography>{comment.commentDate}</Typography> | |
</div> | |
)); | |
return comments; | |
} | |
}; | |
render() { | |
return this.props.isPostsFetching || this.props.isPostCommentFetching ? ( | |
<Typography>Loading...</Typography> | |
) : ( | |
<Container> | |
{this.renderPosts()} | |
</Container> | |
); | |
} | |
} | |
... |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment