2016-08-08 11:18:21 +09:00
|
|
|
import Telescope 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-03-24 10:56:47 +09:00
|
|
|
import { Button } from 'react-bootstrap';
|
2016-06-07 15:03:00 +09:00
|
|
|
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-29 14:08:24 +01:00
|
|
|
import { withCurrentUser } from 'meteor/nova:users';
|
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() {
|
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-03-17 18:08:03 +09:00
|
|
|
}
|
2016-02-18 21:53:44 +09:00
|
|
|
|
|
|
|
renderCommenters() {
|
2016-11-07 18:03:07 +01:00
|
|
|
return this.props.post.commenters && this.props.post.commenters.length > 0 ? <Telescope.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>}>
|
|
|
|
<Telescope.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-03-17 18:08:03 +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-04-19 15:45:36 +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
|
|
|
|
2016-04-19 15:45:36 +09:00
|
|
|
<div className="posts-item-vote">
|
2016-11-11 11:23:39 +01:00
|
|
|
<Telescope.components.Vote post={post}/>
|
2016-03-24 16:03:30 +09:00
|
|
|
</div>
|
2016-02-18 21:53:44 +09:00
|
|
|
|
2016-05-22 16:42:24 +09:00
|
|
|
{post.thumbnailUrl ? <Telescope.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-03-24 16:03:30 +09: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-04-19 15:45:36 +09:00
|
|
|
<div className="posts-item-meta">
|
2016-05-22 16:42:24 +09:00
|
|
|
{post.user? <div className="posts-item-user"><Telescope.components.UsersAvatar user={post.user} size="small"/><Telescope.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-11-15 18:33:16 +01:00
|
|
|
{this.props.currentUser && this.props.currentUser.isAdmin ? <Telescope.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()}
|
|
|
|
|
|
|
|
</div>
|
|
|
|
)
|
|
|
|
}
|
2016-03-17 18:08:03 +09: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
|
|
|
};
|
|
|
|
|
2016-11-26 11:17:01 +09:00
|
|
|
PostsItem.fragmentName = 'PostsItemFragment';
|
|
|
|
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
|
|
|
|
}
|
2016-11-30 16:54:58 +09:00
|
|
|
userId
|
2016-11-26 11:17:01 +09:00
|
|
|
}
|
|
|
|
`;
|
|
|
|
|
2016-11-17 20:00:20 +01:00
|
|
|
Telescope.registerComponent('PostsItem', PostsItem, withCurrentUser);
|