1
0
mirror of https://github.com/haiwen/seahub.git synced 2025-09-12 04:10:47 +00:00
Files
seahub/frontend/src/components/review-list-view/review-comment-dialog.js

102 lines
2.8 KiB
JavaScript
Raw Normal View History

2018-11-28 17:03:44 +08:00
import React from 'react';
import PropTypes from 'prop-types';
import { Button } from 'reactstrap';
import { seafileAPI } from '../../utils/seafile-api';
import { gettext, name, draftRepoID, draftFilePath } from '../../utils/constants';
2018-12-08 12:13:02 +08:00
import { processor } from '../../utils/seafile-markdown2html';
2018-11-28 17:03:44 +08:00
import '../../css/review-comment-dialog.css';
const commentDialogPropTypes = {
onCommentAdded: PropTypes.func.isRequired,
toggleCommentDialog: PropTypes.func.isRequired,
2018-12-08 12:13:02 +08:00
quote: PropTypes.string,
2018-11-28 17:03:44 +08:00
newIndex: PropTypes.number,
oldIndex: PropTypes.number,
draftID: PropTypes.string,
2018-11-28 17:03:44 +08:00
};
class ReviewCommentDialog extends React.Component {
constructor(props) {
super(props);
this.state = {
comment: '',
2018-12-08 12:13:02 +08:00
quote: '',
2018-11-28 17:03:44 +08:00
};
}
handleCommentChange = (event) => {
let comment = event.target.value;
this.setState({
comment: comment
});
}
submitComment = () => {
let comment = this.state.comment.trim();
if (comment.length > 0) {
2018-12-08 12:13:02 +08:00
if (this.props.quote.length > 0) {
2018-11-28 17:03:44 +08:00
let detail = {
2018-12-08 12:13:02 +08:00
quote: this.props.quote,
2018-11-28 17:03:44 +08:00
newIndex: this.props.newIndex,
oldIndex: this.props.oldIndex
};
let detailJSON = JSON.stringify(detail);
seafileAPI.postComment(draftRepoID, draftFilePath, comment, detailJSON).then((response) => {
2018-11-28 17:03:44 +08:00
this.props.onCommentAdded();
});
}
else {
seafileAPI.postComment(draftRepoID, draftFilePath, comment).then((response) => {
2018-11-28 17:03:44 +08:00
this.props.onCommentAdded();
});
}
this.setState({
comment: ''
});
}
}
2018-12-08 12:13:02 +08:00
setQuoteText = (mdQuote) => {
processor.process(mdQuote).then(
(result) => {
let quote = String(result);
this.setState({
quote: quote
});
}
);
2018-11-28 17:03:44 +08:00
}
componentDidMount() {
2018-12-08 12:13:02 +08:00
this.setQuoteText(this.props.quote);
2018-11-28 17:03:44 +08:00
}
componentWillReceiveProps(nextProps) {
2018-12-08 12:13:02 +08:00
if (this.props.quote !== nextProps.quote) {
this.setQuoteText(nextProps.quote);
2018-11-28 17:03:44 +08:00
}
}
render() {
return (
2018-12-06 17:56:31 +08:00
<div className="review-comment-dialog">
2018-12-26 13:54:54 +08:00
<div>{name}</div>
2018-12-08 12:13:02 +08:00
<blockquote className="review-comment-dialog-quote">
<div dangerouslySetInnerHTML={{ __html: this.state.quote}}></div>
</blockquote>
2018-11-28 17:03:44 +08:00
<textarea value={this.state.comment} onChange={this.handleCommentChange}></textarea>
<div className="button-group">
<Button size="sm" color="primary" onClick={this.submitComment}>{gettext('Submit')}</Button>
<Button size="sm" color="secondary" onClick={this.props.toggleCommentDialog}>{gettext('Cancel')}</Button>
2018-11-28 17:03:44 +08:00
</div>
<span className="review-comment-dialog-triangle"></span>
</div>
);
}
}
ReviewCommentDialog.propTypes = commentDialogPropTypes;
export default ReviewCommentDialog;