Vulcan/packages/customization-demo/lib/components/CustomPostsItem.jsx

118 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-19 16:25:19 +09:00
import { FormattedMessage, FormattedRelative } from 'react-intl';
import { Button } from 'react-bootstrap';
import moment from 'moment';
2016-06-19 16:25:19 +09:00
import { ModalTrigger } from "meteor/nova:core";
import { Link } from 'react-router';
2016-06-23 11:40:35 +09:00
import Posts from "meteor/nova:posts";
2016-06-23 15:11:56 +09:00
import Categories from "meteor/nova:categories";
class CustomPostsItem extends Telescope.getRawComponent('PostsItem') {
render() {
const post = this.props.post;
let postClass = "posts-item";
2016-06-19 16:25:19 +09:00
if (post.sticky) postClass += " posts-sticky";
// ⭐ custom code starts here ⭐
if (post.color) {
postClass += " post-"+post.color;
}
// ⭐ custom code ends here ⭐
return (
<div className={postClass}>
<div className="posts-item-vote">
<Telescope.components.Vote post={post} />
</div>
2016-06-19 16:25:19 +09:00
{post.thumbnailUrl ? <Telescope.components.PostsThumbnail post={post}/> : null}
<div className="posts-item-content">
<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>
{this.renderCategories()}
</h3>
<div className="posts-item-meta">
2016-06-19 16:25:19 +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}
<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>
{this.props.currentUser && this.props.currentUser.isAdmin ? <Telescope.components.PostsStats post={post} /> : null}
{this.renderActions()}
</div>
</div>
{this.renderCommenters()}
2016-06-19 16:25:19 +09:00
</div>
)
}
};
2016-06-19 16:25:19 +09:00
CustomPostsItem.propTypes = {
currentUser: React.PropTypes.object,
2016-06-19 16:25:19 +09:00
post: React.PropTypes.object.isRequired
};
2016-11-29 11:35:20 +09:00
CustomPostsItem.fragmentName = 'PostsItemFragment';
CustomPostsItem.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
}
color
}
`;
Telescope.replaceComponent('PostsItem', CustomPostsItem);