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 dd5b26b
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 dialog #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)

Check warning on line 126 in packages/frontend/src/components/composer/ComposerMessageInput.tsx

View workflow job for this annotation

GitHub Actions / Code Validation

Replace `↹` with `········`
}
}
}
}

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 dd5b26b

Please sign in to comment.