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

128 lines
3.5 KiB
React
Raw Normal View History

import { Components, registerComponent } from 'meteor/nova:lib';
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";
import { withCurrentUser } from 'meteor/nova:core';
2016-11-26 11:17:01 +09:00
import gql from 'graphql-tag';
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() {
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 (
2016-02-19 10:12:08 +09:00
<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>
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 post={post}/>
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}
<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>
{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 = {
2016-11-15 18:33:16 +01:00
currentUser: React.PropTypes.object,
post: React.PropTypes.object.isRequired,
};
2016-11-26 11:17:01 +09:00
PostsItem.fragment = gql`
fragment PostsItemFragment on Post {
_id
title
url
slug
thumbnailUrl
baseScore
postedAt
sticky
status
categories {
# ...minimumCategoryInfo
_id
name
slug
}
commentCount
commenters {
# ...avatarUserInfo
_id
__displayName
__emailHash
__slug
}
upvoters {
_id
}
downvoters {
_id
}
upvotes # should be asked only for admins?
score # should be asked only for admins?
viewCount # should be asked only for admins?
clickCount # should be asked only for admins?
user {
# ...avatarUserInfo
_id
__displayName
__emailHash
__slug
}
userId
2016-11-26 11:17:01 +09:00
}
`;
registerComponent('PostsItem', PostsItem, withCurrentUser);