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

85 lines
3 KiB
React
Raw Normal View History

2017-03-23 16:27:59 +09:00
import { Components, registerComponent, ModalTrigger } from 'meteor/vulcan:core';
2017-05-19 14:42:43 -06:00
import React, { PureComponent } from 'react';
import PropTypes from 'prop-types';
2017-06-01 18:23:36 +09:00
import { FormattedMessage } from 'meteor/vulcan:i18n';
2016-06-11 16:36:18 +09:00
import { Link } from 'react-router';
2017-03-23 16:27:59 +09:00
import Posts from "meteor/vulcan:posts";
2017-06-01 18:23:36 +09:00
import moment from 'moment';
2016-03-30 10:52:40 +09:00
2017-05-19 14:42:43 -06:00
class PostsItem extends PureComponent {
2016-02-18 21:53:44 +09:00
renderCategories() {
return this.props.post.categories && this.props.post.categories.length > 0 ? <Components.PostsCategories post={this.props.post} /> : "";
}
2016-02-18 21:53:44 +09:00
renderCommenters() {
return this.props.post.commenters && this.props.post.commenters.length > 0 ? <Components.PostsCommenters post={this.props.post}/> : "";
}
2016-02-18 21:53:44 +09:00
renderActions() {
return (
2017-04-28 16:37:08 +09:00
<div className="posts-actions">
<ModalTrigger title="Edit Post" component={<a className="posts-action-edit"><FormattedMessage id="posts.edit"/></a>}>
<Components.PostsEditForm post={this.props.post} />
</ModalTrigger>
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() {
const {post} = this.props;
2016-02-18 21:53:44 +09:00
let postClass = "posts-item";
2016-04-26 09:12:38 +09:00
if (post.sticky) postClass += " posts-sticky";
2016-03-24 16:19:46 +09:00
2016-02-18 21:53:44 +09:00
return (
2016-03-24 16:19:46 +09:00
<div className={postClass}>
<div className="posts-item-vote">
<Components.Vote collection={Posts} document={post} currentUser={this.props.currentUser}/>
2016-03-24 16:03:30 +09:00
</div>
{post.thumbnailUrl ? <Components.PostsThumbnail post={post}/> : null}
2016-03-27 18:17:20 +09:00
<div className="posts-item-content">
<h3 className="posts-item-title">
2016-06-17 09:54:25 +09:00
<Link to={Posts.getLink(post)} className="posts-item-title-link" target={Posts.getLinkTarget(post)}>
2016-06-13 16:02:27 +09:00
{post.title}
</Link>
2016-03-24 16:03:30 +09:00
{this.renderCategories()}
</h3>
<div className="posts-item-meta">
{post.user? <div className="posts-item-user"><Components.UsersAvatar user={post.user} size="small"/><Components.UsersName user={post.user}/></div> : null}
2017-06-01 18:23:36 +09:00
<div className="posts-item-date">{post.postedAt ? moment(new Date(post.postedAt)).fromNow() : <FormattedMessage id="posts.dateNotDefined"/>}</div>
2016-06-11 16:36:18 +09:00
<div className="posts-item-comments">
2016-06-17 09:54:25 +09:00
<Link to={Posts.getPageUrl(post)}>
2017-06-01 18:23:36 +09:00
{!post.commentCount || post.commentCount === 0 ? <FormattedMessage id="comments.count_0"/> :
post.commentCount === 1 ? <FormattedMessage id="comments.count_1" /> :
<FormattedMessage id="comments.count_2" values={{count: post.commentCount}}/>
}
2016-06-12 12:11:05 +09:00
</Link>
2016-06-11 16:36:18 +09:00
</div>
{this.props.currentUser && this.props.currentUser.isAdmin ? <Components.PostsStats post={post} /> : null}
{Posts.options.mutations.edit.check(this.props.currentUser, post) ? this.renderActions() : null}
2016-03-24 16:03:30 +09:00
</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-02-18 21:53:44 +09:00
</div>
)
}
}
2016-04-14 10:12:35 +09:00
PostsItem.propTypes = {
2017-05-19 14:42:43 -06:00
currentUser: PropTypes.object,
post: PropTypes.object.isRequired,
terms: PropTypes.object,
};
registerComponent('PostsItem', PostsItem);