lbry-desktop/src/ui/component/commentsList/view.jsx

82 lines
1.9 KiB
React
Raw Normal View History

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 = {
comments: {},
fetchList: string => void,
uri: string,
isLoading: boolean,
};
type CommentProps = {
commentId: string,
claimId: string,
author: string,
message: string,
timePosted: number,
};
class CommentList extends React.PureComponent<CommentListProps> {
componentDidMount() {
this.fetchComments(this.props);
}
2019-05-21 23:15:37 +02:00
2019-05-17 20:21:07 +02:00
fetchComments = (props: Props) => {
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-05-21 23:15:37 +02:00
<ul className="comments">
{comments['comments'].map(comment => {
console.log(comment.message);
return (
<Comment
author={comment.author}
claimId={comment.claim_id}
commentId={comment.comment_id}
key={comment.author + comment.comment_id}
message={comment.message}
timePosted={comment.time_posted}
/>
);
})}
</ul>
2019-05-17 20:21:07 +02:00
);
}
}
class Comment extends React.PureComponent<CommentProps> {
render() {
return (
2019-05-21 23:15:37 +02:00
<li className="comment">
<div className="comment__meta card__actions--between">
<div>{this.props.author}</div>
<time datatime={this.props.timePosted}>{relativeDate(this.props.timePosted)}</time>
</div>
<div className="comment__content">{this.props.message}</div>
<div className="comment__actions card__actions--between">
<button className={'button button--primary'}>Reply</button>
<span>
<button className="comment__action button button--secondary">Up</button>
<button className="comment__action button button--secondary">Down</button>
</span>
2019-05-17 20:21:07 +02:00
</div>
2019-05-21 23:15:37 +02:00
</li>
2019-05-17 20:21:07 +02:00
);
}
}
export default CommentList;