import React from 'react'; import { connect } from 'react-redux'; import moment from 'moment'; import { Button } from 'antd'; import Markdown from 'components/Markdown'; import Identicon from 'components/Identicon'; import MarkdownEditor, { MARKDOWN_TYPE } from 'components/MarkdownEditor'; import { postProposalComment } from 'modules/proposals/actions'; import { Comment as IComment, Proposal } from 'types'; import { AppState } from 'store/reducers'; import './style.less'; interface OwnProps { comment: IComment; proposalId: Proposal['proposalId']; } interface StateProps { isPostCommentPending: AppState['proposal']['isPostCommentPending']; postCommentError: AppState['proposal']['postCommentError']; } interface DispatchProps { postProposalComment: typeof postProposalComment; } type Props = OwnProps & StateProps & DispatchProps; interface State { reply: string; isReplying: boolean; } class Comment extends React.Component { state: State = { reply: '', isReplying: false, }; componentDidUpdate(prevProps: Props) { // TODO: Come up with better check on if our comment post was a success const { isPostCommentPending, postCommentError } = this.props; if (!isPostCommentPending && !postCommentError && prevProps.isPostCommentPending) { this.setState({ reply: '', isReplying: false }); } } public render(): React.ReactNode { const { comment, proposalId } = this.props; const { isReplying, reply } = this.state; return (
{/*
*/}
{comment.author.username}
{moment(comment.dateCreated).fromNow()}
{isReplying ? 'Cancel' : 'Reply'} {/*Report*/}
{(comment.replies.length || isReplying) && (
{isReplying && (
)} {comment.replies.map(subComment => ( ))}
)}
); } private toggleReply = () => { this.setState({ isReplying: !this.state.isReplying }); }; private handleChangeReply = (reply: string) => { this.setState({ reply }); }; private reply = () => { const { comment, proposalId } = this.props; const { reply } = this.state; this.props.postProposalComment(proposalId, reply, comment.commentId); }; } const ConnectedComment = connect( (state: AppState) => ({ isPostCommentPending: state.proposal.isPostCommentPending, postCommentError: state.proposal.postCommentError, }), { postProposalComment, }, )(Comment); export default ConnectedComment;