import * as React from 'react'; import ReactMarkdown from 'react-markdown'; import Gravatar from 'react-gravatar'; import I18n from 'i18n-js'; import NewComment from './NewComment'; import { ReplyFormState } from '../../reducers/replyFormReducer'; import CommentEditForm from './CommentEditForm'; import CommentFooter from './CommentFooter'; import { StaffIcon } from '../common/Icons'; interface Props { id: number; body: string; isPostUpdate: boolean; userFullName: string; userEmail: string; userRole: number; createdAt: string; updatedAt: string; replyForm: ReplyFormState; handleToggleCommentReply(): void; handleCommentReplyBodyChange(e: React.FormEvent): void; handleSubmitComment(body: string, parentId: number, isPostUpdate: boolean): void; handleUpdateComment(commentId: number, body: string, isPostUpdate: boolean, onSuccess: Function): void; handleDeleteComment(id: number): void; isLoggedIn: boolean; isPowerUser: boolean; currentUserEmail: string; } interface State { editMode: boolean; } class Comment extends React.Component { 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, userRole, createdAt, updatedAt, replyForm, handleToggleCommentReply, handleCommentReplyBodyChange, handleSubmitComment, handleDeleteComment, isLoggedIn, isPowerUser, currentUserEmail, } = this.props; return (
{userFullName} { userRole > 0 && } { isPostUpdate ? {I18n.t('post.comments.post_update_badge')} : null }
{ this.state.editMode ? : <> {body} } { replyForm.isOpen ? null} handleSubmit={handleSubmitComment} isLoggedIn={isLoggedIn} isPowerUser={isPowerUser} userEmail={currentUserEmail} /> : null }
); } } export default Comment;