2016-12-06 18:06:29 +01:00
|
|
|
import { Components, getRawComponent, replaceComponent } from 'meteor/nova:lib';
|
2016-06-16 11:34:13 +09:00
|
|
|
import React, { PropTypes, Component } from 'react';
|
2016-06-19 16:25:19 +09:00
|
|
|
import { FormattedMessage, FormattedRelative } from 'react-intl';
|
|
|
|
import { Link } from 'react-router';
|
2016-06-23 11:40:35 +09:00
|
|
|
import Posts from "meteor/nova:posts";
|
2016-12-08 11:03:20 +09:00
|
|
|
import gql from 'graphql-tag';
|
2016-06-16 11:34:13 +09:00
|
|
|
|
2016-12-06 18:06:29 +01:00
|
|
|
class CustomPostsItem extends getRawComponent('PostsItem') {
|
2016-06-16 11:34:13 +09:00
|
|
|
|
|
|
|
render() {
|
|
|
|
|
|
|
|
const post = this.props.post;
|
|
|
|
|
2016-11-26 02:46:55 +08:00
|
|
|
let postClass = "posts-item";
|
2016-06-19 16:25:19 +09:00
|
|
|
if (post.sticky) postClass += " posts-sticky";
|
|
|
|
|
2016-06-16 11:34:13 +09:00
|
|
|
// ⭐ custom code starts here ⭐
|
|
|
|
if (post.color) {
|
|
|
|
postClass += " post-"+post.color;
|
|
|
|
}
|
|
|
|
// ⭐ custom code ends here ⭐
|
|
|
|
|
|
|
|
return (
|
|
|
|
<div className={postClass}>
|
2016-11-26 02:46:55 +08:00
|
|
|
|
2016-06-16 11:34:13 +09:00
|
|
|
<div className="posts-item-vote">
|
2017-01-22 10:12:05 +09:00
|
|
|
<Components.Vote collection={Posts} document={post} currentUser={this.props.currentUser}/>
|
2016-06-16 11:34:13 +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-06-16 11:34:13 +09:00
|
|
|
|
|
|
|
<div className="posts-item-content">
|
2016-11-26 02:46:55 +08:00
|
|
|
|
2016-06-16 11:34:13 +09:00
|
|
|
<h3 className="posts-item-title">
|
2016-06-19 16:25:19 +09:00
|
|
|
<Link to={Posts.getLink(post)} className="posts-item-title-link" target={Posts.getLinkTarget(post)}>
|
|
|
|
{post.title}
|
|
|
|
</Link>
|
2016-06-16 11:34:13 +09:00
|
|
|
{this.renderCategories()}
|
|
|
|
</h3>
|
2016-11-26 02:46:55 +08:00
|
|
|
|
2016-06-16 11:34:13 +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-06-19 16:25:19 +09:00
|
|
|
<div className="posts-item-date"><FormattedRelative value={post.postedAt}/></div>
|
|
|
|
<div className="posts-item-comments">
|
|
|
|
<Link to={Posts.getPageUrl(post)}>
|
|
|
|
<FormattedMessage id="comments.count" values={{count: post.commentCount}}/>
|
|
|
|
</Link>
|
|
|
|
</div>
|
2016-12-06 18:06:29 +01:00
|
|
|
{this.props.currentUser && this.props.currentUser.isAdmin ? <Components.PostsStats post={post} /> : null}
|
2017-01-10 11:17:16 +01:00
|
|
|
{Posts.options.mutations.edit.check(this.props.currentUser, post) ? this.renderActions() : null}
|
2016-06-16 11:34:13 +09:00
|
|
|
</div>
|
|
|
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
{this.renderCommenters()}
|
2016-11-26 02:46:55 +08:00
|
|
|
|
|
|
|
|
2016-06-16 11:34:13 +09:00
|
|
|
</div>
|
|
|
|
)
|
|
|
|
}
|
2016-11-26 02:46:55 +08:00
|
|
|
}
|
|
|
|
|
2016-06-19 16:25:19 +09:00
|
|
|
CustomPostsItem.propTypes = {
|
2016-11-17 20:00:20 +01:00
|
|
|
currentUser: React.PropTypes.object,
|
2016-06-19 16:25:19 +09:00
|
|
|
post: React.PropTypes.object.isRequired
|
|
|
|
};
|
2016-06-16 11:34:13 +09:00
|
|
|
|
2016-11-29 11:35:20 +09:00
|
|
|
CustomPostsItem.fragment = gql`
|
2017-01-10 10:07:13 +01:00
|
|
|
fragment CustomPostsItemFragment on Post {
|
2016-11-29 11:35:20 +09:00
|
|
|
_id
|
|
|
|
title
|
|
|
|
url
|
|
|
|
slug
|
|
|
|
thumbnailUrl
|
|
|
|
baseScore
|
|
|
|
postedAt
|
|
|
|
sticky
|
|
|
|
status
|
|
|
|
categories {
|
|
|
|
# ...minimumCategoryInfo
|
|
|
|
_id
|
|
|
|
name
|
|
|
|
slug
|
|
|
|
}
|
|
|
|
commentCount
|
|
|
|
commenters {
|
|
|
|
# ...avatarUserInfo
|
|
|
|
_id
|
2017-01-18 10:18:33 +09:00
|
|
|
displayName
|
|
|
|
emailHash
|
|
|
|
slug
|
2016-11-29 11:35:20 +09:00
|
|
|
}
|
|
|
|
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
|
2017-01-18 10:18:33 +09:00
|
|
|
displayName
|
|
|
|
emailHash
|
|
|
|
slug
|
2016-11-29 11:35:20 +09:00
|
|
|
}
|
|
|
|
color
|
|
|
|
}
|
|
|
|
`;
|
|
|
|
|
2016-12-08 23:48:16 +01:00
|
|
|
replaceComponent('PostsItem', CustomPostsItem);
|