diff --git a/frontend/src/components/review-list-view/review-comments.js b/frontend/src/components/review-list-view/review-comments.js index 9594ab8dad..9aa9ba9b14 100644 --- a/frontend/src/components/review-list-view/review-comments.js +++ b/frontend/src/components/review-list-view/review-comments.js @@ -5,15 +5,14 @@ import { Button, Dropdown, DropdownToggle, DropdownMenu, DropdownItem } from 're import { seafileAPI } from '../../utils/seafile-api'; import { gettext, draftFilePath, draftRepoID } from '../../utils/constants'; import Loading from '../../components/loading.js'; -import reviewComment from '../../models/review-comment.js'; import { username } from '../../utils/constants.js'; import '../../css/review-comments.css'; const commentPropTypes = { - getCommentsNumber: PropTypes.func.isRequired, + listComments: PropTypes.func.isRequired, inResizing: PropTypes.bool.isRequired, - commentsNumber: PropTypes.number, + commentsList: PropTypes.array.isRequired, scrollToQuote: PropTypes.func.isRequired }; @@ -22,7 +21,6 @@ class ReviewComments extends React.Component { constructor(props) { super(props); this.state = { - commentsList: [], inResizing: false, commentFooterHeight: 25, showResolvedComment: true, @@ -30,23 +28,6 @@ class ReviewComments extends React.Component { }; } - listComments = (scroll) => { - seafileAPI.listComments(draftRepoID, draftFilePath).then((response) => { - let commentList = []; - response.data.comments.forEach(item => { - let commentItem = new reviewComment(item); - commentList.push(commentItem); - }); - this.setState({ commentsList: commentList }); - if (scroll) { - let that = this; - setTimeout(() => { - that.refs.commentsList.scrollTo(0, 10000); - }, 100); - } - }); - } - handleCommentChange = (event) => { this.setState({ comment: event.target.value }); } @@ -54,9 +35,8 @@ class ReviewComments extends React.Component { submitComment = () => { let comment = this.state.comment.trim(); if (comment.length > 0) { - seafileAPI.postComment(draftRepoID, draftFilePath, comment).then(() => { - this.listComments(true); - this.props.getCommentsNumber(); + seafileAPI.postComment(draftRepoID, draftFilePath, comment).then(() => { + this.props.listComments(); }); this.setState({ comment: '' }); } @@ -64,15 +44,13 @@ class ReviewComments extends React.Component { resolveComment = (event) => { seafileAPI.updateComment(draftRepoID, event.target.id, 'true').then((res) => { - this.props.getCommentsNumber(); - this.listComments(); + this.props.listComments(); }); } editComment = (commentID, newComment) => { seafileAPI.updateComment(draftRepoID, commentID, null, null, newComment).then((res) => { - this.props.getCommentsNumber(); - this.listComments(); + this.props.listComments(); }); } @@ -82,8 +60,7 @@ class ReviewComments extends React.Component { deleteComment = (event) => { seafileAPI.deleteComment(draftRepoID, event.target.id).then((res) => { - this.props.getCommentsNumber(); - this.listComments(); + this.props.listComments(); }); } @@ -117,20 +94,18 @@ class ReviewComments extends React.Component { this.setState({ comment: '' }); } - componentWillMount() { - this.listComments(); - } - componentWillReceiveProps(nextProps) { - if (this.props.commentsNumber !== nextProps.commentsNumber) { - this.listComments(); + if (this.props.commentsList.length < nextProps.commentsList.length) { + let that = this; + setTimeout(() => { + that.refs.commentsList.scrollTo(0, 10000); + }, 100); } } render() { const onResizeMove = this.state.inResizing ? this.onResizeMouseMove : null; - const { commentsNumber } = this.props; - const { commentsList } = this.state; + const { commentsList } = this.props; return (
- {commentsNumber == 0 && + {commentsList.length === 0 &&
{gettext('No comment yet.')}
} - {(commentsList.length === 0 && commentsNumber > 0) && -
- } - {commentsList.length > 0 && - - } +
@@ -186,9 +156,7 @@ class ReviewComments extends React.Component { onChange={this.handleCommentChange} clos="100" rows="3" warp="virtual" > - +
diff --git a/frontend/src/draft.js b/frontend/src/draft.js index 882e2d4e9a..c62e17dffb 100644 --- a/frontend/src/draft.js +++ b/frontend/src/draft.js @@ -21,6 +21,7 @@ import classnames from 'classnames'; import HistoryList from './pages/review/history-list'; import { Value, Document, Block } from 'slate'; import ModalPortal from './components/modal-portal'; +import reviewComment from './models/review-comment.js'; import './assets/css/fa-solid.css'; import './assets/css/fa-regular.css'; @@ -45,11 +46,10 @@ class Draft extends React.Component { isShowDiff: true, showDiffTip: false, activeTab: 'reviewInfo', - commentsNumber: null, + commentsList: [], changedNodes: [], originRepoName: '', isShowCommentDialog: false, - unresolvedComments: 0, activeItem: null, historyList: [], showReviewerDialog: false, @@ -196,25 +196,16 @@ class Draft extends React.Component { } onHistoryListChange = (historyList) => { - this.setState({ - historyList: historyList - }); + this.setState({historyList: historyList }); } - getCommentsNumber = () => { + listComments = () => { seafileAPI.listComments(draftRepoID, draftFilePath).then((res) => { - let number = res.data.total_count; - let comments = res.data.comments; - let unresolvedComments = 0; - for (let i = 0; i < res.data.total_count; i++) { - if (comments[i].resolved === false) { - unresolvedComments++; - } - } - this.setState({ - commentsNumber: number, - unresolvedComments: unresolvedComments, + let commentsList = []; + res.data.comments.forEach((item) => { + commentsList.push(new reviewComment(item)); }); + this.setState({ commentsList: commentsList }); }); } @@ -226,7 +217,7 @@ class Draft extends React.Component { } onCommentAdded = () => { - this.getCommentsNumber(); + this.listComments(); this.toggleCommentDialog(); } @@ -238,9 +229,7 @@ class Draft extends React.Component { getOriginRepoInfo = () => { seafileAPI.getRepoInfo(draftRepoID).then((res) => { - this.setState({ - originRepoName: res.data.repo_name - }); + this.setState({ originRepoName: res.data.repo_name }); }); } @@ -488,6 +477,7 @@ class Draft extends React.Component { } showNavItem = (showTab) => { + const commentsNumber = this.state.commentsList.length; switch(showTab) { case 'info': return ( @@ -508,7 +498,7 @@ class Draft extends React.Component { onClick={() => {this.tabItemClick('comments');}} > - {this.state.commentsNumber > 0 &&
{this.state.commentsNumber}
} + {commentsNumber > 0 &&
{commentsNumber}
} ); @@ -662,14 +652,11 @@ class Draft extends React.Component { this.setState({ rightPartWidth: rate }); }; - componentWillMount() { - this.getCommentsNumber(); - this.listReviewers(); + componentDidMount() { this.getOriginRepoInfo(); this.getDraftInfo(); - } - - componentDidMount() { + this.listReviewers(); + this.listComments(); this.initialContent(); document.addEventListener('selectionchange', this.setBtnPosition); } @@ -744,12 +731,13 @@ class Draft extends React.Component { } render() { + const { draftInfo, reviewers, originRepoName } = this.state; const onResizeMove = this.state.inResizing ? this.onResizeMouseMove : null; const draftLink = siteRoot + 'lib/' + draftRepoID + '/file' + draftFilePath + '?mode=edit'; const freezePublish = (this.state.freezePublish || draftStatus === 'published') ? true : false; const canPublish = !this.state.freezePublish && draftFileExists && filePermission == 'rw'; - const time = moment(this.state.draftInfo.mtime * 1000).format('YYYY-MM-DD HH:mm'); - const url = `${siteRoot}profile/${encodeURIComponent(this.state.draftInfo.last_modifier_email)}/`; + const time = moment(draftInfo.mtime * 1000).format('YYYY-MM-DD HH:mm'); + const url = `${siteRoot}profile/${encodeURIComponent(draftInfo.last_modifier_email)}/`; return(
- {(!freezePublish && this.state.draftInfo.mtime) && + {(!freezePublish && draftInfo.mtime) &&
- {this.state.draftInfo.last_modifier_name}{time} + {draftInfo.last_modifier_name}{time}
}
@@ -777,20 +765,12 @@ class Draft extends React.Component { } {canPublish && - } {freezePublish && - } @@ -817,25 +797,23 @@ class Draft extends React.Component {
- {draftFileExists && - - } + {draftFileExists && } {(this.state.isShowDiff === true && this.state.changedNodes.length > 0) && } - +
@@ -859,7 +837,7 @@ class Draft extends React.Component { showReviewerDialog={this.state.showReviewerDialog} toggleAddReviewerDialog={this.toggleAddReviewerDialog} draftID={draftID} - reviewers={this.state.reviewers} + reviewers={reviewers} /> } @@ -967,11 +945,20 @@ class UnresolvedComments extends React.Component { } render() { + const { commentsList } = this.props; + let unresolvedNumber = 0; + if (commentsList) { + for (let i = 0, count = commentsList.length; i < count; i++) { + if (commentsList[i].resolved === false) { + unresolvedNumber++; + } + } + } return (
{gettext('Comments')}
- {gettext('Unresolved comments:')}{' '}{this.props.number} + {gettext('Unresolved comments:')}{' '}{unresolvedNumber}
); @@ -979,7 +966,7 @@ class UnresolvedComments extends React.Component { } const UnresolvedCommentsPropTypes = { - number: PropTypes.number.isRequired + commentsList: PropTypes.array.isRequired, }; UnresolvedComments.propTypes = UnresolvedCommentsPropTypes;