2019-05-17 20:21:07 +02:00
|
|
|
// @flow
|
|
|
|
import * as React from 'react';
|
2019-05-21 23:15:37 +02:00
|
|
|
import relativeDate from 'tiny-relative-date';
|
2019-05-17 20:21:07 +02:00
|
|
|
|
|
|
|
type CommentListProps = {
|
2019-06-12 16:53:27 +02:00
|
|
|
comments: Array<any>,
|
2019-05-17 20:21:07 +02:00
|
|
|
fetchList: string => void,
|
|
|
|
uri: string,
|
|
|
|
isLoading: boolean,
|
|
|
|
};
|
|
|
|
|
|
|
|
type CommentProps = {
|
|
|
|
commentId: string,
|
|
|
|
claimId: string,
|
|
|
|
author: string,
|
|
|
|
message: string,
|
2019-05-22 20:59:46 +02:00
|
|
|
parentId: number,
|
2019-05-17 20:21:07 +02:00
|
|
|
timePosted: number,
|
|
|
|
};
|
|
|
|
|
|
|
|
class CommentList extends React.PureComponent<CommentListProps> {
|
|
|
|
componentDidMount() {
|
|
|
|
this.fetchComments(this.props);
|
|
|
|
}
|
2019-05-21 23:15:37 +02:00
|
|
|
|
2019-06-12 16:53:27 +02:00
|
|
|
fetchComments = (props: CommentListProps) => {
|
2019-05-17 20:21:07 +02:00
|
|
|
const { fetchList, uri } = props;
|
|
|
|
fetchList(uri);
|
|
|
|
};
|
2019-05-21 23:15:37 +02:00
|
|
|
|
2019-05-17 20:21:07 +02:00
|
|
|
render() {
|
|
|
|
const { comments } = this.props;
|
2019-05-21 23:15:37 +02:00
|
|
|
|
2019-05-17 20:21:07 +02:00
|
|
|
if (!comments) {
|
|
|
|
return null;
|
|
|
|
}
|
2019-05-21 23:15:37 +02:00
|
|
|
|
2019-05-17 20:21:07 +02:00
|
|
|
return (
|
2019-06-12 16:53:27 +02:00
|
|
|
<section>
|
|
|
|
<ul className="comments">
|
|
|
|
{comments.map(comment => {
|
|
|
|
return (
|
|
|
|
<Comment
|
|
|
|
author={comment.channel_name}
|
|
|
|
claimId={comment.channel_id}
|
|
|
|
commentId={comment.comment_id}
|
|
|
|
key={comment.channel_id + comment.comment_id}
|
|
|
|
message={comment.comment}
|
|
|
|
parentId={comment.parent_id || null}
|
|
|
|
timePosted={comment.timestamp * 1000}
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
})}
|
|
|
|
</ul>
|
|
|
|
</section>
|
2019-05-17 20:21:07 +02:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class Comment extends React.PureComponent<CommentProps> {
|
|
|
|
render() {
|
|
|
|
return (
|
2019-05-22 20:59:46 +02:00
|
|
|
<li className={this.props.parentId ? 'comment reply' : 'comment'}>
|
2019-05-21 23:15:37 +02:00
|
|
|
<div className="comment__meta card__actions--between">
|
2019-06-12 16:53:27 +02:00
|
|
|
{this.props.author && <strong>{this.props.author}</strong>}
|
|
|
|
{!this.props.author && <strong>Anonymous</strong>}
|
|
|
|
|
2019-05-22 20:59:46 +02:00
|
|
|
<time dateTime={this.props.timePosted}>{relativeDate(this.props.timePosted)}</time>
|
2019-05-21 23:15:37 +02:00
|
|
|
</div>
|
|
|
|
|
|
|
|
<div className="comment__content">{this.props.message}</div>
|
2019-06-12 16:53:27 +02:00
|
|
|
{/* The following is for adding threaded replies, upvoting and downvoting */}
|
|
|
|
{/* <div className="comment__actions card__actions--between"> */}
|
|
|
|
{/* <button className={'button button--primary'}>Reply</button> */}
|
2019-05-21 23:15:37 +02:00
|
|
|
|
2019-06-12 16:53:27 +02:00
|
|
|
{/* <span className="comment__actions-wrap"> */}
|
|
|
|
{/* <button className="comment__action upvote">Up</button> */}
|
|
|
|
{/* <button className="comment__action downvote">Down</button> */}
|
|
|
|
{/* </span> */}
|
|
|
|
{/* </div> */}
|
2019-05-21 23:15:37 +02:00
|
|
|
</li>
|
2019-05-17 20:21:07 +02:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export default CommentList;
|