Vulcan/packages/nova-base-components/lib/posts/PostsItem.jsx

99 lines
2.6 KiB
React
Raw Normal View History

import React, { PropTypes, Component } from 'react';
import { Button } from 'react-bootstrap';
2016-03-30 10:52:40 +09:00
import Core from "meteor/nova:core";
const ModalTrigger = Core.ModalTrigger;
import SmartContainers from "meteor/utilities:react-list-container";
const DocumentContainer = SmartContainers.DocumentContainer;
2016-04-14 10:12:35 +09:00
class PostsItem extends Component {
2016-02-18 21:53:44 +09:00
renderCategories() {
2016-04-14 10:12:35 +09:00
({PostsCategories} = Telescope.components);
2016-02-18 21:53:44 +09:00
2016-04-14 10:12:35 +09:00
return this.props.post.categoriesArray ? <PostsCategories post={this.props.post} /> : "";
}
2016-02-18 21:53:44 +09:00
renderCommenters() {
2016-04-14 10:12:35 +09:00
({PostsCommenters} = Telescope.components);
2016-02-18 21:53:44 +09:00
2016-04-14 10:12:35 +09:00
return this.props.post.commentersArray ? <PostsCommenters post={this.props.post}/> : "";
}
2016-02-18 21:53:44 +09:00
renderActions() {
2016-02-25 21:05:53 +09:00
2016-04-14 10:12:35 +09:00
({PostsEditForm} = Telescope.components);
2016-02-25 21:32:13 +09:00
const component = (
2016-04-07 10:33:44 +09:00
<ModalTrigger title="Edit Post" component={<a className="edit-link">Edit</a>}>
2016-04-14 10:12:35 +09:00
<PostsEditForm post={this.props.post}/>
</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-04-14 10:12:35 +09:00
({UserAvatar, UserName, Vote, PostsStats, PostsThumbnail} = 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-04-14 10:12:35 +09:00
{post.thumbnailUrl ? <PostsThumbnail post={post}/> : null}
2016-03-27 18:17:20 +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-28 12:36:29 +09:00
{post.user? <div className="post-user"><UserAvatar user={post.user} size="small"/><UserName user={post.user}/></div> : null}
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-04-14 10:12:35 +09:00
<PostsStats post={post} />
2016-03-24 16:03:30 +09:00
{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>
)
}
};
2016-04-14 10:12:35 +09:00
PostsItem.propTypes = {
2016-03-29 10:13:35 +09:00
post: React.PropTypes.object.isRequired,
currentUser: React.PropTypes.object
}
2016-04-14 10:12:35 +09:00
PostsItem.contextTypes = {
currentUser: React.PropTypes.object
};
2016-04-14 10:12:35 +09:00
module.exports = PostsItem;
export default PostsItem;