import { Component, linkEvent } from 'inferno'; import { CommentNode as CommentNodeI, CommentForm as CommentFormI } from '../interfaces'; import { WebSocketService } from '../services'; import * as autosize from 'autosize'; interface CommentFormProps { postId?: number; node?: CommentNodeI; onReplyCancel?(): any; edit?: boolean; } interface CommentFormState { commentForm: CommentFormI; buttonTitle: string; } export class CommentForm extends Component { private emptyState: CommentFormState = { commentForm: { auth: null, content: null, post_id: this.props.node ? this.props.node.comment.post_id : this.props.postId }, buttonTitle: !this.props.node ? "Post" : this.props.edit ? "Edit" : "Reply" } constructor(props: any, context: any) { super(props, context); this.state = this.emptyState; if (this.props.node) { if (this.props.edit) { this.state.commentForm.edit_id = this.props.node.comment.id; this.state.commentForm.parent_id = this.props.node.comment.parent_id; this.state.commentForm.content = this.props.node.comment.content; } else { // A reply gets a new parent id this.state.commentForm.parent_id = this.props.node.comment.id; } } } componentDidMount() { autosize(document.querySelectorAll('textarea')); } render() { return (