Files
astuto/app/javascript/components/Comments/Comment.tsx
2019-09-30 23:28:52 +02:00

83 lines
2.0 KiB
TypeScript

import * as React from 'react';
import Gravatar from 'react-gravatar';
import NewComment from './NewComment';
import Separator from '../shared/Separator';
import { MutedText } from '../shared/CustomTexts';
import { ReplyFormState } from '../../reducers/replyFormReducer';
import friendlyDate from '../../helpers/friendlyDate';
interface Props {
id: number;
body: string;
userFullName: string;
userEmail: string;
updatedAt: string;
replyForm: ReplyFormState;
handleToggleCommentReply(): void;
handleCommentReplyBodyChange(e: React.FormEvent): void;
handleSubmitComment(body: string, parentId: number): void;
isLoggedIn: boolean;
isPowerUser: boolean;
}
const Comment = ({
id,
body,
userFullName,
userEmail,
updatedAt,
replyForm,
handleToggleCommentReply,
handleCommentReplyBodyChange,
handleSubmitComment,
isLoggedIn,
isPowerUser,
}: Props) => (
<div className="comment">
<div className="commentHeader">
<Gravatar email={userEmail} size={24} className="gravatar" />
<span className="commentAuthor">{userFullName}</span>
</div>
<p className="commentBody">{body}</p>
<div className="commentFooter">
<a className="commentReplyButton" onClick={handleToggleCommentReply}>
{ replyForm.isOpen ? 'Cancel' : 'Reply' }
</a>
{
isPowerUser ?
<React.Fragment>
<Separator />
<a href={`/admin/comments/${id}`} data-turbolinks="false">Edit</a>
</React.Fragment>
:
null
}
<Separator />
<MutedText>{friendlyDate(updatedAt)}</MutedText>
</div>
{
replyForm.isOpen ?
<NewComment
body={replyForm.body}
parentId={id}
isSubmitting={replyForm.isSubmitting}
error={replyForm.error}
handleChange={handleCommentReplyBodyChange}
handleSubmit={handleSubmitComment}
isLoggedIn={isLoggedIn}
/>
:
null
}
</div>
);
export default Comment;