1
0
mirror of https://github.com/haiwen/seahub.git synced 2025-09-11 11:51:27 +00:00

Add comment and participant (#3882)

* update handle error

* comment and add participant

* update nextProps
This commit is contained in:
Michael An
2019-07-22 16:34:25 +08:00
committed by Daniel Pan
parent 2598cd433e
commit fc56ae5cec
3 changed files with 67 additions and 17 deletions

View File

@@ -5,6 +5,7 @@ import { gettext } from '../../utils/constants';
import { seafileAPI } from '../../utils/seafile-api'; import { seafileAPI } from '../../utils/seafile-api';
import UserSelect from '../user-select'; import UserSelect from '../user-select';
import toaster from '../toast'; import toaster from '../toast';
import { Utils } from '../../utils/utils';
import '../../css/participants-list.css'; import '../../css/participants-list.css';
const fileParticipantListItemPropTypes = { const fileParticipantListItemPropTypes = {
@@ -75,8 +76,9 @@ class FileParticipantDialog extends Component {
const { repoID, filePath } = this.props; const { repoID, filePath } = this.props;
seafileAPI.deleteFileParticipant(repoID, filePath, email).then((res) => { seafileAPI.deleteFileParticipant(repoID, filePath, email).then((res) => {
this.props.onParticipantsChange(repoID, filePath); this.props.onParticipantsChange(repoID, filePath);
}).catch((error) => { }).catch(error => {
this.handleError(error); let errMessage = Utils.getErrorMsg(error);
toaster.danger(errMessage);
}); });
this.refs.userSelect.clearSelect(); this.refs.userSelect.clearSelect();
}; };
@@ -90,22 +92,15 @@ class FileParticipantDialog extends Component {
for (let i = 0; i < selectedOption.length; i++) { for (let i = 0; i < selectedOption.length; i++) {
seafileAPI.addFileParticipant(repoID, filePath, selectedOption[i].email).then((res) => { seafileAPI.addFileParticipant(repoID, filePath, selectedOption[i].email).then((res) => {
this.props.onParticipantsChange(repoID, filePath); this.props.onParticipantsChange(repoID, filePath);
}).catch((error) => { }).catch(error => {
this.handleError(error); let errMessage = Utils.getErrorMsg(error);
toaster.danger(errMessage);
}); });
} }
this.setState({ selectedOption: null }); this.setState({ selectedOption: null });
this.refs.userSelect.clearSelect(); this.refs.userSelect.clearSelect();
}; };
handleError = (e) => {
if (e.response) {
toaster.danger(e.response.data.error_msg || e.response.data.detail || gettext('Error'), {duration: 3});
} else {
toaster.danger(gettext('Please check the network.'), {duration: 3});
}
};
render() { render() {
const renderParticipantList = this.props.fileParticipantList.map((participant, index) => { const renderParticipantList = this.props.fileParticipantList.map((participant, index) => {
return ( return (

View File

@@ -3,15 +3,13 @@ import PropTypes from 'prop-types';
import moment from 'moment'; import moment from 'moment';
import { processor } from '@seafile/seafile-editor/dist/utils/seafile-markdown2html'; import { processor } from '@seafile/seafile-editor/dist/utils/seafile-markdown2html';
import { Button, Dropdown, DropdownToggle, DropdownMenu, DropdownItem } from 'reactstrap'; import { Button, Dropdown, DropdownToggle, DropdownMenu, DropdownItem } from 'reactstrap';
import { gettext } from '../../utils/constants'; import { gettext, username } from '../../utils/constants';
import { seafileAPI } from '../../utils/seafile-api'; import { seafileAPI } from '../../utils/seafile-api';
import { Utils } from '../../utils/utils'; import { Utils } from '../../utils/utils';
import toaster from '../toast'; import toaster from '../toast';
import ParticipantsList from '../file-view/participants-list'; import ParticipantsList from '../file-view/participants-list';
import '../../css/comments-list.css'; import '../../css/comments-list.css';
const { username } = window.app.pageOptions;
const DetailCommentListPropTypes = { const DetailCommentListPropTypes = {
repoID: PropTypes.string.isRequired, repoID: PropTypes.string.isRequired,
filePath: PropTypes.string.isRequired, filePath: PropTypes.string.isRequired,
@@ -26,10 +24,12 @@ class DetailCommentList extends React.Component {
this.state = { this.state = {
commentsList: [], commentsList: [],
}; };
this.isParticipant = false;
} }
componentDidMount() { componentDidMount() {
this.listComments(); this.listComments();
this.checkParticipant();
} }
componentWillReceiveProps(nextProps) { componentWillReceiveProps(nextProps) {
@@ -38,6 +38,17 @@ class DetailCommentList extends React.Component {
} }
} }
checkParticipant = () => {
const fileParticipantList = this.props.fileParticipantList;
if (fileParticipantList.length === 0) {
this.isParticipant = false;
} else {
this.isParticipant = fileParticipantList.some((participant) => {
return participant.email === username;
});
}
}
listComments = (filePath) => { listComments = (filePath) => {
seafileAPI.listComments(this.props.repoID, (filePath || this.props.filePath)).then((res) => { seafileAPI.listComments(this.props.repoID, (filePath || this.props.filePath)).then((res) => {
this.setState({ commentsList: res.data.comments }); this.setState({ commentsList: res.data.comments });
@@ -61,10 +72,23 @@ class DetailCommentList extends React.Component {
let errMessage = Utils.getErrorMsg(error); let errMessage = Utils.getErrorMsg(error);
toaster.danger(errMessage); toaster.danger(errMessage);
}); });
this.addParticipant();
} }
this.refs.commentTextarea.value = ''; this.refs.commentTextarea.value = '';
} }
addParticipant = () => {
const { repoID, filePath } = this.props;
if (this.isParticipant) return;
seafileAPI.addFileParticipant(repoID, filePath, username).then((res) => {
this.isParticipant = true;
this.props.onParticipantsChange(repoID, filePath);
}).catch((err) => {
let errMessage = Utils.getErrorMsg(err);
toaster.danger(errMessage);
});
}
resolveComment = (event) => { resolveComment = (event) => {
const { repoID } = this.props; const { repoID } = this.props;
seafileAPI.updateComment(repoID, event.target.id, 'true').then(() => { seafileAPI.updateComment(repoID, event.target.id, 'true').then(() => {

View File

@@ -28,6 +28,7 @@ class CommentPanel extends React.Component {
showResolvedComment: true, showResolvedComment: true,
participants: null, participants: null,
}; };
this.isParticipant = false;
} }
toggleResolvedComment = () => { toggleResolvedComment = () => {
@@ -62,10 +63,22 @@ class CommentPanel extends React.Component {
let errMessage = Utils.getErrorMsg(error); let errMessage = Utils.getErrorMsg(error);
toaster.danger(errMessage); toaster.danger(errMessage);
}); });
this.addParticipant();
} }
this.refs.commentTextarea.value = ''; this.refs.commentTextarea.value = '';
} }
addParticipant = () => {
if (this.isParticipant) return;
seafileAPI.addFileParticipant(repoID, filePath, username).then((res) => {
this.isParticipant = true;
this.onParticipantsChange(repoID, filePath);
}).catch((err) => {
let errMessage = Utils.getErrorMsg(err);
toaster.danger(errMessage);
});
}
resolveComment = (event) => { resolveComment = (event) => {
seafileAPI.updateComment(repoID, event.target.id, 'true').then(() => { seafileAPI.updateComment(repoID, event.target.id, 'true').then(() => {
this.listComments(); this.listComments();
@@ -103,10 +116,25 @@ class CommentPanel extends React.Component {
getParticipants = () => { getParticipants = () => {
if (this.props.participants) { if (this.props.participants) {
this.setState({ participants: this.props.participants }); this.setState({ participants: this.props.participants }, () => {
this.checkParticipant();
});
} else { } else {
seafileAPI.listFileParticipants(repoID, filePath).then((res) => { seafileAPI.listFileParticipants(repoID, filePath).then((res) => {
this.setState({ participants: res.data.participant_list }); this.setState({ participants: res.data.participant_list }, () => {
this.checkParticipant();
});
});
}
}
checkParticipant = () => {
const participants = this.state.participants;
if (participants.length === 0) {
this.isParticipant = false;
} else {
this.isParticipant = participants.some((participant) => {
return participant.email === username;
}); });
} }
} }
@@ -120,6 +148,9 @@ class CommentPanel extends React.Component {
if (this.props.commentsNumber !== nextProps.commentsNumber) { if (this.props.commentsNumber !== nextProps.commentsNumber) {
this.listComments(); this.listComments();
} }
if (this.props.participants !== nextProps.participants) {
this.setState({ participants: nextProps.participants });
}
} }
render() { render() {