File size: 1,679 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 |
import React from 'react';
import { Link } from 'react-router-dom';
import CommentsContainer from '../comments/comments_container';
class NewsFeedIndexItem extends React.Component{
constructor(props){
super(props);
this.handleSubmit = this.handleSubmit.bind(this);
}
handleSubmit(e){
this.props.deletePost(this.props.post.id)
.then(()=>this.props.fetchNewsFeed());
}
renderImage(){
if(this.props.post.photo.match( '/assets/missing-post')){
return null ;
}else{
return (<section><img className="post-photo"
src={this.props.post.photo} /></section>);
}
}
renderDelete(){
if(this.props.currentUser.id === this.props.post.author_id){
return(<div
onClick={()=>this.handleSubmit()}>
<span className="delete-hover"> ...
<i className="fas fa-trash-alt space-del"></i>
</span></div>);
}else{
return null;
}
}
render(){
const { post, deletePost,user,fetchNewsFeed} = this.props;
return (
<li className="index-post">
<div className="title-top">
<div className="post-name">
<Link to={`/users/${post.author_id}`}>
<section><img className="profile_img nimg nnsp"
src={post.profile_image_url} /></section>
</Link>
<Link to={`/users/${post.author_id}`}>
<h2 className="post-author">{post.authorfname}</h2>
</Link>
</div>
{this.renderDelete()}
</div>
<div>
<h2 className="pos-text">{post.body}</h2>
{this.renderImage()}
</div>
<CommentsContainer post={post} comments={post.comments}/>
</li>);
}
}
export default NewsFeedIndexItem;
|