2019-09-17 17:04:19 +02:00
|
|
|
import * as React from 'react';
|
2019-09-17 19:09:38 +02:00
|
|
|
import { FormEvent } from 'react';
|
2019-09-17 17:04:19 +02:00
|
|
|
|
2019-09-18 13:40:00 +02:00
|
|
|
import NewComment from './NewComment';
|
2019-09-17 17:04:19 +02:00
|
|
|
import { MutedText } from '../shared/CustomTexts';
|
|
|
|
|
|
2019-09-17 19:09:38 +02:00
|
|
|
import { CommentRepliesState } from '../../reducers/commentRepliesReducer';
|
|
|
|
|
|
2019-09-17 17:04:19 +02:00
|
|
|
interface Props {
|
|
|
|
|
id: number;
|
|
|
|
|
body: string;
|
|
|
|
|
parentId: number;
|
|
|
|
|
userFullName: string;
|
|
|
|
|
updatedAt: string;
|
|
|
|
|
|
|
|
|
|
level: number;
|
2019-09-17 19:09:38 +02:00
|
|
|
reply: CommentRepliesState;
|
|
|
|
|
handleToggleCommentReply(): void;
|
|
|
|
|
handleCommentReplyBodyChange(e: FormEvent): void;
|
2019-09-18 13:40:00 +02:00
|
|
|
handleSubmitComment(body: string, parentId: number): void;
|
2019-09-17 17:04:19 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const Comment = ({
|
|
|
|
|
id,
|
|
|
|
|
body,
|
|
|
|
|
parentId,
|
|
|
|
|
userFullName,
|
|
|
|
|
updatedAt,
|
|
|
|
|
|
|
|
|
|
level,
|
2019-09-17 19:09:38 +02:00
|
|
|
reply,
|
|
|
|
|
handleToggleCommentReply,
|
|
|
|
|
handleCommentReplyBodyChange,
|
2019-09-18 13:40:00 +02:00
|
|
|
handleSubmitComment,
|
2019-09-17 17:04:19 +02:00
|
|
|
}: Props) => (
|
|
|
|
|
<div className="comment">
|
|
|
|
|
<div className="commentHeader">
|
|
|
|
|
<span className="commentAuthor">{userFullName}</span>
|
|
|
|
|
</div>
|
|
|
|
|
<p className="commentBody">{body}</p>
|
|
|
|
|
<div className="commentFooter">
|
2019-09-18 17:00:58 +02:00
|
|
|
<a className="commentReplyButton" onClick={handleToggleCommentReply}>Reply</a>
|
2019-09-17 17:04:19 +02:00
|
|
|
<MutedText>{updatedAt}</MutedText>
|
|
|
|
|
</div>
|
2019-09-17 19:09:38 +02:00
|
|
|
{
|
|
|
|
|
reply.isOpen ?
|
2019-09-18 13:40:00 +02:00
|
|
|
<NewComment
|
|
|
|
|
body={reply.body}
|
|
|
|
|
parentId={id}
|
|
|
|
|
handleChange={handleCommentReplyBodyChange}
|
|
|
|
|
handleSubmit={handleSubmitComment}
|
2019-09-17 19:09:38 +02:00
|
|
|
/>
|
|
|
|
|
:
|
|
|
|
|
null
|
|
|
|
|
}
|
2019-09-17 17:04:19 +02:00
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
export default Comment;
|