mirror of
https://github.com/vale981/Vulcan
synced 2025-03-06 10:01:40 -05:00
pass currentUser to CommentsItem instead of using HoC
This commit is contained in:
parent
2ed1762e3e
commit
b42d7892f7
4 changed files with 15 additions and 36 deletions
|
@ -1,4 +1,4 @@
|
|||
import { Components, registerComponent, withCurrentUser, withMessages } from 'meteor/vulcan:core';
|
||||
import { Components, registerComponent, withMessages } from 'meteor/vulcan:core';
|
||||
import React, { PureComponent } from 'react';
|
||||
import PropTypes from 'prop-types';
|
||||
import { intlShape, FormattedMessage } from 'meteor/vulcan:i18n';
|
||||
|
@ -132,4 +132,4 @@ CommentsItem.contextTypes = {
|
|||
intl: intlShape
|
||||
};
|
||||
|
||||
registerComponent('CommentsItem', CommentsItem, withCurrentUser, withMessages);
|
||||
registerComponent('CommentsItem', CommentsItem);
|
||||
|
|
|
@ -2,12 +2,12 @@ import { Components, registerComponent } from 'meteor/vulcan:core';
|
|||
import React from 'react';
|
||||
import { FormattedMessage } from 'meteor/vulcan:i18n';
|
||||
|
||||
const CommentsList = ({comments, commentCount}) => {
|
||||
const CommentsList = ({comments, commentCount, currentUser}) => {
|
||||
|
||||
if (commentCount > 0) {
|
||||
return (
|
||||
<div className="comments-list">
|
||||
{comments.map(comment => <Components.CommentsNode comment={comment} key={comment._id} />)}
|
||||
{comments.map(comment => <Components.CommentsNode currentUser={currentUser} comment={comment} key={comment._id} />)}
|
||||
{/*hasMore ? (ready ? <Components.CommentsLoadMore loadMore={loadMore} count={count} totalCount={totalCount} /> : <Components.Loading/>) : null*/}
|
||||
</div>
|
||||
)
|
||||
|
|
|
@ -2,37 +2,16 @@ import { Components, registerComponent } from 'meteor/vulcan:core';
|
|||
import React, { PureComponent } from 'react';
|
||||
import PropTypes from 'prop-types';
|
||||
|
||||
class CommentsNode extends PureComponent {
|
||||
|
||||
renderComment(comment) {
|
||||
|
||||
return (
|
||||
<Components.CommentsItem comment={comment} key={comment._id} />
|
||||
)
|
||||
}
|
||||
|
||||
renderChildren(children) {
|
||||
return (
|
||||
<div className="comments-children">
|
||||
{children.map(comment => <CommentsNode comment={comment} key={comment._id} />)}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
render() {
|
||||
|
||||
const comment = this.props.comment;
|
||||
const children = this.props.comment.childrenResults;
|
||||
|
||||
return (
|
||||
const CommentsNode = ({ comment, currentUser }) =>
|
||||
<div className="comments-node">
|
||||
{this.renderComment(comment)}
|
||||
{children ? this.renderChildren(children) : null}
|
||||
<Components.CommentsItem currentUser={currentUser} comment={comment} key={comment._id} />
|
||||
{comment.childrenResults ?
|
||||
<div className="comments-children">
|
||||
{comment.childrenResults.map(comment => <CommentsNode currentUser={currentUser} comment={comment} key={comment._id} />)}
|
||||
</div>
|
||||
)
|
||||
: null
|
||||
}
|
||||
|
||||
}
|
||||
</div>
|
||||
|
||||
CommentsNode.propTypes = {
|
||||
comment: PropTypes.object.isRequired, // the current comment
|
||||
|
|
|
@ -6,7 +6,7 @@ import Comments from 'meteor/vulcan:comments';
|
|||
|
||||
const PostsCommentsThread = (props, /* context*/) => {
|
||||
|
||||
const {loading, terms: { postId }, results, totalCount} = props;
|
||||
const {loading, terms: { postId }, results, totalCount, currentUser} = props;
|
||||
|
||||
if (loading) {
|
||||
|
||||
|
@ -20,8 +20,8 @@ const PostsCommentsThread = (props, /* context*/) => {
|
|||
return (
|
||||
<div className="posts-comments-thread">
|
||||
<h4 className="posts-comments-thread-title"><FormattedMessage id="comments.comments"/></h4>
|
||||
<Components.CommentsList comments={nestedComments} commentCount={totalCount}/>
|
||||
{!!props.currentUser ?
|
||||
<Components.CommentsList currentUser={currentUser} comments={nestedComments} commentCount={totalCount}/>
|
||||
{!!currentUser ?
|
||||
<div className="posts-comments-thread-new">
|
||||
<h4><FormattedMessage id="comments.new"/></h4>
|
||||
<Components.CommentsNewForm
|
||||
|
|
Loading…
Add table
Reference in a new issue