2019-09-17 17:04:19 +02:00
|
|
|
import * as React from 'react';
|
2022-06-06 20:20:03 +02:00
|
|
|
import ReactMarkdown from 'react-markdown';
|
2019-09-30 23:28:52 +02:00
|
|
|
import Gravatar from 'react-gravatar';
|
2022-06-06 20:20:03 +02:00
|
|
|
import I18n from 'i18n-js';
|
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
|
|
|
|
2022-05-28 11:03:36 +02:00
|
|
|
import friendlyDate from '../../helpers/datetime';
|
2019-09-20 17:56:01 +02:00
|
|
|
|
2019-09-17 17:04:19 +02:00
|
|
|
interface Props {
|
|
|
|
|
id: number;
|
|
|
|
|
body: string;
|
2019-10-02 16:43:13 +02:00
|
|
|
isPostUpdate: boolean;
|
2019-09-17 17:04:19 +02:00
|
|
|
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-10-02 16:43:13 +02:00
|
|
|
handleToggleIsCommentUpdate(commentId: number, currentIsPostUpdate: boolean): void;
|
2022-05-28 11:03:36 +02:00
|
|
|
handleSubmitComment(body: string, parentId: number, isPostUpdate: boolean): void;
|
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
|
|
|
currentUserEmail: string;
|
2019-09-17 17:04:19 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const Comment = ({
|
|
|
|
|
id,
|
|
|
|
|
body,
|
2019-10-02 16:43:13 +02:00
|
|
|
isPostUpdate,
|
2019-09-17 17:04:19 +02:00
|
|
|
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-10-02 16:43:13 +02:00
|
|
|
handleToggleIsCommentUpdate,
|
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-10-02 15:26:32 +02:00
|
|
|
currentUserEmail,
|
2019-09-17 17:04:19 +02:00
|
|
|
}: Props) => (
|
|
|
|
|
<div className="comment">
|
|
|
|
|
<div className="commentHeader">
|
2022-05-28 11:03:36 +02:00
|
|
|
<Gravatar email={userEmail} size={28} className="gravatar" />
|
2019-09-17 17:04:19 +02:00
|
|
|
<span className="commentAuthor">{userFullName}</span>
|
2022-06-05 11:40:43 +02:00
|
|
|
{
|
|
|
|
|
isPostUpdate ?
|
|
|
|
|
<span className="postUpdateBadge">
|
|
|
|
|
{I18n.t('post.comments.post_update_badge')}
|
|
|
|
|
</span>
|
|
|
|
|
:
|
|
|
|
|
null
|
|
|
|
|
}
|
2019-09-17 17:04:19 +02:00
|
|
|
</div>
|
2022-06-06 20:20:03 +02:00
|
|
|
|
|
|
|
|
<ReactMarkdown
|
|
|
|
|
className="commentBody"
|
|
|
|
|
disallowedTypes={['heading', 'image', 'html']}
|
|
|
|
|
unwrapDisallowed
|
|
|
|
|
>
|
|
|
|
|
{body}
|
|
|
|
|
</ReactMarkdown>
|
|
|
|
|
|
2019-09-17 17:04:19 +02:00
|
|
|
<div className="commentFooter">
|
2019-10-02 16:43:13 +02:00
|
|
|
<a className="commentReplyButton commentLink" onClick={handleToggleCommentReply}>
|
2022-06-05 11:40:43 +02:00
|
|
|
{
|
|
|
|
|
replyForm.isOpen ?
|
|
|
|
|
I18n.t('common.buttons.cancel')
|
|
|
|
|
:
|
|
|
|
|
I18n.t('post.comments.reply_button')
|
|
|
|
|
}
|
2019-09-20 17:56:01 +02:00
|
|
|
</a>
|
2019-09-25 11:50:23 +02:00
|
|
|
{
|
|
|
|
|
isPowerUser ?
|
|
|
|
|
<React.Fragment>
|
2019-10-02 16:43:13 +02:00
|
|
|
<Separator />
|
|
|
|
|
<a
|
|
|
|
|
onClick={() => handleToggleIsCommentUpdate(id, isPostUpdate)}
|
|
|
|
|
className="commentLink"
|
|
|
|
|
>
|
2019-10-02 16:53:35 +02:00
|
|
|
{ 'Post update: ' + (isPostUpdate ? 'yes' : 'no') }
|
2019-10-02 16:43:13 +02:00
|
|
|
</a>
|
2019-09-25 11:50:23 +02:00
|
|
|
<Separator />
|
2022-06-05 11:40:43 +02:00
|
|
|
<a href={`/admin/comments/${id}/edit`} className="commentLink" data-turbolinks="false">
|
|
|
|
|
{I18n.t('common.buttons.edit')}
|
|
|
|
|
</a>
|
2019-10-02 16:53:35 +02:00
|
|
|
<Separator />
|
|
|
|
|
<a
|
|
|
|
|
href={`/admin/comments/${id}`}
|
2020-07-17 17:51:34 +01:00
|
|
|
className="commentLink"
|
2019-10-02 16:53:35 +02:00
|
|
|
data-method="delete"
|
|
|
|
|
data-confirm="Are you sure?"
|
2022-06-05 11:40:43 +02:00
|
|
|
data-turbolinks="false">
|
|
|
|
|
{I18n.t('common.buttons.delete')}
|
|
|
|
|
</a>
|
2019-10-02 16:43:13 +02:00
|
|
|
|
2019-09-25 11:50:23 +02:00
|
|
|
</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}
|
2022-05-28 11:03:36 +02:00
|
|
|
postUpdateFlagValue={replyForm.isPostUpdate}
|
2019-09-26 18:22:18 +02:00
|
|
|
isSubmitting={replyForm.isSubmitting}
|
|
|
|
|
error={replyForm.error}
|
2019-09-18 13:40:00 +02:00
|
|
|
handleChange={handleCommentReplyBodyChange}
|
2022-05-28 11:03:36 +02:00
|
|
|
handlePostUpdateFlag={() => null}
|
2019-09-18 13:40:00 +02:00
|
|
|
handleSubmit={handleSubmitComment}
|
2019-09-20 18:43:24 +02:00
|
|
|
|
|
|
|
|
isLoggedIn={isLoggedIn}
|
2022-05-28 11:03:36 +02:00
|
|
|
isPowerUser={isPowerUser}
|
2019-10-02 15:26:32 +02:00
|
|
|
userEmail={currentUserEmail}
|
2019-09-17 19:09:38 +02:00
|
|
|
/>
|
|
|
|
|
:
|
|
|
|
|
null
|
|
|
|
|
}
|
2019-09-17 17:04:19 +02:00
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
export default Comment;
|