diff --git a/webapp/src/components/commentsList.tsx b/webapp/src/components/commentsList.tsx index 5bd3263f9..4203ff869 100644 --- a/webapp/src/components/commentsList.tsx +++ b/webapp/src/components/commentsList.tsx @@ -8,7 +8,8 @@ import {IBlock} from '../blocks/block' import {Utils} from '../utils' import mutator from '../mutator' -import {Editable} from './editable' +import Editable from '../widgets/editable' + import Comment from './comment' import './commentsList.scss' @@ -19,21 +20,32 @@ type Props = { intl: IntlShape } -class CommentsList extends React.Component { - newCommentRef = React.createRef() - sendCommentButtonRef = React.createRef() +type State = { + newComment: string + inputFocused: boolean +} + +class CommentsList extends React.Component { + public constructor(props: Props) { + super(props) + this.state = { + newComment: '', + inputFocused: false, + } + } public shouldComponentUpdate() { return true } - private sendComment = (text: string) => { + private sendComment = () => { const {cardId} = this.props Utils.assertValue(cardId) - const block = new MutableCommentBlock({parentId: cardId, title: text}) + const block = new MutableCommentBlock({parentId: cardId, title: this.state.newComment}) mutator.insertBlock(block, 'add comment') + this.setState({newComment: ''}) } public render(): JSX.Element { @@ -62,42 +74,33 @@ class CommentsList extends React.Component { src={userImageUrl} /> { }} - onFocus={() => { - this.sendCommentButtonRef.current.style.display = null - }} - onBlur={() => { - if (!this.newCommentRef.current?.text) { - this.sendCommentButtonRef.current.style.display = 'none' - } - }} - onKeyDown={(e: React.KeyboardEvent) => { + onChange={(value: string) => this.setState({newComment: value})} + value={this.state.newComment} + onFocus={() => this.setState({inputFocused: true})} + onBlur={() => this.setState({inputFocused: false})} + onKeyDown={(e: React.KeyboardEvent) => { if (e.keyCode === 13 && !(e.metaKey || e.ctrlKey) && !e.shiftKey && !e.altKey) { - this.sendCommentButtonRef.current.click() + this.sendComment() } }} /> -
{ - 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() - }} - > - -
+ {this.state.newComment && this.state.inputFocused && +
{ + Utils.log(`Send comment: ${this.state.newComment}`) + this.sendComment() + this.setState({inputFocused: false, newComment: ''}) + }} + > + +
} )