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 16, 2024
1 parent 9e1922e commit 3a10e62
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 8 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
- cancel old message highlight animations when a new message is highlighted #4203
- fix: packaging: include architecture in filename for all appimages #4202
- fix: make open external link scheme case insensive #4201
- fix: save draft when you switch to another chat #3733

<a id="1_46_8"></a>

Expand Down
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: ReturnType<typeof debounce<(text: string, chatId: number) => void>>
constructor(props: ComposerMessageInputProps) {
super(props)
this.state = {
Expand All @@ -46,10 +46,9 @@ 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)
}, 200)

this.textareaRef = React.createRef()
this.focus = this.focus.bind(this)
Expand Down Expand Up @@ -124,17 +123,14 @@ export default class ComposerMessageInput extends React.Component<
this.resizeTextareaAndComposer()
if (prevState.text !== this.state.text) {
if (!this.state.loadingDraft) {
this.saveDraft()
this.saveDraft(this.state.text, prevState.chatId)
}
}
}
}

onChange(e: React.ChangeEvent<HTMLTextAreaElement>) {
this.setState({ text: e.target.value /*error: false*/ })
if (!this.state.loadingDraft) {
this.saveDraft()
}
}

keyEventToAction(e: React.KeyboardEvent<HTMLTextAreaElement>) {
Expand Down

0 comments on commit 3a10e62

Please sign in to comment.