import React from 'react'; import { processor } from "../../utils/seafile-markdown2html"; import { Button, Input, Dropdown, DropdownToggle, DropdownMenu, DropdownItem } from 'reactstrap'; import { seafileAPI } from '../../utils/seafile-api'; import { draftID, reviewID, gettext } from '../../utils/constants'; import moment from 'moment'; import Loading from '../../components/loading.js'; import '../../css/review-comments.css'; class ReviewComments extends React.Component { constructor(props) { super(props); this.state = { commentsList: [], userAvatar: `${window.location.host}media/avatars/default.png`, } this.accountInfo = {}; } listComments = () => { seafileAPI.listReviewComments(reviewID).then((response) => { this.setState({ commentsList: response.data.comments }); }); } getUserAvatar = () => { seafileAPI.getAccountInfo().then((res) => { this.accountInfo = res.data; this.setState({ userAvatar: res.data.avatar_url, }) }) } handleCommentChange = (event) => { this.setState({ comment: event.target.value, }); } submitComment = () => { let comment = this.refs.commentTextarea.value; if (comment.trim().length > 0) { seafileAPI.addReviewComment(reviewID, comment.trim()).then((res) => { this.listComments(); this.props.getCommentsNumber(); }); this.refs.commentTextarea.value = ''; } } resolveComment = (event) => { seafileAPI.updateReviewComment(reviewID, event.target.id, 'true').then((res) => { this.listComments(); }); } deleteComment = (event) => { seafileAPI.deleteReviewComment(reviewID, event.target.id).then((res) => { this.props.getCommentsNumber(); this.listComments(); }); } componentWillMount() { this.getUserAvatar(); this.listComments(); } render() { return (
{gettext('Comments')}
{ this.props.commentsNumber == 0 &&
{gettext('No comment yet.')}
} { (this.state.commentsList.length == 0 && this.props.commentsNumber > 0) &&
}
) } } class CommentItem extends React.Component { constructor(props) { super(props); this.state = { dropdownOpen: false, html: '', } } toggleDropDownMenu = () => { this.setState({ dropdownOpen: !this.state.dropdownOpen, }) } convertComment = (mdFile) => { processor.process(mdFile).then( (result) => { let html = String(result); this.setState({ html: html }) } ); } componentWillMount() { this.convertComment(this.props.comment); } componentWillReceiveProps(nextProps) { this.convertComment(nextProps.comment); } render() { return (
  • {this.props.name}
    {this.props.time}
    { (this.props.user_email === this.props.accountInfo.email) && {gettext('Delete')} } {gettext('Mark as resolved')}
  • ) } } export default ReviewComments;