123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172 |
- import React, { Component } from "react";
- import PropTypes from "prop-types";
- import Comment from "../../Comment";
-
- class CommentInput extends Component {
- constructor(props) {
- super(props);
- this.state = {};
- this.handleSubmit = this.handleSubmit.bind(this);
- }
-
- handleSubmit(value) {
- console.log("handleSubmit comment input value: ", value);
- const { action, commentId, replyId, callback } = this.props;
- console.log(" action, commentId, replyId, callback: ", this.props);
-
- if (action === "comment") {
- this.props.app.sCreateComment({
- content: value
- });
- } else if (action === "reply") {
- this.props.app.sCreateReply(
- {
- comment_id: commentId,
- content: value
- },
- () => callback && callback()
- );
- } else if (action === "replyToReply") {
- this.props.app.sCreateReply(
- {
- comment_id: commentId,
- content: value,
- reply_id: replyId
- },
- () => callback && callback()
- );
- }
- }
-
- render() {
- const childrenWithProps = React.Children.map(this.props.content, child => {
- return React.cloneElement(child, {
- // 默认使用 CommentInput 的 onSubmit 来提交评论
- // 但也可以使用 Editor 的 props 来覆盖 onSubmit
- onSubmit: this.handleSubmit,
- ...child.props,
- // 如果当前的编辑器不是“评论”,则编辑器高度减小一些
- rows:
- this.props.action === "comment"
- ? child.props.rows
- : child.props.rows - 1
- });
- });
-
- return <div>{childrenWithProps}</div>;
- }
- }
-
- CommentInput.propTypes = {
- // comment 评论
- // reply 评论的回复
- // replyToReply 回复的回复
- action: PropTypes.oneOf(["comment", "reply", "replyToReply"])
- };
-
- CommentInput.defaultProps = {
- action: "comment"
- };
-
- export default Comment(CommentInput);
|