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

83 lines
1.9 KiB
TypeScript
Raw Normal View History

2019-09-17 17:04:19 +02:00
import * as React from 'react';
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-25 11:50:23 +02:00
import Separator from '../shared/Separator';
2019-09-17 17:04:19 +02:00
import { MutedText } from '../shared/CustomTexts';
import { CommentRepliesState } from '../../reducers/commentRepliesReducer';
import friendlyDate from '../../helpers/friendlyDate';
2019-09-17 17:04:19 +02:00
interface Props {
id: number;
body: string;
parentId: number;
userFullName: string;
updatedAt: string;
level: number;
reply: CommentRepliesState;
handleToggleCommentReply(): void;
handleCommentReplyBodyChange(e: FormEvent): void;
2019-09-18 13:40:00 +02:00
handleSubmitComment(body: string, parentId: number): void;
2019-09-20 18:43:24 +02:00
isLoggedIn: boolean;
2019-09-25 11:50:23 +02:00
isPowerUser: boolean;
2019-09-17 17:04:19 +02:00
}
const Comment = ({
id,
body,
parentId,
userFullName,
updatedAt,
level,
reply,
handleToggleCommentReply,
handleCommentReplyBodyChange,
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-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">
<a className="commentReplyButton" onClick={handleToggleCommentReply}>
{ reply.isOpen ? 'Cancel' : 'Reply' }
</a>
2019-09-25 11:50:23 +02:00
{
isPowerUser ?
<React.Fragment>
<Separator />
<a href={`/admin/comments/${id}`} data-turbolinks="false">Edit</a>
</React.Fragment>
:
null
}
<Separator />
<MutedText>{friendlyDate(updatedAt)}</MutedText>
2019-09-17 17:04:19 +02:00
</div>
{
reply.isOpen ?
2019-09-18 13:40:00 +02:00
<NewComment
body={reply.body}
parentId={id}
2019-09-20 18:43:24 +02:00
isSubmitting={reply.isSubmitting}
2019-09-18 13:40:00 +02:00
handleChange={handleCommentReplyBodyChange}
handleSubmit={handleSubmitComment}
2019-09-20 18:43:24 +02:00
isLoggedIn={isLoggedIn}
/>
:
null
}
2019-09-17 17:04:19 +02:00
</div>
);
export default Comment;