Files
astuto/app/javascript/components/Comments/CommentList.tsx

100 lines
2.9 KiB
TypeScript
Raw Permalink Normal View History

2019-09-17 17:04:19 +02:00
import * as React from 'react';
import Comment from './Comment';
import IComment from '../../interfaces/IComment';
import { ReplyFormState } from '../../reducers/replyFormReducer';
import ITenantSetting from '../../interfaces/ITenantSetting';
2019-09-17 17:04:19 +02:00
interface Props {
comments: Array<IComment>;
replyForms: Array<ReplyFormState>;
2019-09-17 17:04:19 +02:00
parentId: number;
level: number;
2019-09-18 13:40:00 +02:00
toggleCommentReply(commentId: number): void;
setCommentReplyBody(commentId: number, body: string): void;
handleSubmitComment(body: string, parentId: number, isPostUpdate: boolean, attachments: File[], onSuccess: Function): void;
2025-02-05 22:53:22 +01:00
handleUpdateComment(commentId: number, body: string, isPostUpdate: boolean, attachmentsToDelete: number[], attachments: File[], onSuccess: Function): void;
handleDeleteComment(id: number): void;
2019-09-20 18:43:24 +02:00
tenantSetting: ITenantSetting;
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;
userAvatar?: string;
2019-09-17 17:04:19 +02:00
}
const CommentList = ({
comments,
replyForms,
parentId,
level,
toggleCommentReply,
setCommentReplyBody,
2019-09-18 13:40:00 +02:00
handleSubmitComment,
handleUpdateComment,
handleDeleteComment,
2019-09-20 18:43:24 +02:00
tenantSetting,
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,
userAvatar,
}: Props) => (
<>
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}>
<Comment
replyForm={replyForms.find(replyForm => replyForm.commentId === comment.id)}
handleToggleCommentReply={() => toggleCommentReply(comment.id)}
handleCommentReplyBodyChange={
(e: React.FormEvent) => (
setCommentReplyBody(comment.id, (e.target as HTMLTextAreaElement).value)
)
}
2019-09-18 13:40:00 +02:00
handleSubmitComment={handleSubmitComment}
handleUpdateComment={handleUpdateComment}
handleDeleteComment={handleDeleteComment}
{...comment}
2019-09-20 18:43:24 +02:00
tenantSetting={tenantSetting}
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}
currentUserAvatar={userAvatar}
/>
2019-09-17 17:04:19 +02:00
<CommentList
comments={comments}
replyForms={replyForms}
2019-09-17 17:04:19 +02:00
parentId={comment.id}
level={level+1}
toggleCommentReply={toggleCommentReply}
setCommentReplyBody={setCommentReplyBody}
2019-09-18 13:40:00 +02:00
handleSubmitComment={handleSubmitComment}
handleUpdateComment={handleUpdateComment}
handleDeleteComment={handleDeleteComment}
2019-09-20 18:43:24 +02:00
tenantSetting={tenantSetting}
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}
userAvatar={userAvatar}
2019-09-17 17:04:19 +02:00
/>
</div>
);
} else return null;
})}
</>
2019-09-17 17:04:19 +02:00
);
export default CommentList;