2019-09-17 17:04:19 +02:00
|
|
|
import * as React from 'react';
|
|
|
|
|
|
|
|
|
|
import Comment from './Comment';
|
|
|
|
|
|
|
|
|
|
import IComment from '../../interfaces/IComment';
|
2019-09-26 18:22:18 +02:00
|
|
|
import { ReplyFormState } from '../../reducers/replyFormReducer';
|
2019-09-17 17:04:19 +02:00
|
|
|
|
|
|
|
|
interface Props {
|
|
|
|
|
comments: Array<IComment>;
|
2019-09-26 18:22:18 +02:00
|
|
|
replyForms: Array<ReplyFormState>;
|
2019-09-17 17:04:19 +02:00
|
|
|
parentId: number;
|
|
|
|
|
level: number;
|
2019-09-17 19:09:38 +02:00
|
|
|
|
2019-09-18 13:40:00 +02:00
|
|
|
toggleCommentReply(commentId: number): void;
|
|
|
|
|
setCommentReplyBody(commentId: number, body: string): void;
|
2019-10-02 16:43:13 +02:00
|
|
|
handleToggleIsCommentUpdate(commentId: number, currentIsPostUpdate: boolean): void;
|
2022-05-28 11:03:36 +02:00
|
|
|
handleSubmitComment(body: string, parentId: number, isPostUpdate: boolean): void;
|
2019-09-20 18:43:24 +02:00
|
|
|
|
|
|
|
|
isLoggedIn: boolean;
|
2019-09-25 11:50:23 +02:00
|
|
|
isPowerUser: boolean;
|
2019-10-02 15:26:32 +02:00
|
|
|
userEmail: string;
|
2019-09-17 17:04:19 +02:00
|
|
|
}
|
|
|
|
|
|
2019-09-17 19:09:38 +02:00
|
|
|
const CommentList = ({
|
|
|
|
|
comments,
|
2019-09-26 18:22:18 +02:00
|
|
|
replyForms,
|
2019-09-17 19:09:38 +02:00
|
|
|
parentId,
|
|
|
|
|
level,
|
|
|
|
|
|
|
|
|
|
toggleCommentReply,
|
|
|
|
|
setCommentReplyBody,
|
2019-10-02 16:43:13 +02:00
|
|
|
handleToggleIsCommentUpdate,
|
2019-09-18 13:40:00 +02:00
|
|
|
handleSubmitComment,
|
2019-09-20 18:43:24 +02:00
|
|
|
|
|
|
|
|
isLoggedIn,
|
2019-09-25 11:50:23 +02:00
|
|
|
isPowerUser,
|
2019-10-02 15:26:32 +02:00
|
|
|
userEmail,
|
2019-09-17 19:09:38 +02:00
|
|
|
}: Props) => (
|
2022-06-12 15:22:06 +02:00
|
|
|
<>
|
2019-09-17 17:04:19 +02:00
|
|
|
{comments.map((comment, i) => {
|
|
|
|
|
if (comment.parentId === parentId) {
|
|
|
|
|
return (
|
2019-09-18 13:40:00 +02:00
|
|
|
<div className="commentList" key={i}>
|
2019-09-17 19:09:38 +02:00
|
|
|
<Comment
|
2019-09-26 18:22:18 +02:00
|
|
|
replyForm={replyForms.find(replyForm => replyForm.commentId === comment.id)}
|
2019-09-17 19:09:38 +02:00
|
|
|
handleToggleCommentReply={() => toggleCommentReply(comment.id)}
|
|
|
|
|
handleCommentReplyBodyChange={
|
2019-09-26 11:00:32 +02:00
|
|
|
(e: React.FormEvent) => (
|
2019-09-17 19:09:38 +02:00
|
|
|
setCommentReplyBody(comment.id, (e.target as HTMLTextAreaElement).value)
|
|
|
|
|
)
|
|
|
|
|
}
|
2019-10-02 16:43:13 +02:00
|
|
|
handleToggleIsCommentUpdate={handleToggleIsCommentUpdate}
|
2019-09-18 13:40:00 +02:00
|
|
|
handleSubmitComment={handleSubmitComment}
|
2019-09-17 19:09:38 +02:00
|
|
|
{...comment}
|
2019-09-20 18:43:24 +02:00
|
|
|
|
|
|
|
|
isLoggedIn={isLoggedIn}
|
2019-09-25 11:50:23 +02:00
|
|
|
isPowerUser={isPowerUser}
|
2019-10-02 15:26:32 +02:00
|
|
|
currentUserEmail={userEmail}
|
2019-09-17 19:09:38 +02:00
|
|
|
/>
|
2019-09-17 17:04:19 +02:00
|
|
|
|
|
|
|
|
<CommentList
|
|
|
|
|
comments={comments}
|
2019-09-26 18:22:18 +02:00
|
|
|
replyForms={replyForms}
|
2019-09-17 17:04:19 +02:00
|
|
|
parentId={comment.id}
|
|
|
|
|
level={level+1}
|
2019-09-17 19:09:38 +02:00
|
|
|
|
|
|
|
|
toggleCommentReply={toggleCommentReply}
|
|
|
|
|
setCommentReplyBody={setCommentReplyBody}
|
2019-10-02 16:43:13 +02:00
|
|
|
handleToggleIsCommentUpdate={handleToggleIsCommentUpdate}
|
2019-09-18 13:40:00 +02:00
|
|
|
handleSubmitComment={handleSubmitComment}
|
2019-09-20 18:43:24 +02:00
|
|
|
|
|
|
|
|
isLoggedIn={isLoggedIn}
|
2019-09-25 11:50:23 +02:00
|
|
|
isPowerUser={isPowerUser}
|
2019-10-02 15:26:32 +02:00
|
|
|
userEmail={userEmail}
|
2019-09-17 17:04:19 +02:00
|
|
|
/>
|
|
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
} else return null;
|
|
|
|
|
})}
|
2022-06-12 15:22:06 +02:00
|
|
|
</>
|
2019-09-17 17:04:19 +02:00
|
|
|
);
|
|
|
|
|
|
|
|
|
|
export default CommentList;
|