1
0
mirror of https://github.com/haiwen/seahub.git synced 2025-08-15 21:53:37 +00:00
seahub/frontend/src/components/file-view/comment-widget/comment-item-readonly.js
Michael An 7ff4b52005
basic file support comment (#7731)
* basic file support comment

* 01 add init loading icon

* delete useless comment

* 02 delete comment tip

* update api validation

* 03 update API params

* 04 delete useless api

* 05 remove read all notification

* 06 change comment and reply permission

* 07 change docUuid to fileUuid

---------

Co-authored-by: r350178982 <32759763+r350178982@users.noreply.github.com>
2025-04-21 21:33:13 +08:00

100 lines
2.9 KiB
JavaScript

import React from 'react';
import PropTypes from 'prop-types';
import { processor } from '@seafile/seafile-editor';
const commentItemPropTypes = {
time: PropTypes.string,
item: PropTypes.object,
showResolvedComment: PropTypes.bool,
onClickComment: PropTypes.func,
};
class CommentItemReadOnly extends React.Component {
constructor(props) {
super(props);
this.state = {
html: '',
newComment: this.props.item.comment,
};
}
convertComment = (mdFile) => {
processor.process(mdFile).then((result) => {
let html = String(result);
this.setState({ html: html });
});
};
handleCommentChange = (event) => {
this.setState({
newComment: event.target.value,
});
};
componentWillMount() {
this.convertComment(this.props.item.comment);
}
componentWillReceiveProps(nextProps) {
this.convertComment(nextProps.item.comment);
}
onCommentContentClick = (e) => {
// click participant link, page shouldn't jump
if (e.target.nodeName !== 'A') return;
const preNode = e.target.previousSibling;
if (preNode && preNode.nodeType === 3 && preNode.nodeValue.slice(-1) === '@') {
e.preventDefault();
}
};
render() {
const item = this.props.item;
const replies = item.replies || [];
const lastReply = replies[replies.length - 1];
return (
<li className={'seafile-comment-item'} id={item.id} onClick={() => this.props.onClickComment(item)}>
<div className="seafile-comment-info">
<img className="avatar mt-1" src={item.avatar_url} alt=""/>
<div className="comment-author-info">
<div className="comment-author-name ellipsis">{item.user_name}</div>
<div className="comment-author-time">
{this.props.time}
{item.resolved &&
<span className="comment-success-resolved sdocfont sdoc-mark-as-resolved"></span>
}
</div>
</div>
</div>
<div
className="seafile-comment-content"
dangerouslySetInnerHTML={{ __html: this.state.html }}
onClick={e => this.onCommentContentClick(e)}
>
</div>
{replies.length > 0 &&
<div className="comment-footer">
<span className="comments-count">
<i className="sdocfont sdoc-comments"></i>
<span className="comments-count-number">{replies.length}</span>
</span>
<div className="comment-author">
<span className="comment-author__avatar">
<img alt="" src={lastReply.avatar_url}/>
</span>
<div className="comment-author__latest-reply">
<p>{lastReply.reply}</p>
</div>
</div>
</div>
}
</li>
);
}
}
CommentItemReadOnly.propTypes = commentItemPropTypes;
export default CommentItemReadOnly;