diff --git a/CHANGELOG.md b/CHANGELOG.md
index 963cd84ef0..f95f1da09b 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -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 dialog #3733
diff --git a/packages/frontend/src/components/composer/ComposerMessageInput.tsx b/packages/frontend/src/components/composer/ComposerMessageInput.tsx
index dc8640fe75..a24e652893 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: ReturnType void>>
constructor(props: ComposerMessageInputProps) {
super(props)
this.state = {
@@ -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)
@@ -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(this.state.text, prevState.chatId)
}
}
}
@@ -132,9 +131,6 @@ 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()
- }
}
keyEventToAction(e: React.KeyboardEvent) {