From f3b8adb0f8979035609b98534168917ccb6db22e Mon Sep 17 00:00:00 2001 From: Fedi Rajhi Date: Wed, 4 Sep 2024 18:11:02 +0100 Subject: [PATCH 1/4] [Chore]: Unify comment emptiness check with ReportActionCompose --- .../ComposerWithSuggestions/ComposerWithSuggestions.tsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/pages/home/report/ReportActionCompose/ComposerWithSuggestions/ComposerWithSuggestions.tsx b/src/pages/home/report/ReportActionCompose/ComposerWithSuggestions/ComposerWithSuggestions.tsx index 085aa2f7db9a..8fd8621de5fb 100644 --- a/src/pages/home/report/ReportActionCompose/ComposerWithSuggestions/ComposerWithSuggestions.tsx +++ b/src/pages/home/report/ReportActionCompose/ComposerWithSuggestions/ComposerWithSuggestions.tsx @@ -481,14 +481,14 @@ function ComposerWithSuggestions( } // Trigger the edit box for last sent message if ArrowUp is pressed and the comment is empty and Chronos is not in the participants - const valueLength = valueRef.current.length; + const isEmptyComment = !valueRef.current || valueRef.current.match(/^(\s)*$/); if ( 'key' in event && event.key === CONST.KEYBOARD_SHORTCUTS.ARROW_UP.shortcutKey && textInputRef.current && 'selectionStart' in textInputRef.current && textInputRef.current?.selectionStart === 0 && - valueLength === 0 && + isEmptyComment && !includeChronos ) { event.preventDefault(); From 52b0eaf8930cc10e4b9c49e140a82a38f0198a2d Mon Sep 17 00:00:00 2001 From: Fedi Rajhi Date: Wed, 4 Sep 2024 18:14:40 +0100 Subject: [PATCH 2/4] [Chore]: Update deprecated selectionStart prop and simplify code --- .../ComposerWithSuggestions.tsx | 14 +++----------- 1 file changed, 3 insertions(+), 11 deletions(-) diff --git a/src/pages/home/report/ReportActionCompose/ComposerWithSuggestions/ComposerWithSuggestions.tsx b/src/pages/home/report/ReportActionCompose/ComposerWithSuggestions/ComposerWithSuggestions.tsx index 8fd8621de5fb..57a926352a6a 100644 --- a/src/pages/home/report/ReportActionCompose/ComposerWithSuggestions/ComposerWithSuggestions.tsx +++ b/src/pages/home/report/ReportActionCompose/ComposerWithSuggestions/ComposerWithSuggestions.tsx @@ -482,23 +482,15 @@ function ComposerWithSuggestions( // Trigger the edit box for last sent message if ArrowUp is pressed and the comment is empty and Chronos is not in the participants const isEmptyComment = !valueRef.current || valueRef.current.match(/^(\s)*$/); - if ( - 'key' in event && - event.key === CONST.KEYBOARD_SHORTCUTS.ARROW_UP.shortcutKey && - textInputRef.current && - 'selectionStart' in textInputRef.current && - textInputRef.current?.selectionStart === 0 && - isEmptyComment && - !includeChronos - ) { - event.preventDefault(); + if (webEvent.key === CONST.KEYBOARD_SHORTCUTS.ARROW_UP.shortcutKey && selection.start <= 0 && isEmptyComment && !includeChronos) { + webEvent.preventDefault(); if (lastReportAction) { const message = Array.isArray(lastReportAction?.message) ? lastReportAction?.message?.at(-1) ?? null : lastReportAction?.message ?? null; Report.saveReportActionDraft(reportID, lastReportAction, Parser.htmlToMarkdown(message?.html ?? '')); } } }, - [shouldUseNarrowLayout, isKeyboardShown, suggestionsRef, includeChronos, handleSendMessage, lastReportAction, reportID], + [shouldUseNarrowLayout, isKeyboardShown, suggestionsRef, selection.start, includeChronos, handleSendMessage, lastReportAction, reportID], ); const onChangeText = useCallback( From 919946c4319cae5f7f21e98021294fad405084b9 Mon Sep 17 00:00:00 2001 From: Fedi Rajhi Date: Wed, 4 Sep 2024 18:35:49 +0100 Subject: [PATCH 3/4] [Chore]: fix null checks --- .../ComposerWithSuggestions/ComposerWithSuggestions.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pages/home/report/ReportActionCompose/ComposerWithSuggestions/ComposerWithSuggestions.tsx b/src/pages/home/report/ReportActionCompose/ComposerWithSuggestions/ComposerWithSuggestions.tsx index 57a926352a6a..7035654c5b3b 100644 --- a/src/pages/home/report/ReportActionCompose/ComposerWithSuggestions/ComposerWithSuggestions.tsx +++ b/src/pages/home/report/ReportActionCompose/ComposerWithSuggestions/ComposerWithSuggestions.tsx @@ -481,7 +481,7 @@ function ComposerWithSuggestions( } // Trigger the edit box for last sent message if ArrowUp is pressed and the comment is empty and Chronos is not in the participants - const isEmptyComment = !valueRef.current || valueRef.current.match(/^(\s)*$/); + const isEmptyComment = !valueRef.current || !!valueRef.current.match(/^(\s)*$/); if (webEvent.key === CONST.KEYBOARD_SHORTCUTS.ARROW_UP.shortcutKey && selection.start <= 0 && isEmptyComment && !includeChronos) { webEvent.preventDefault(); if (lastReportAction) { From e3477a0b6a22027a6e2da6e91d4d9f8e856cb4b6 Mon Sep 17 00:00:00 2001 From: Fedi Rajhi Date: Wed, 4 Sep 2024 19:27:12 +0100 Subject: [PATCH 4/4] [Chore]: Refactor comment emptiness check to use CONST.REGEX.EMPTY_COMMENT --- src/CONST.ts | 1 + .../ComposerWithSuggestions/ComposerWithSuggestions.tsx | 2 +- .../home/report/ReportActionCompose/ReportActionCompose.tsx | 2 +- 3 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/CONST.ts b/src/CONST.ts index 4a0b3e2b18e4..37f3b0e9ec15 100755 --- a/src/CONST.ts +++ b/src/CONST.ts @@ -2395,6 +2395,7 @@ const CONST = { HAS_COLON_ONLY_AT_THE_BEGINNING: /^:[^:]+$/, HAS_AT_MOST_TWO_AT_SIGNS: /^@[^@]*@?[^@]*$/, + EMPTY_COMMENT: /^(\s)*$/, SPECIAL_CHAR: /[,/?"{}[\]()&^%;`$=#<>!*]/g, FIRST_SPACE: /.+?(?=\s)/, diff --git a/src/pages/home/report/ReportActionCompose/ComposerWithSuggestions/ComposerWithSuggestions.tsx b/src/pages/home/report/ReportActionCompose/ComposerWithSuggestions/ComposerWithSuggestions.tsx index 7035654c5b3b..21521396f347 100644 --- a/src/pages/home/report/ReportActionCompose/ComposerWithSuggestions/ComposerWithSuggestions.tsx +++ b/src/pages/home/report/ReportActionCompose/ComposerWithSuggestions/ComposerWithSuggestions.tsx @@ -481,7 +481,7 @@ function ComposerWithSuggestions( } // Trigger the edit box for last sent message if ArrowUp is pressed and the comment is empty and Chronos is not in the participants - const isEmptyComment = !valueRef.current || !!valueRef.current.match(/^(\s)*$/); + const isEmptyComment = !valueRef.current || !!valueRef.current.match(CONST.REGEX.EMPTY_COMMENT); if (webEvent.key === CONST.KEYBOARD_SHORTCUTS.ARROW_UP.shortcutKey && selection.start <= 0 && isEmptyComment && !includeChronos) { webEvent.preventDefault(); if (lastReportAction) { diff --git a/src/pages/home/report/ReportActionCompose/ReportActionCompose.tsx b/src/pages/home/report/ReportActionCompose/ReportActionCompose.tsx index 72e89c8de013..fd194040c1e6 100644 --- a/src/pages/home/report/ReportActionCompose/ReportActionCompose.tsx +++ b/src/pages/home/report/ReportActionCompose/ReportActionCompose.tsx @@ -179,7 +179,7 @@ function ReportActionCompose({ const [isCommentEmpty, setIsCommentEmpty] = useState(() => { const draftComment = getDraftComment(reportID); - return !draftComment || !!draftComment.match(/^(\s)*$/); + return !draftComment || !!draftComment.match(CONST.REGEX.EMPTY_COMMENT); }); /**