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-17 17:04:19 +02:00
|
|
|
|
2019-09-26 18:22:18 +02:00
|
|
|
import { ReplyFormState } from '../../reducers/replyFormReducer';
|
2019-09-17 19:09:38 +02:00
|
|
|
|
2022-06-22 10:17:42 +02:00
|
|
|
import CommentEditForm from './CommentEditForm';
|
|
|
|
|
import CommentFooter from './CommentFooter';
|
2024-02-14 19:40:39 +01:00
|
|
|
import { StaffIcon } from '../common/Icons';
|
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;
|
2024-02-14 19:40:39 +01:00
|
|
|
userRole: number;
|
2022-06-22 10:17:42 +02:00
|
|
|
createdAt: 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;
|
2022-06-22 10:17:42 +02:00
|
|
|
|
2022-05-28 11:03:36 +02:00
|
|
|
handleSubmitComment(body: string, parentId: number, isPostUpdate: boolean): void;
|
2022-06-22 10:17:42 +02:00
|
|
|
handleUpdateComment(commentId: number, body: string, isPostUpdate: boolean, onSuccess: Function): void;
|
|
|
|
|
handleDeleteComment(id: number): 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
|
|
|
}
|
|
|
|
|
|
2022-06-22 10:17:42 +02:00
|
|
|
interface State {
|
|
|
|
|
editMode: boolean;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
class Comment extends React.Component<Props, State> {
|
|
|
|
|
constructor(props: Props) {
|
|
|
|
|
super(props);
|
|
|
|
|
|
|
|
|
|
this.state = {
|
|
|
|
|
editMode: false,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
this.toggleEditMode = this.toggleEditMode.bind(this);
|
|
|
|
|
this._handleUpdateComment = this._handleUpdateComment.bind(this);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
toggleEditMode() {
|
|
|
|
|
this.setState({editMode: !this.state.editMode});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_handleUpdateComment(body: string, isPostUpdate: boolean) {
|
|
|
|
|
this.props.handleUpdateComment(
|
|
|
|
|
this.props.id,
|
|
|
|
|
body,
|
|
|
|
|
isPostUpdate,
|
|
|
|
|
this.toggleEditMode,
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
render() {
|
|
|
|
|
const {
|
|
|
|
|
id,
|
|
|
|
|
body,
|
|
|
|
|
isPostUpdate,
|
|
|
|
|
userFullName,
|
|
|
|
|
userEmail,
|
2024-02-14 19:40:39 +01:00
|
|
|
userRole,
|
2022-06-22 10:17:42 +02:00
|
|
|
createdAt,
|
|
|
|
|
updatedAt,
|
|
|
|
|
|
|
|
|
|
replyForm,
|
|
|
|
|
handleToggleCommentReply,
|
|
|
|
|
handleCommentReplyBodyChange,
|
|
|
|
|
|
|
|
|
|
handleSubmitComment,
|
|
|
|
|
handleDeleteComment,
|
|
|
|
|
|
|
|
|
|
isLoggedIn,
|
|
|
|
|
isPowerUser,
|
|
|
|
|
currentUserEmail,
|
|
|
|
|
} = this.props;
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<div className="comment">
|
|
|
|
|
<div className="commentHeader">
|
|
|
|
|
<Gravatar email={userEmail} size={28} className="gravatar" />
|
|
|
|
|
<span className="commentAuthor">{userFullName}</span>
|
2024-02-14 19:40:39 +01:00
|
|
|
|
|
|
|
|
{ userRole > 0 && <StaffIcon /> }
|
|
|
|
|
|
2022-06-22 10:17:42 +02:00
|
|
|
{
|
|
|
|
|
isPostUpdate ?
|
|
|
|
|
<span className="postUpdateBadge">
|
|
|
|
|
{I18n.t('post.comments.post_update_badge')}
|
|
|
|
|
</span>
|
|
|
|
|
:
|
|
|
|
|
null
|
|
|
|
|
}
|
|
|
|
|
</div>
|
|
|
|
|
|
2022-06-05 11:40:43 +02:00
|
|
|
{
|
2022-06-22 10:17:42 +02:00
|
|
|
this.state.editMode ?
|
|
|
|
|
<CommentEditForm
|
|
|
|
|
id={id}
|
|
|
|
|
initialBody={body}
|
|
|
|
|
initialIsPostUpdate={isPostUpdate}
|
|
|
|
|
|
|
|
|
|
isPowerUser={isPowerUser}
|
|
|
|
|
|
|
|
|
|
handleUpdateComment={this._handleUpdateComment}
|
|
|
|
|
toggleEditMode={this.toggleEditMode}
|
|
|
|
|
/>
|
2022-06-05 11:40:43 +02:00
|
|
|
:
|
2022-06-22 10:17:42 +02:00
|
|
|
<>
|
|
|
|
|
<ReactMarkdown
|
|
|
|
|
className="commentBody"
|
|
|
|
|
disallowedTypes={['heading', 'image', 'html']}
|
|
|
|
|
unwrapDisallowed
|
|
|
|
|
>
|
|
|
|
|
{body}
|
|
|
|
|
</ReactMarkdown>
|
|
|
|
|
|
|
|
|
|
<CommentFooter
|
|
|
|
|
id={id}
|
|
|
|
|
createdAt={createdAt}
|
|
|
|
|
updatedAt={updatedAt}
|
|
|
|
|
replyForm={replyForm}
|
|
|
|
|
isPowerUser={isPowerUser}
|
|
|
|
|
currentUserEmail={currentUserEmail}
|
|
|
|
|
commentAuthorEmail={userEmail}
|
|
|
|
|
|
|
|
|
|
handleDeleteComment={handleDeleteComment}
|
|
|
|
|
handleToggleCommentReply={handleToggleCommentReply}
|
|
|
|
|
toggleEditMode={this.toggleEditMode}
|
|
|
|
|
/>
|
|
|
|
|
</>
|
2022-06-05 11:40:43 +02:00
|
|
|
}
|
2022-06-22 10:17:42 +02:00
|
|
|
{
|
|
|
|
|
replyForm.isOpen ?
|
|
|
|
|
<NewComment
|
|
|
|
|
body={replyForm.body}
|
|
|
|
|
parentId={id}
|
|
|
|
|
postUpdateFlagValue={replyForm.isPostUpdate}
|
|
|
|
|
isSubmitting={replyForm.isSubmitting}
|
|
|
|
|
error={replyForm.error}
|
|
|
|
|
handleChange={handleCommentReplyBodyChange}
|
|
|
|
|
handlePostUpdateFlag={() => null}
|
|
|
|
|
handleSubmit={handleSubmitComment}
|
|
|
|
|
|
|
|
|
|
isLoggedIn={isLoggedIn}
|
|
|
|
|
isPowerUser={isPowerUser}
|
|
|
|
|
userEmail={currentUserEmail}
|
|
|
|
|
/>
|
|
|
|
|
:
|
|
|
|
|
null
|
|
|
|
|
}
|
|
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|
2019-09-17 17:04:19 +02:00
|
|
|
|
|
|
|
|
export default Comment;
|