2018-08-06 11:52:18 -04:00
|
|
|
const React = require('react');
|
|
|
|
const PropTypes = require('prop-types');
|
|
|
|
const bindAll = require('lodash.bindall');
|
|
|
|
const classNames = require('classnames');
|
|
|
|
|
|
|
|
const FlexRow = require('../../../components/flex-row/flex-row.jsx');
|
|
|
|
const Comment = require('./comment.jsx');
|
|
|
|
|
|
|
|
require('./comment.scss');
|
|
|
|
|
|
|
|
class TopLevelComment extends React.Component {
|
|
|
|
constructor (props) {
|
|
|
|
super(props);
|
|
|
|
bindAll(this, [
|
2018-10-03 13:21:36 -04:00
|
|
|
'handleExpandThread',
|
|
|
|
'handleDelete'
|
2018-08-06 11:52:18 -04:00
|
|
|
]);
|
|
|
|
this.state = {
|
|
|
|
expanded: false
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
handleExpandThread () {
|
|
|
|
this.setState({
|
|
|
|
expanded: true
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2018-10-03 13:21:36 -04:00
|
|
|
handleDelete () {
|
|
|
|
this.props.onDelete(this.props.id);
|
|
|
|
}
|
|
|
|
|
2018-08-06 11:52:18 -04:00
|
|
|
render () {
|
|
|
|
const {
|
|
|
|
author,
|
2018-10-04 15:02:59 -04:00
|
|
|
canReply,
|
2018-08-06 11:52:18 -04:00
|
|
|
content,
|
|
|
|
datetimeCreated,
|
2018-10-03 13:21:36 -04:00
|
|
|
deletable,
|
|
|
|
deleted,
|
2018-08-06 11:52:18 -04:00
|
|
|
id,
|
2018-10-04 15:02:59 -04:00
|
|
|
replies,
|
|
|
|
projectId,
|
|
|
|
onAddComment
|
2018-08-06 11:52:18 -04:00
|
|
|
} = this.props;
|
|
|
|
|
|
|
|
return (
|
|
|
|
<FlexRow className="comment-container">
|
2018-10-03 13:21:36 -04:00
|
|
|
<Comment
|
2018-10-04 15:02:59 -04:00
|
|
|
projectId={projectId}
|
|
|
|
onAddComment={onAddComment}
|
2018-10-03 13:21:36 -04:00
|
|
|
onDelete={this.handleDelete}
|
2018-10-04 15:02:59 -04:00
|
|
|
{...{author, content, datetimeCreated, deletable, deleted, canReply, id}}
|
2018-10-03 13:21:36 -04:00
|
|
|
/>
|
2018-08-06 11:52:18 -04:00
|
|
|
{replies.length > 0 &&
|
|
|
|
<FlexRow
|
|
|
|
className={classNames(
|
|
|
|
'replies',
|
|
|
|
'column',
|
|
|
|
{collapsed: !this.state.expanded && replies.length > 3}
|
|
|
|
)}
|
|
|
|
key={id}
|
|
|
|
>
|
|
|
|
{(this.state.expanded ? replies : replies.slice(0, 3)).map(reply => (
|
|
|
|
<Comment
|
|
|
|
author={reply.author}
|
2018-10-04 15:02:59 -04:00
|
|
|
canReply={canReply}
|
2018-08-06 11:52:18 -04:00
|
|
|
content={reply.content}
|
|
|
|
datetimeCreated={reply.datetime_created}
|
2018-10-03 13:21:36 -04:00
|
|
|
deletable={deletable}
|
|
|
|
deleted={reply.deleted}
|
2018-08-06 11:52:18 -04:00
|
|
|
id={reply.id}
|
|
|
|
key={reply.id}
|
2018-10-04 15:02:59 -04:00
|
|
|
projectId={projectId}
|
|
|
|
onAddComment={this.props.onAddComment}
|
2018-10-03 13:21:36 -04:00
|
|
|
onDelete={this.handleDelete}
|
2018-08-06 11:52:18 -04:00
|
|
|
/>
|
|
|
|
))}
|
|
|
|
</FlexRow>
|
|
|
|
}
|
|
|
|
{!this.state.expanded && replies.length > 3 &&
|
|
|
|
<a
|
|
|
|
className="expand-thread"
|
|
|
|
onClick={this.handleExpandThread}
|
|
|
|
>See all {replies.length} replies</a>
|
|
|
|
}
|
|
|
|
</FlexRow>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
TopLevelComment.propTypes = {
|
|
|
|
author: PropTypes.shape({
|
|
|
|
id: PropTypes.number,
|
|
|
|
image: PropTypes.string,
|
|
|
|
username: PropTypes.string
|
|
|
|
}),
|
2018-10-04 15:02:59 -04:00
|
|
|
canReply: PropTypes.bool,
|
2018-08-06 11:52:18 -04:00
|
|
|
content: PropTypes.string,
|
|
|
|
datetimeCreated: PropTypes.string,
|
2018-10-03 13:21:36 -04:00
|
|
|
deletable: PropTypes.bool,
|
|
|
|
deleted: PropTypes.bool,
|
2018-08-06 11:52:18 -04:00
|
|
|
id: PropTypes.number,
|
2018-10-04 15:02:59 -04:00
|
|
|
onAddComment: PropTypes.func,
|
2018-10-03 13:21:36 -04:00
|
|
|
onDelete: PropTypes.func,
|
2018-08-06 11:52:18 -04:00
|
|
|
parentId: PropTypes.number,
|
|
|
|
projectId: PropTypes.string,
|
|
|
|
replies: PropTypes.arrayOf(PropTypes.object)
|
|
|
|
};
|
|
|
|
|
|
|
|
module.exports = TopLevelComment;
|