2019-09-17 17:04:19 +02:00
|
|
|
import * as React from 'react';
|
2019-09-30 23:28:52 +02:00
|
|
|
import Gravatar from 'react-gravatar';
|
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';
|
|
|
|
|
|
2019-09-26 18:22:18 +02:00
|
|
|
import { ReplyFormState } from '../../reducers/replyFormReducer';
|
2019-09-17 19:09:38 +02:00
|
|
|
|
2019-09-20 17:56:01 +02:00
|
|
|
import friendlyDate from '../../helpers/friendlyDate';
|
|
|
|
|
|
2019-09-17 17:04:19 +02:00
|
|
|
interface Props {
|
|
|
|
|
id: number;
|
|
|
|
|
body: string;
|
|
|
|
|
userFullName: string;
|
2019-09-30 23:28:52 +02:00
|
|
|
userEmail: string;
|
2019-09-17 17:04:19 +02:00
|
|
|
updatedAt: string;
|
|
|
|
|
|
2019-09-26 18:22:18 +02:00
|
|
|
replyForm: ReplyFormState;
|
2019-09-17 19:09:38 +02:00
|
|
|
handleToggleCommentReply(): void;
|
2019-09-26 11:00:32 +02:00
|
|
|
handleCommentReplyBodyChange(e: React.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,
|
|
|
|
|
userFullName,
|
2019-09-30 23:28:52 +02:00
|
|
|
userEmail,
|
2019-09-17 17:04:19 +02:00
|
|
|
updatedAt,
|
|
|
|
|
|
2019-09-26 18:22:18 +02:00
|
|
|
replyForm,
|
2019-09-17 19:09:38 +02:00
|
|
|
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">
|
2019-09-30 23:28:52 +02:00
|
|
|
<Gravatar email={userEmail} size={24} className="gravatar" />
|
2019-09-17 17:04:19 +02:00
|
|
|
<span className="commentAuthor">{userFullName}</span>
|
|
|
|
|
</div>
|
|
|
|
|
<p className="commentBody">{body}</p>
|
|
|
|
|
<div className="commentFooter">
|
2019-09-20 17:56:01 +02:00
|
|
|
<a className="commentReplyButton" onClick={handleToggleCommentReply}>
|
2019-09-26 18:22:18 +02:00
|
|
|
{ replyForm.isOpen ? 'Cancel' : 'Reply' }
|
2019-09-20 17:56:01 +02:00
|
|
|
</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 />
|
2019-09-20 17:56:01 +02:00
|
|
|
<MutedText>{friendlyDate(updatedAt)}</MutedText>
|
2019-09-17 17:04:19 +02:00
|
|
|
</div>
|
2019-09-17 19:09:38 +02:00
|
|
|
{
|
2019-09-26 18:22:18 +02:00
|
|
|
replyForm.isOpen ?
|
2019-09-18 13:40:00 +02:00
|
|
|
<NewComment
|
2019-09-26 18:22:18 +02:00
|
|
|
body={replyForm.body}
|
2019-09-18 13:40:00 +02:00
|
|
|
parentId={id}
|
2019-09-26 18:22:18 +02:00
|
|
|
isSubmitting={replyForm.isSubmitting}
|
|
|
|
|
error={replyForm.error}
|
2019-09-18 13:40:00 +02:00
|
|
|
handleChange={handleCommentReplyBodyChange}
|
|
|
|
|
handleSubmit={handleSubmitComment}
|
2019-09-20 18:43:24 +02:00
|
|
|
|
|
|
|
|
isLoggedIn={isLoggedIn}
|
2019-09-17 19:09:38 +02:00
|
|
|
/>
|
|
|
|
|
:
|
|
|
|
|
null
|
|
|
|
|
}
|
2019-09-17 17:04:19 +02:00
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
export default Comment;
|