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

90 lines
3.1 KiB
React
Raw Normal View History

2016-08-08 11:18:21 +09:00
import Telescope from 'meteor/nova:lib';
import React, { PropTypes, Component } from 'react';
2016-06-10 10:25:38 +09:00
import { FormattedMessage, FormattedRelative } from 'react-intl';
import { Button } from 'react-bootstrap';
import moment from 'moment';
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";
2016-06-23 15:00:58 +09:00
import Users from 'meteor/nova:users';
2016-11-15 18:33:16 +01: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-10-19 17:38:21 +02:00
return this.props.post.categories && this.props.post.categories.length > 0 ? <Telescope.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 ? <Telescope.components.PostsCommenters post={this.props.post}/> : "";
}
2016-02-18 21:53:44 +09:00
renderActions() {
return (
2016-02-19 10:12:08 +09:00
<div className="post-actions">
<Telescope.components.CanDo
action="posts.edit.all"
document={this.props.post}
>
<ModalTrigger title="Edit Post" component={<a className="posts-action-edit"><FormattedMessage id="posts.edit"/></a>}>
<Telescope.components.PostsEditForm
post={this.props.post}
/>
</ModalTrigger>
</Telescope.components.CanDo>
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}>
2016-02-18 21:53:44 +09:00
<div className="posts-item-vote">
<Telescope.components.Vote post={post}/>
2016-03-24 16:03:30 +09:00
</div>
2016-02-18 21:53:44 +09:00
{post.thumbnailUrl ? <Telescope.components.PostsThumbnail post={post}/> : null}
2016-03-27 18:17:20 +09:00
<div className="posts-item-content">
2016-03-24 16:03:30 +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>
<div className="posts-item-meta">
{post.user? <div className="posts-item-user"><Telescope.components.UsersAvatar user={post.user} size="small"/><Telescope.components.UsersName user={post.user}/></div> : null}
<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-11-15 18:33:16 +01:00
{this.props.currentUser && this.props.currentUser.isAdmin ? <Telescope.components.PostsStats post={post} /> : null}
2016-10-19 17:38:21 +02:00
{this.renderActions()}
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()}
</div>
)
}
};
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,
};
Telescope.registerComponent('PostsItem', PostsItem, withCurrentUser);