import * as React from 'react'; import { FormEvent } from 'react'; import NewComment from './NewComment'; import CommentList from './CommentList'; import Spinner from '../shared/Spinner'; import { DangerText, UppercaseText } from '../shared/CustomTexts'; import IComment from '../../interfaces/IComment'; import { CommentRepliesState } from '../../reducers/commentRepliesReducer'; interface Props { postId: number; authenticityToken: string; comments: Array; replies: Array; areLoading: boolean; error: string; requestComments(postId: number, page?: number): void; toggleCommentReply(commentId: number): void; setCommentReplyBody(commentId: number, body: string): void; submitComment( postId: number, body: string, parentId: number, authenticityToken: string, ): void; } class CommentsP extends React.Component { componentDidMount() { this.props.requestComments(this.props.postId); } _handleSubmitComment = (body, parentId) => { this.props.submitComment( this.props.postId, body, parentId, this.props.authenticityToken, ); } render() { const { comments, replies, areLoading, error, toggleCommentReply, setCommentReplyBody, submitComment, } = this.props; return (
reply.commentId === -1) && replies.find(reply => reply.commentId === -1).body} parentId={null} handleChange={ (e: FormEvent) => ( setCommentReplyBody(-1, (e.target as HTMLTextAreaElement).value) ) } handleSubmit={this._handleSubmitComment} /> { areLoading ? : null } { error ? {error} : null } activity • {comments.length} comments
); } } export default CommentsP;