import React from 'react'; import PropTypes from 'prop-types'; import { processor } from '../../utils/seafile-markdown2html'; import { Button, Dropdown, DropdownToggle, DropdownMenu, DropdownItem } from 'reactstrap'; import { seafileAPI } from '../../utils/seafile-api'; import { reviewID, gettext } from '../../utils/constants'; import Loading from '../../components/loading.js'; import reviewComment from '../../models/review-comment.js'; import '../../css/review-comments.css'; const commentPropTypes = { getCommentsNumber: PropTypes.func.isRequired, inResizing: PropTypes.bool.isRequired, commentsNumber: PropTypes.number, scrollToQuote: PropTypes.func.isRequired }; class ReviewComments extends React.Component { constructor(props) { super(props); this.state = { commentsList: [], inResizing: false, commentFooterHeight: 30, showResolvedComment: true, comment: '', }; this.accountInfo = {}; } listComments = (scroll) => { seafileAPI.listReviewComments(reviewID).then((response) => { response.data.comments.reverse(); let commentList = []; response.data.comments.forEach(item => { let commentItem = new reviewComment(item); commentList.push(commentItem); }); this.setState({ commentsList: commentList }); if (scroll) { this.refs.commentsList.scrollTo(0, 10000); } }); } handleCommentChange = (event) => { this.setState({ comment: event.target.value, }); } submitComment = () => { let comment = this.state.comment.trim(); if (comment.length > 0) { seafileAPI.addReviewComment(reviewID, comment).then((response) => { this.listComments(true); this.props.getCommentsNumber(); }); this.setState({ comment: '' }); } } resolveComment = (event) => { seafileAPI.updateReviewComment(reviewID, event.target.id, 'true').then((res) => { this.listComments(); }); } toggleResolvedComment = () => { this.setState({ showResolvedComment: !this.state.showResolvedComment }); } deleteComment = (event) => { seafileAPI.deleteReviewComment(reviewID, event.target.id).then((res) => { this.props.getCommentsNumber(); this.listComments(); }); } onResizeMouseUp = () => { if (this.state.inResizing) { this.setState({ inResizing: false }); } } onResizeMouseDown = () => { this.setState({ inResizing: true }); }; onResizeMouseMove = (event) => { let rate = 100 - (event.nativeEvent.clientY - 120 ) / this.refs.comment.clientHeight * 100; if (rate < 20 || rate > 70) { if (rate < 20) { this.setState({ commentFooterHeight: 25 }); } if (rate > 70) { this.setState({ commentFooterHeight: 65 }); } this.setState({ inResizing: false }); return null; } this.setState({ commentFooterHeight: rate }); }; scrollToQuote = (newIndex, oldIndex, quote) => { this.props.scrollToQuote(newIndex, oldIndex, quote); this.setState({ comment: '' }); } componentWillMount() { this.listComments(); } componentWillReceiveProps(nextProps) { if (this.props.commentsNumber !== nextProps.commentsNumber) { this.listComments(); } } render() { const onResizeMove = this.state.inResizing ? this.onResizeMouseMove : null; return (
}