From 98bb17747372770ac08fe6847fcee0ac826383b5 Mon Sep 17 00:00:00 2001 From: DylanDylann Date: Mon, 2 Oct 2023 12:04:23 +0700 Subject: [PATCH 1/2] fix draft icon show even there is not anything --- .../ComposerWithSuggestions.js | 22 ++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/src/pages/home/report/ReportActionCompose/ComposerWithSuggestions.js b/src/pages/home/report/ReportActionCompose/ComposerWithSuggestions.js index d04983dc2f75..6e103f77c068 100644 --- a/src/pages/home/report/ReportActionCompose/ComposerWithSuggestions.js +++ b/src/pages/home/report/ReportActionCompose/ComposerWithSuggestions.js @@ -24,7 +24,6 @@ import * as User from '../../../../libs/actions/User'; import * as ReportUtils from '../../../../libs/ReportUtils'; import * as ReportActionsUtils from '../../../../libs/ReportActionsUtils'; import canFocusInputOnScreenFocus from '../../../../libs/canFocusInputOnScreenFocus'; -import debouncedSaveReportComment from '../../../../libs/ComposerUtils/debouncedSaveReportComment'; import SilentCommentUpdater from './SilentCommentUpdater'; import Suggestions from './Suggestions'; import getDraftComment from '../../../../libs/ComposerUtils/getDraftComment'; @@ -187,6 +186,14 @@ function ComposerWithSuggestions({ RNTextInputReset.resetKeyboardInput(findNodeHandle(textInputRef.current)); }, [textInputRef]); + const debouncedSaveReportComment = useMemo( + () => + _.debounce((selectedReportID, newComment) => { + Report.saveReportComment(selectedReportID, newComment || ''); + }, 1000), + [], + ); + /** * Update the value of the comment in Onyx * @@ -238,7 +245,16 @@ function ComposerWithSuggestions({ debouncedBroadcastUserIsTyping(reportID); } }, - [debouncedUpdateFrequentlyUsedEmojis, preferredLocale, preferredSkinTone, reportID, setIsCommentEmpty, suggestionsRef, raiseIsScrollLikelyLayoutTriggered], + [ + debouncedUpdateFrequentlyUsedEmojis, + preferredLocale, + preferredSkinTone, + reportID, + setIsCommentEmpty, + suggestionsRef, + raiseIsScrollLikelyLayoutTriggered, + debouncedSaveReportComment, + ], ); /** @@ -279,7 +295,7 @@ function ComposerWithSuggestions({ } setIsFullComposerAvailable(false); return trimmedComment; - }, [updateComment, setTextInputShouldClear, isComposerFullSize, setIsFullComposerAvailable, reportID]); + }, [updateComment, setTextInputShouldClear, isComposerFullSize, setIsFullComposerAvailable, reportID, debouncedSaveReportComment]); /** * Callback to add whatever text is chosen into the main input (used f.e as callback for the emoji picker) From a0a36c9d6a4818df46be0cfdcc0c0c67758cc0c4 Mon Sep 17 00:00:00 2001 From: DylanDylann Date: Mon, 2 Oct 2023 20:18:52 +0700 Subject: [PATCH 2/2] fix remove stale function --- src/libs/ComposerUtils/debouncedSaveReportComment.ts | 11 ----------- 1 file changed, 11 deletions(-) delete mode 100644 src/libs/ComposerUtils/debouncedSaveReportComment.ts diff --git a/src/libs/ComposerUtils/debouncedSaveReportComment.ts b/src/libs/ComposerUtils/debouncedSaveReportComment.ts deleted file mode 100644 index e449245edc52..000000000000 --- a/src/libs/ComposerUtils/debouncedSaveReportComment.ts +++ /dev/null @@ -1,11 +0,0 @@ -import debounce from 'lodash/debounce'; -import * as Report from '../actions/Report'; - -/** - * Save draft report comment. Debounced to happen at most once per second. - */ -const debouncedSaveReportComment = debounce((reportID: string, comment = '') => { - Report.saveReportComment(reportID, comment); -}, 1000); - -export default debouncedSaveReportComment;