Skip to content

Commit

Permalink
Save draft on chat change
Browse files Browse the repository at this point in the history
- resolves 3733
  • Loading branch information
maxphilippov committed Oct 15, 2024
1 parent 9e1922e commit c9e78c0
Showing 1 changed file with 5 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export default class ComposerMessageInput extends React.Component<
composerSize: number
setCursorPosition: number | false
textareaRef: React.RefObject<HTMLTextAreaElement>
saveDraft: () => void
saveDraft: any
constructor(props: ComposerMessageInputProps) {
super(props)
this.state = {
Expand All @@ -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)

Expand Down Expand Up @@ -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)
}
}
}
Expand All @@ -133,7 +132,8 @@ export default class ComposerMessageInput extends React.Component<
onChange(e: React.ChangeEvent<HTMLTextAreaElement>) {
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)
}
}

Expand Down

0 comments on commit c9e78c0

Please sign in to comment.