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

70 lines
1.9 KiB
React
Raw Normal View History

import React, { PropTypes, Component } from 'react';
class PostItem extends Component {
2016-02-18 21:53:44 +09:00
renderCategories() {
({PostCategories} = Telescope.components);
return this.props.post.categoriesArray ? <PostCategories categories={this.props.post.categoriesArray} /> : "";
}
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-02-19 10:12:08 +09:00
return this.props.post.commentersArray ? <PostCommenters commenters={this.props.post.commentersArray}/> : "";
}
2016-02-18 21:53:44 +09:00
renderActions() {
2016-02-25 21:05:53 +09:00
2016-03-02 13:54:58 +09:00
({ModalButton, DocumentContainer, EditDocContainer} = Telescope.components);
2016-02-25 21:32:13 +09:00
const component = (
<ModalButton label="Edit" className="button button--secondary">
<EditDocContainer
collection={Posts}
document={this.props.post}
label="Edit Post"
methodName="posts.edit"
/>
2016-02-25 21:32:13 +09:00
</ModalButton>
);
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() {
({UserAvatar, 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;
return (
2016-02-19 18:38:39 +09:00
<div className="post-item">
2016-02-18 21:53:44 +09:00
<Vote post={post} currentUser={this.props.currentUser}/>
2016-02-18 21:53:44 +09:00
<h3 className="post-title"><a href={Posts.getLink(post)} target={Posts.getLinkTarget(post)}>{post.title}</a></h3>
2016-03-19 18:19:28 +09:00
<p><a href={Users.getProfileUrl(post.user)}><UserAvatar user={post.user}/>{Users.getDisplayName(post.user)}</a>, {moment(post.postedAt).fromNow()}, {post.commentCount} comments</p>
2016-02-18 21:53:44 +09:00
<PostStats post={post} />
2016-02-18 21:53:44 +09:00
{this.renderCategories()}
{this.renderCommenters()}
{this.renderActions()}
</div>
)
}
};
PostItem.propTypes = {
post: React.PropTypes.object.isRequired, // the current comment
currentUser: React.PropTypes.object, // the current user
}
module.exports = PostItem;