import React, { Component } from "react"; import PropTypes from "prop-types"; import { Avatar, Icon } from "antd"; import dayjs from "dayjs"; import Comment from "../../Comment"; import CommentInput from "../CommentInput"; import { renderContent } from "../../helper"; import "./index.css"; class CommentItem extends Component { constructor(props) { super(props); this.state = { isShowInput: false }; this.handleToggleInput = this.handleToggleInput.bind(this); this.renderTextWithReply = this.renderTextWithReply.bind(this); } handleToggleInput() { this.setState({ isShowInput: !this.state.isShowInput }); } renderTextWithReply(text, content) { let newText = text; const { reply } = content; if (reply) { newText = `${newText} //@${ reply.user_name } ${reply.content}`; if (reply.reply) { return this.renderTextWithReply(newText, reply); } } return newText; } render() { const { commentId, replyId, content, type, showReply, onShowReply, app } = this.props; const { isShowInput } = this.state; const isComment = type === "comment"; return (
{content.user_name || "暂无昵称"} {dayjs(content.created * 1000).format("YYYY-MM-DD HH:mm:ss")}
{isComment && content.reply_count ? (
{content.reply_count} 条回复 {showReply ? : }
) : null}   回复
app.sCommentFavor(content.id, content.favored)} >  {content.favor_count}
{isShowInput ? ( ) : null}
); } } CommentItem.propTypes = { content: PropTypes.object.isRequired, // comment 评论 // reply 回复 type: PropTypes.oneOf(["comment", "reply"]), onShowReply: PropTypes.func }; CommentItem.defaultProps = { type: "comment", onShowReply: () => {} }; export default Comment(CommentItem);