import React, { Fragment } from 'react'; import PropTypes from 'prop-types'; import moment from 'moment'; import { processor } from '@seafile/seafile-editor/dist/utils/seafile-markdown2html'; import { Button, Dropdown, DropdownToggle, DropdownMenu, DropdownItem } from 'reactstrap'; import { gettext } from '../../utils/constants'; import { seafileAPI } from '../../utils/seafile-api'; import { Utils } from '../../utils/utils'; import toaster from '../toast'; import '../../css/comments-list.css'; const { username } = window.app.pageOptions; const DetailCommentListPropTypes = { repoID: PropTypes.string.isRequired, filePath: PropTypes.string.isRequired, }; class DetailCommentList extends React.Component { constructor(props) { super(props); this.state = { commentsList: [], }; } componentDidMount() { this.listComments(); } componentWillReceiveProps(nextProps) { if (nextProps.filePath !== this.props.filePath) { this.listComments(nextProps.filePath); } } listComments = (filePath) => { seafileAPI.listComments(this.props.repoID, (filePath || this.props.filePath)).then((res) => { this.setState({ commentsList: res.data.comments }); }).catch(error => { let errMessage = Utils.getErrorMsg(error); toaster.danger(errMessage); }); } handleCommentChange = (event) => { this.setState({ comment: event.target.value }); } submitComment = () => { let comment = this.refs.commentTextarea.value; const { repoID, filePath } = this.props; if (comment.trim()) { seafileAPI.postComment(repoID, filePath, comment.trim()).then(() => { this.listComments(); }).catch(error => { let errMessage = Utils.getErrorMsg(error); toaster.danger(errMessage); }); } this.refs.commentTextarea.value = ''; } resolveComment = (event) => { const { repoID } = this.props; seafileAPI.updateComment(repoID, event.target.id, 'true').then(() => { this.listComments(); }).catch(error => { let errMessage = Utils.getErrorMsg(error); toaster.danger(errMessage); }); } deleteComment = (event) => { const { repoID } = this.props; seafileAPI.deleteComment(repoID, event.target.id).then(() => { this.listComments(); }).catch(error => { let errMessage = Utils.getErrorMsg(error); toaster.danger(errMessage); }); } editComment = (commentID, newComment) => { const { repoID } = this.props; seafileAPI.updateComment(repoID, commentID, null, null, newComment).then(() => { this.listComments(); }).catch(error => { let errMessage = Utils.getErrorMsg(error); toaster.danger(errMessage); }); } render() { return (