// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved. // See LICENSE.txt for license information. import React from 'react' import {injectIntl, IntlShape, FormattedMessage} from 'react-intl' import {MutableCommentBlock} from '../blocks/commentBlock' import {IBlock} from '../blocks/block' import {Utils} from '../utils' import mutator from '../mutator' import {Editable} from './editable' import Comment from './comment' type Props = { comments: readonly IBlock[] cardId: string intl: IntlShape } class CommentsList extends React.Component { newCommentRef = React.createRef() sendCommentButtonRef = React.createRef() public shouldComponentUpdate() { return true } private sendComment = (text: string) => { const {cardId} = this.props Utils.assertValue(cardId) const block = new MutableCommentBlock({parentId: cardId, title: text}) mutator.insertBlock(block, 'add comment') } public render(): JSX.Element { const {comments, intl} = this.props // TODO: Replace this placeholder const username = 'John Smith' const userImageUrl = 'data:image/svg+xml,' return (
{comments.map((comment) => ( ))} {/* New comment */}
{ }} onFocus={() => { this.sendCommentButtonRef.current.style.display = null }} onBlur={() => { if (!this.newCommentRef.current?.text) { this.sendCommentButtonRef.current.style.display = 'none' } }} onKeyDown={(e: React.KeyboardEvent) => { if (e.keyCode === 13 && !(e.metaKey || e.ctrlKey) && !e.shiftKey && !e.altKey) { this.sendCommentButtonRef.current.click() } }} />
{ const text = this.newCommentRef.current.text Utils.log(`Send comment: ${this.newCommentRef.current.text}`) this.sendComment(text) this.newCommentRef.current.text = undefined this.newCommentRef.current.blur() }} >
) } } export default injectIntl(CommentsList)