Vulcan/packages/base-components/lib/posts/list/PostItem.jsx

100 lines
2.6 KiB
React
Raw Normal View History

import React, { PropTypes, Component } from 'react';
import { Button } from 'react-bootstrap';
import ReactForms from "meteor/utilities:react-form-containers";
const EditDocument = ReactForms.EditDocument;
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-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-02-18 21:53:44 +09:00
renderActions() {
2016-02-25 21:05:53 +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>}>
<h3 className="modal-form-title">Edit Post</h3>
<EditDocument
collection={Posts}
document={this.props.post}
currentUser={this.context.currentUser}
methodName="posts.edit"
/>
</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-02-18 21:53:44 +09:00
render() {
2016-03-24 16:03:30 +09:00
({UserAvatar, UserName, Vote, PostStats} = 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-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}&nbsp;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-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>
)
}
};
PostItem.propTypes = {
post: React.PropTypes.object.isRequired, // the current comment
currentUser: React.PropTypes.object, // the current user
}
PostItem.contextTypes = {
currentUser: React.PropTypes.object
};
module.exports = PostItem;