import * as React from 'react'; import { FormEvent } from 'react'; import Comment from './Comment'; import IComment from '../../interfaces/IComment'; import { CommentRepliesState } from '../../reducers/commentRepliesReducer'; interface Props { comments: Array; replies: Array; parentId: number; level: number; toggleCommentReply(commentId: number): void; setCommentReplyBody(commentId: number, body: string): void; handleSubmitComment(body: string, parentId: number): void; } const CommentList = ({ comments, replies, parentId, level, toggleCommentReply, setCommentReplyBody, handleSubmitComment, }: Props) => ( {comments.map((comment, i) => { if (comment.parentId === parentId) { return (
reply.commentId === comment.id)} handleToggleCommentReply={() => toggleCommentReply(comment.id)} handleCommentReplyBodyChange={ (e: FormEvent) => ( setCommentReplyBody(comment.id, (e.target as HTMLTextAreaElement).value) ) } handleSubmitComment={handleSubmitComment} {...comment} />
); } else return null; })}
); export default CommentList;