import * as React from 'react'; import Comment from './Comment'; import IComment from '../../interfaces/IComment'; import { ReplyFormState } from '../../reducers/replyFormReducer'; interface Props { comments: Array; replyForms: Array; parentId: number; level: number; toggleCommentReply(commentId: number): void; setCommentReplyBody(commentId: number, body: string): void; handleSubmitComment(body: string, parentId: number, isPostUpdate: boolean): void; handleUpdateComment(commentId: number, body: string, isPostUpdate: boolean, onSuccess: Function): void; handleDeleteComment(id: number): void; isLoggedIn: boolean; isPowerUser: boolean; userEmail: string; } const CommentList = ({ comments, replyForms, parentId, level, toggleCommentReply, setCommentReplyBody, handleSubmitComment, handleUpdateComment, handleDeleteComment, isLoggedIn, isPowerUser, userEmail, }: Props) => ( <> {comments.map((comment, i) => { if (comment.parentId === parentId) { return (
replyForm.commentId === comment.id)} handleToggleCommentReply={() => toggleCommentReply(comment.id)} handleCommentReplyBodyChange={ (e: React.FormEvent) => ( setCommentReplyBody(comment.id, (e.target as HTMLTextAreaElement).value) ) } handleSubmitComment={handleSubmitComment} handleUpdateComment={handleUpdateComment} handleDeleteComment={handleDeleteComment} {...comment} isLoggedIn={isLoggedIn} isPowerUser={isPowerUser} currentUserEmail={userEmail} />
); } else return null; })} ); export default CommentList;