Skip to content

Commit

Permalink
Merge pull request #11552 from Expensify/youssef_fix_message_reappearing
Browse files Browse the repository at this point in the history
Only debounce saving draft when user is typing
  • Loading branch information
tgolen authored Oct 4, 2022
2 parents 5d05cc7 + 84e9841 commit 1a42cf8
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions src/pages/home/report/ReportActionCompose.js
Original file line number Diff line number Diff line change
Expand Up @@ -376,8 +376,9 @@ class ReportActionCompose extends React.Component {
* Update the value of the comment in Onyx
*
* @param {String} newComment
* @param {Boolean} shouldDebounceSaveComment
*/
updateComment(newComment) {
updateComment(newComment, shouldDebounceSaveComment) {
this.setState({
isCommentEmpty: !!newComment.match(/^(\s|`)*$/),
value: newComment,
Expand All @@ -394,7 +395,11 @@ class ReportActionCompose extends React.Component {
}

this.comment = newComment;
this.debouncedSaveReportComment(newComment);
if (shouldDebounceSaveComment) {
this.debouncedSaveReportComment(newComment);
} else {
Report.saveReportComment(this.props.reportID, newComment || '');
}
if (newComment) {
this.debouncedBroadcastUserIsTyping();
}
Expand Down Expand Up @@ -472,6 +477,11 @@ class ReportActionCompose extends React.Component {
e.preventDefault();
}

// Since we're submitting the form here which should clear the composer
// We don't really care about saving the draft the user was typing
// We need to make sure an empty draft gets saved instead
this.debouncedSaveReportComment.cancel();

const comment = this.prepareCommentAndResetComposer();
if (!comment) {
return;
Expand Down Expand Up @@ -604,7 +614,7 @@ class ReportActionCompose extends React.Component {
textAlignVertical="top"
placeholder={inputPlaceholder}
placeholderTextColor={themeColors.placeholderText}
onChangeText={this.updateComment}
onChangeText={comment => this.updateComment(comment, true)}
onKeyPress={this.triggerHotkeyActions}
onDragEnter={(e, isOriginComposer) => {
if (!isOriginComposer) {
Expand Down

0 comments on commit 1a42cf8

Please sign in to comment.