import React from 'react'; import PropTypes from 'prop-types'; import { processor } from '@seafile/seafile-editor'; import { Button, Dropdown, DropdownToggle, DropdownMenu, DropdownItem } from 'reactstrap'; import { gettext } from '../../../utils/constants'; import CommentDeletePopover from './comment-delete-popover'; const { username } = window.app.pageOptions; const commentItemPropTypes = { time: PropTypes.string, item: PropTypes.object, deleteReply: PropTypes.func, showResolvedComment: PropTypes.bool, editComment: PropTypes.func, }; class ReplyItem extends React.Component { constructor(props) { super(props); this.state = { dropdownOpen: false, html: '', newReply: this.props.item.reply, editable: false, isShowDeletePopover: false, }; } componentWillMount() { this.convertComment(this.props.item.reply); } componentWillReceiveProps(nextProps) { this.convertComment(nextProps.item.reply); } toggleDropDownMenu = () => { this.setState({ dropdownOpen: !this.state.dropdownOpen, }); }; convertComment = (mdFile) => { processor.process(mdFile).then((result) => { let html = String(result); this.setState({ html: html }); }); }; toggleEditComment = () => { this.setState({ editable: !this.state.editable }); }; updateComment = () => { const newReply = this.state.newReply.trim(); if (this.props.item.reply !== newReply) { this.props.updateReply(newReply); } this.toggleEditComment(); }; handleCommentChange = (event) => { this.setState({ newReply: event.target.value, }); }; 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(); } }; toggleShowDeletePopover = () => { this.setState({ isShowDeletePopover: !this.state.isShowDeletePopover }); }; render() { const item = this.props.item; const replyOpToolsId = `commentOpTools_${item?.id}`; if (this.state.editable) { return (
  • {item.user_name}
    {this.props.time}
    {' '}
  • ); } return (
  • {item.user_name}
    {this.props.time}
    {(item.user_email === username) && {gettext('Delete')} {gettext('Edit')} }
    this.onCommentContentClick(e)} >
    {this.state.isShowDeletePopover && ( )}
  • ); } } ReplyItem.propTypes = commentItemPropTypes; export default ReplyItem;