diff --git a/packages/frontend/src/components/composer/ComposerMessageInput.tsx b/packages/frontend/src/components/composer/ComposerMessageInput.tsx index dc8640fe75..500f0ac572 100644 --- a/packages/frontend/src/components/composer/ComposerMessageInput.tsx +++ b/packages/frontend/src/components/composer/ComposerMessageInput.tsx @@ -29,7 +29,7 @@ export default class ComposerMessageInput extends React.Component< composerSize: number setCursorPosition: number | false textareaRef: React.RefObject - saveDraft: () => void + saveDraft: any constructor(props: ComposerMessageInputProps) { super(props) this.state = { @@ -46,8 +46,7 @@ export default class ComposerMessageInput extends React.Component< this.insertStringAtCursorPosition = this.insertStringAtCursorPosition.bind(this) - this.saveDraft = debounce(() => { - const { text, chatId } = this.state + this.saveDraft = debounce((text: string, chatId: number) => { this.props.updateDraftText(text.trim() === '' ? '' : text, chatId) }, 1000) @@ -124,7 +123,7 @@ export default class ComposerMessageInput extends React.Component< this.resizeTextareaAndComposer() if (prevState.text !== this.state.text) { if (!this.state.loadingDraft) { - this.saveDraft() + this.saveDraft.flush(this.state.text, prevState.chatId) } } } @@ -133,7 +132,8 @@ export default class ComposerMessageInput extends React.Component< onChange(e: React.ChangeEvent) { this.setState({ text: e.target.value /*error: false*/ }) if (!this.state.loadingDraft) { - this.saveDraft() + // call direrectly with new value so we don't wait for state update + this.saveDraft(e.target.value, this.state.chatId) } }