2016-03-17 18:08:03 +09:00
|
|
|
import React, { PropTypes, Component } from 'react';
|
2016-03-24 10:56:47 +09:00
|
|
|
import { Button } from 'react-bootstrap';
|
2016-03-17 18:08:03 +09:00
|
|
|
|
2016-03-27 13:04:21 +09:00
|
|
|
import ReactForms from "meteor/utilities:react-form-containers";
|
|
|
|
const EditDocument = ReactForms.EditDocument;
|
|
|
|
|
2016-03-17 18:08:03 +09:00
|
|
|
class PostItem extends Component {
|
2016-02-18 21:53:44 +09:00
|
|
|
|
|
|
|
renderCategories() {
|
|
|
|
|
|
|
|
({PostCategories} = Telescope.components);
|
|
|
|
|
2016-03-24 16:03:30 +09:00
|
|
|
return this.props.post.categoriesArray ? <PostCategories post={this.props.post} /> : "";
|
2016-03-17 18:08:03 +09:00
|
|
|
}
|
2016-02-18 21:53:44 +09:00
|
|
|
|
|
|
|
renderCommenters() {
|
|
|
|
|
2016-02-19 10:12:08 +09:00
|
|
|
({PostCommenters} = Telescope.components);
|
2016-02-18 21:53:44 +09:00
|
|
|
|
2016-03-24 16:03:30 +09:00
|
|
|
return this.props.post.commentersArray ? <PostCommenters post={this.props.post}/> : "";
|
2016-03-17 18:08:03 +09:00
|
|
|
}
|
2016-02-18 21:53:44 +09:00
|
|
|
|
|
|
|
renderActions() {
|
2016-02-25 21:05:53 +09:00
|
|
|
|
2016-03-27 13:04:21 +09:00
|
|
|
({ModalTrigger, DocumentContainer} = Telescope.components);
|
2016-02-25 21:32:13 +09:00
|
|
|
|
|
|
|
const component = (
|
2016-03-24 16:03:30 +09:00
|
|
|
<ModalTrigger component={<a href="#" className="edit-link">Edit</a>}>
|
2016-03-27 18:17:20 +09:00
|
|
|
<div className="edit-post-form">
|
|
|
|
<h3 className="modal-form-title">Edit Post</h3>
|
|
|
|
<EditDocument
|
|
|
|
collection={Posts}
|
|
|
|
document={this.props.post}
|
|
|
|
currentUser={this.context.currentUser}
|
|
|
|
methodName="posts.edit"
|
|
|
|
/>
|
|
|
|
</div>
|
2016-03-24 10:56:47 +09:00
|
|
|
</ModalTrigger>
|
2016-02-25 21:32:13 +09:00
|
|
|
);
|
2016-02-25 21:05:53 +09:00
|
|
|
|
2016-02-18 21:53:44 +09:00
|
|
|
return (
|
2016-02-19 10:12:08 +09:00
|
|
|
<div className="post-actions">
|
2016-02-25 21:32:13 +09:00
|
|
|
{Users.can.edit(this.props.currentUser, this.props.post) ? component : ""}
|
2016-02-19 10:12:08 +09:00
|
|
|
</div>
|
2016-02-18 21:53:44 +09:00
|
|
|
)
|
2016-03-17 18:08:03 +09:00
|
|
|
}
|
2016-02-18 21:53:44 +09:00
|
|
|
|
|
|
|
render() {
|
|
|
|
|
2016-03-27 18:17:20 +09:00
|
|
|
({UserAvatar, UserName, Vote, PostStats, PostThumbnail} = Telescope.components);
|
2016-03-19 18:19:28 +09:00
|
|
|
|
2016-02-18 21:53:44 +09:00
|
|
|
const post = this.props.post;
|
|
|
|
|
2016-03-24 16:19:46 +09:00
|
|
|
let postClass = "post-item";
|
|
|
|
if (post.sticky) postClass += " post-sticky";
|
|
|
|
|
2016-03-24 16:03:30 +09:00
|
|
|
// console.log(post)
|
|
|
|
// console.log(post.user)
|
|
|
|
|
2016-02-18 21:53:44 +09:00
|
|
|
return (
|
2016-03-24 16:19:46 +09:00
|
|
|
<div className={postClass}>
|
2016-02-18 21:53:44 +09:00
|
|
|
|
2016-03-24 16:03:30 +09:00
|
|
|
<div className="post-vote">
|
|
|
|
<Vote post={post} currentUser={this.props.currentUser}/>
|
|
|
|
</div>
|
2016-02-18 21:53:44 +09:00
|
|
|
|
2016-03-27 18:17:20 +09:00
|
|
|
{post.thumbnailUrl ? <PostThumbnail post={post}/> : null}
|
|
|
|
|
2016-03-24 16:03:30 +09:00
|
|
|
<div className="post-content">
|
|
|
|
|
|
|
|
<h3 className="post-title">
|
|
|
|
<a className="post-title-link" href={Posts.getLink(post)} target={Posts.getLinkTarget(post)}>{post.title}</a>
|
|
|
|
{this.renderCategories()}
|
|
|
|
</h3>
|
|
|
|
|
|
|
|
<div className="post-meta">
|
2016-03-27 16:32:29 +09:00
|
|
|
<UserAvatar user={post.user} size="small"/>
|
|
|
|
<UserName user={post.user}/>
|
2016-03-24 16:03:30 +09:00
|
|
|
<div className="post-date">{moment(post.postedAt).fromNow()}</div>
|
2016-03-25 11:22:35 +09:00
|
|
|
<div className="post-comments"><a href={Posts.getPageUrl(post)}>{post.commentCount} comments</a></div>
|
2016-03-24 16:03:30 +09:00
|
|
|
<PostStats post={post} />
|
|
|
|
{this.renderActions()}
|
|
|
|
</div>
|
2016-03-27 16:32:29 +09:00
|
|
|
|
2016-03-24 16:03:30 +09:00
|
|
|
</div>
|
2016-03-21 10:27:43 +09:00
|
|
|
|
2016-02-18 21:53:44 +09:00
|
|
|
{this.renderCommenters()}
|
2016-03-24 16:03:30 +09:00
|
|
|
|
2016-02-18 21:53:44 +09:00
|
|
|
|
|
|
|
</div>
|
|
|
|
)
|
|
|
|
}
|
2016-03-17 18:08:03 +09:00
|
|
|
};
|
|
|
|
|
|
|
|
PostItem.propTypes = {
|
|
|
|
post: React.PropTypes.object.isRequired, // the current comment
|
|
|
|
currentUser: React.PropTypes.object, // the current user
|
|
|
|
}
|
2016-02-15 22:33:44 +09:00
|
|
|
|
2016-03-27 13:04:21 +09:00
|
|
|
PostItem.contextTypes = {
|
|
|
|
currentUser: React.PropTypes.object
|
|
|
|
};
|
|
|
|
|
2016-02-15 22:33:44 +09:00
|
|
|
module.exports = PostItem;
|