2016-12-06 18:06:29 +01:00
|
|
|
import { Components, registerComponent } from 'meteor/nova:lib';
|
2016-03-17 18:08:03 +09:00
|
|
|
import React, { PropTypes, Component } from 'react';
|
2016-06-10 10:25:38 +09:00
|
|
|
import { FormattedMessage, FormattedRelative } from 'react-intl';
|
2016-05-22 15:23:30 +09:00
|
|
|
import { ModalTrigger } from "meteor/nova:core";
|
2016-06-11 16:36:18 +09:00
|
|
|
import { Link } from 'react-router';
|
2016-06-23 11:40:35 +09:00
|
|
|
import Posts from "meteor/nova:posts";
|
2017-01-10 17:49:03 +09:00
|
|
|
// import { withCurrentUser } from 'meteor/nova:core';
|
2016-03-30 10:52:40 +09:00
|
|
|
|
2016-04-14 10:12:35 +09:00
|
|
|
class PostsItem extends Component {
|
2016-02-18 21:53:44 +09:00
|
|
|
|
|
|
|
renderCategories() {
|
2016-12-06 18:06:29 +01:00
|
|
|
return this.props.post.categories && this.props.post.categories.length > 0 ? <Components.PostsCategories post={this.props.post} /> : "";
|
2016-03-17 18:08:03 +09:00
|
|
|
}
|
2016-02-18 21:53:44 +09:00
|
|
|
|
|
|
|
renderCommenters() {
|
2016-12-06 18:06:29 +01:00
|
|
|
return this.props.post.commenters && this.props.post.commenters.length > 0 ? <Components.PostsCommenters post={this.props.post}/> : "";
|
2016-03-17 18:08:03 +09:00
|
|
|
}
|
2016-02-18 21:53:44 +09:00
|
|
|
|
|
|
|
renderActions() {
|
|
|
|
return (
|
2016-02-19 10:12:08 +09:00
|
|
|
<div className="post-actions">
|
2016-11-30 16:54:58 +09:00
|
|
|
<ModalTrigger title="Edit Post" component={<a className="posts-action-edit"><FormattedMessage id="posts.edit"/></a>}>
|
2016-12-06 18:06:29 +01:00
|
|
|
<Components.PostsEditForm post={this.props.post} />
|
2016-11-30 16:54:58 +09:00
|
|
|
</ModalTrigger>
|
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
|
|
|
}
|
2017-01-09 15:42:24 +09:00
|
|
|
|
2016-02-18 21:53:44 +09:00
|
|
|
render() {
|
|
|
|
|
2016-11-08 12:58:53 +01:00
|
|
|
const {post} = this.props;
|
2016-02-18 21:53:44 +09:00
|
|
|
|
2016-11-26 02:46:55 +08: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}>
|
2016-11-26 02:46:55 +08:00
|
|
|
|
2016-04-19 15:45:36 +09:00
|
|
|
<div className="posts-item-vote">
|
2017-01-09 15:42:24 +09:00
|
|
|
<Components.Vote collection={Posts} document={post}/>
|
2016-03-24 16:03:30 +09:00
|
|
|
</div>
|
2016-11-26 02:46:55 +08:00
|
|
|
|
2016-12-06 18:06:29 +01:00
|
|
|
{post.thumbnailUrl ? <Components.PostsThumbnail post={post}/> : null}
|
2016-03-27 18:17:20 +09:00
|
|
|
|
2016-04-19 15:45:36 +09:00
|
|
|
<div className="posts-item-content">
|
2016-11-26 02:46:55 +08:00
|
|
|
|
2016-04-19 15:45:36 +09:00
|
|
|
<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>
|
2016-11-26 02:46:55 +08:00
|
|
|
|
2016-04-19 15:45:36 +09:00
|
|
|
<div className="posts-item-meta">
|
2016-12-06 18:06:29 +01:00
|
|
|
{post.user? <div className="posts-item-user"><Components.UsersAvatar user={post.user} size="small"/><Components.UsersName user={post.user}/></div> : null}
|
2016-07-07 11:19:01 +02:00
|
|
|
<div className="posts-item-date">{post.postedAt ? <FormattedRelative value={post.postedAt}/> : <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)}>
|
2016-06-12 12:11:05 +09:00
|
|
|
<FormattedMessage id="comments.count" values={{count: post.commentCount}}/>
|
|
|
|
</Link>
|
2016-06-11 16:36:18 +09:00
|
|
|
</div>
|
2016-12-06 18:06:29 +01:00
|
|
|
{this.props.currentUser && this.props.currentUser.isAdmin ? <Components.PostsStats post={post} /> : null}
|
2016-11-30 16:54:58 +09:00
|
|
|
{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-03-21 10:27:43 +09:00
|
|
|
|
2016-02-18 21:53:44 +09:00
|
|
|
{this.renderCommenters()}
|
2016-11-26 02:46:55 +08:00
|
|
|
|
2016-02-18 21:53:44 +09:00
|
|
|
</div>
|
|
|
|
)
|
|
|
|
}
|
2016-11-26 02:46:55 +08:00
|
|
|
}
|
|
|
|
|
2016-04-14 10:12:35 +09:00
|
|
|
PostsItem.propTypes = {
|
2016-11-15 18:33:16 +01:00
|
|
|
currentUser: React.PropTypes.object,
|
|
|
|
post: React.PropTypes.object.isRequired,
|
2016-03-27 13:04:21 +09:00
|
|
|
};
|
|
|
|
|
2017-01-10 17:49:03 +09:00
|
|
|
registerComponent('PostsItem', PostsItem);
|