mirror of
https://github.com/vale981/Vulcan
synced 2025-03-10 12:36:39 -04:00
79 lines
2.7 KiB
JavaScript
79 lines
2.7 KiB
JavaScript
import { Components, registerComponent, ModalTrigger } from 'meteor/nova:core';
|
|
import React, { PropTypes, Component } from 'react';
|
|
import { FormattedMessage, FormattedRelative } from 'react-intl';
|
|
import { Link } from 'react-router';
|
|
import Posts from "meteor/nova:posts";
|
|
|
|
class PostsItem extends Component {
|
|
|
|
renderCategories() {
|
|
return this.props.post.categories && this.props.post.categories.length > 0 ? <Components.PostsCategories post={this.props.post} /> : "";
|
|
}
|
|
|
|
renderCommenters() {
|
|
return this.props.post.commenters && this.props.post.commenters.length > 0 ? <Components.PostsCommenters post={this.props.post}/> : "";
|
|
}
|
|
|
|
renderActions() {
|
|
return (
|
|
<div className="post-actions">
|
|
<ModalTrigger title="Edit Post" component={<a className="posts-action-edit"><FormattedMessage id="posts.edit"/></a>}>
|
|
<Components.PostsEditForm post={this.props.post} />
|
|
</ModalTrigger>
|
|
</div>
|
|
)
|
|
}
|
|
|
|
render() {
|
|
|
|
const {post} = this.props;
|
|
|
|
let postClass = "posts-item";
|
|
if (post.sticky) postClass += " posts-sticky";
|
|
|
|
return (
|
|
<div className={postClass}>
|
|
|
|
<div className="posts-item-vote">
|
|
<Components.Vote collection={Posts} document={post} currentUser={this.props.currentUser}/>
|
|
</div>
|
|
|
|
{post.thumbnailUrl ? <Components.PostsThumbnail post={post}/> : null}
|
|
|
|
<div className="posts-item-content">
|
|
|
|
<h3 className="posts-item-title">
|
|
<Link to={Posts.getLink(post)} className="posts-item-title-link" target={Posts.getLinkTarget(post)}>
|
|
{post.title}
|
|
</Link>
|
|
{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}
|
|
<div className="posts-item-date">{post.postedAt ? <FormattedRelative value={post.postedAt}/> : <FormattedMessage id="posts.dateNotDefined"/>}</div>
|
|
<div className="posts-item-comments">
|
|
<Link to={Posts.getPageUrl(post)}>
|
|
<FormattedMessage id="comments.count" values={{count: post.commentCount}}/>
|
|
</Link>
|
|
</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}
|
|
</div>
|
|
|
|
</div>
|
|
|
|
{this.renderCommenters()}
|
|
|
|
</div>
|
|
)
|
|
}
|
|
}
|
|
|
|
PostsItem.propTypes = {
|
|
currentUser: React.PropTypes.object,
|
|
post: React.PropTypes.object.isRequired,
|
|
terms: React.PropTypes.object,
|
|
};
|
|
|
|
registerComponent('PostsItem', PostsItem);
|