File size: 2,082 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 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
import React from 'react';
import { Link } from 'react-router-dom';
import PostEditButton from './post_edit_button';
import CommentIndexContainer from '../comments/comment_index_container';
import CreateCommentFormContainer from '../comments/create_comment_form_container';
class PostIndexItem extends React.Component {
postRecipient(author, recipient) {
if (author !== recipient) {
return <span>
<i className="fas fa-caret-right"></i>
<Link to={`/${recipient.userUrl}`} replace>
{recipient.fname} {recipient.lname}
</Link>
</span>;
}
}
renderImages() {
// if (this.props.post.imageUrls) {
// return this.props.post.imageUrls.map(
// (url, idx) => <img
// className="post-image"
// key={idx}
// src={url}
// />
// );
// } else {
// return null;
// }
if (this.props.post.imageUrl) {
return <img className="post-image" src={this.props.post.imageUrl} />
} else {
return null;
}
}
render() {
const { author, recipient, post } = this.props;
return (
<div className="post-container">
<div className="post-header">
<Link
to={`/${author.userUrl}`} replace
className="post-thumbnail"
style={{ backgroundImage: `url(${author.profilePictureUrl})` }}
/>
<div>
<div>
<Link to={`/${author.userUrl}`} replace>
{author.fname} {author.lname}
</Link>
{this.postRecipient(author, recipient)}
</div>
<PostEditButton post={post} />
</div>
<div className="date">{post.createdAt}</div>
</div>
<div className="post-content">
{post.body}
{this.renderImages()}
</div>
<div className="post-comments">
<CommentIndexContainer postId={post.id} />
<CreateCommentFormContainer postId={post.id} />
</div>
</div>
);
}
}
export default PostIndexItem; |