From 3ae75c7f6d1366cfa970b11aa9f9b73597ddfe73 Mon Sep 17 00:00:00 2001 From: s-alves10 Date: Mon, 11 Sep 2023 07:22:23 -0500 Subject: [PATCH 1/7] fix: doesn't focus when modal is open from menu --- .../ReportActionCompose/AttachmentPickerWithMenuItems.js | 5 +++++ .../report/ReportActionCompose/ComposerWithSuggestions.js | 6 +++--- .../home/report/ReportActionCompose/ReportActionCompose.js | 6 ++++++ 3 files changed, 14 insertions(+), 3 deletions(-) diff --git a/src/pages/home/report/ReportActionCompose/AttachmentPickerWithMenuItems.js b/src/pages/home/report/ReportActionCompose/AttachmentPickerWithMenuItems.js index 5864b9b05023..6dd3355f4a53 100644 --- a/src/pages/home/report/ReportActionCompose/AttachmentPickerWithMenuItems.js +++ b/src/pages/home/report/ReportActionCompose/AttachmentPickerWithMenuItems.js @@ -76,6 +76,9 @@ const propTypes = { /** Called when the add action button is pressed */ onAddActionPressed: PropTypes.func.isRequired, + /** Called when the menu item is selected */ + onItemSelected: PropTypes.func.isRequired, + /** A ref for the add action button */ actionButtonRef: PropTypes.shape({ // eslint-disable-next-line react/forbid-prop-types @@ -111,6 +114,7 @@ function AttachmentPickerWithMenuItems({ onCanceledAttachmentPicker, onMenuClosed, onAddActionPressed, + onItemSelected, actionButtonRef, }) { const {translate} = useLocalize(); @@ -257,6 +261,7 @@ function AttachmentPickerWithMenuItems({ onClose={onPopoverMenuClose} onItemSelected={(item, index) => { setMenuVisibility(false); + onItemSelected(); // In order for the file picker to open dynamically, the click // function must be called from within a event handler that was initiated diff --git a/src/pages/home/report/ReportActionCompose/ComposerWithSuggestions.js b/src/pages/home/report/ReportActionCompose/ComposerWithSuggestions.js index 45882dc23a78..d5740a231038 100644 --- a/src/pages/home/report/ReportActionCompose/ComposerWithSuggestions.js +++ b/src/pages/home/report/ReportActionCompose/ComposerWithSuggestions.js @@ -322,11 +322,11 @@ function ComposerWithSuggestions({ suggestionsRef.current.updateShouldShowSuggestionMenuToFalse(false); }, [suggestionsRef]); - const setShouldBlockSuggestionCalc = useCallback(() => { + const setShouldBlockSuggestionCalcToFalse = useCallback(() => { if (!suggestionsRef.current) { return false; } - return suggestionsRef.current.setShouldBlockSuggestionCalc(true); + return suggestionsRef.current.setShouldBlockSuggestionCalc(false); }, [suggestionsRef]); /** @@ -472,7 +472,7 @@ function ComposerWithSuggestions({ maxLines={maxComposerLines} onFocus={onFocus} onBlur={onBlur} - onClick={setShouldBlockSuggestionCalc} + onClick={setShouldBlockSuggestionCalcToFalse} onPasteFile={displayFileInModal} shouldClear={textInputShouldClear} onClear={() => setTextInputShouldClear(false)} diff --git a/src/pages/home/report/ReportActionCompose/ReportActionCompose.js b/src/pages/home/report/ReportActionCompose/ReportActionCompose.js index 3ad92fa5c769..89cbb5583fc4 100644 --- a/src/pages/home/report/ReportActionCompose/ReportActionCompose.js +++ b/src/pages/home/report/ReportActionCompose/ReportActionCompose.js @@ -205,6 +205,10 @@ function ReportActionCompose({ composerRef.current.blur(); }, []); + const onItemSelected = useCallback(() => { + isKeyboardVisibleWhenShowingModalRef.current = false; + }, []); + const updateShouldShowSuggestionMenuToFalse = useCallback(() => { if (!suggestionsRef.current) { return; @@ -271,6 +275,7 @@ function ReportActionCompose({ suggestionsRef.current.setShouldBlockSuggestionCalc(true); } isNextModalWillOpenRef.current = true; + isKeyboardVisibleWhenShowingModalRef.current = true; }, []); const onBlur = useCallback((e) => { @@ -358,6 +363,7 @@ function ReportActionCompose({ onCanceledAttachmentPicker={restoreKeyboardState} onMenuClosed={restoreKeyboardState} onAddActionPressed={onAddActionPressed} + onItemSelected={onItemSelected} actionButtonRef={actionButtonRef} /> Date: Mon, 11 Sep 2023 09:09:44 -0500 Subject: [PATCH 2/7] fix: onSelectionChange isn't called on native platforms --- src/libs/isSelectionChangedOnFocus/index.js | 1 + .../isSelectionChangedOnFocus/index.native.js | 1 + .../ReportActionCompose.js | 19 ++++++++++++++++++- .../ReportActionCompose/SuggestionEmoji.js | 11 ++++++++++- .../ReportActionCompose/SuggestionMention.js | 12 +++++++++++- .../report/ReportActionCompose/Suggestions.js | 6 ++++++ 6 files changed, 47 insertions(+), 3 deletions(-) create mode 100644 src/libs/isSelectionChangedOnFocus/index.js create mode 100644 src/libs/isSelectionChangedOnFocus/index.native.js diff --git a/src/libs/isSelectionChangedOnFocus/index.js b/src/libs/isSelectionChangedOnFocus/index.js new file mode 100644 index 000000000000..ff3177babdde --- /dev/null +++ b/src/libs/isSelectionChangedOnFocus/index.js @@ -0,0 +1 @@ +export default true; diff --git a/src/libs/isSelectionChangedOnFocus/index.native.js b/src/libs/isSelectionChangedOnFocus/index.native.js new file mode 100644 index 000000000000..33136544dba2 --- /dev/null +++ b/src/libs/isSelectionChangedOnFocus/index.native.js @@ -0,0 +1 @@ +export default false; diff --git a/src/pages/home/report/ReportActionCompose/ReportActionCompose.js b/src/pages/home/report/ReportActionCompose/ReportActionCompose.js index 89cbb5583fc4..219ce9fa871a 100644 --- a/src/pages/home/report/ReportActionCompose/ReportActionCompose.js +++ b/src/pages/home/report/ReportActionCompose/ReportActionCompose.js @@ -12,6 +12,7 @@ import ReportTypingIndicator from '../ReportTypingIndicator'; import AttachmentModal from '../../../../components/AttachmentModal'; import compose from '../../../../libs/compose'; import willBlurTextInputOnTapOutsideFunc from '../../../../libs/willBlurTextInputOnTapOutside'; +import isSelectionChangedOnFocus from '../../../../libs/isSelectionChangedOnFocus'; import canFocusInputOnScreenFocus from '../../../../libs/canFocusInputOnScreenFocus'; import CONST from '../../../../CONST'; import * as ReportUtils from '../../../../libs/ReportUtils'; @@ -106,6 +107,7 @@ function ReportActionCompose({ reportActions, shouldShowComposeInput, isCommentEmpty: isCommentEmptyProp, + modal, }) { const {translate} = useLocalize(); const {isMediumScreenWidth, isSmallScreenWidth} = useWindowDimensions(); @@ -179,11 +181,17 @@ function ReportActionCompose({ return; } composerRef.current.focus(true); + + // Restore the suggestions if onSelectionChange is not called on focused + if (isSelectionChangedOnFocus || !suggestionsRef.current) { + return; + } + suggestionsRef.current.restoreSuggestions(); }; const isKeyboardVisibleWhenShowingModalRef = useRef(false); const restoreKeyboardState = useCallback(() => { - if (!isKeyboardVisibleWhenShowingModalRef.current) { + if (!isKeyboardVisibleWhenShowingModalRef.current || !shouldFocusInputOnScreenFocus) { return; } focus(); @@ -311,6 +319,12 @@ function ReportActionCompose({ [], ); + useEffect(() => { + if (!modal.isVisible) { + focus(); + } + }, [modal.isVisible]) + const reportRecipientAcountIDs = ReportUtils.getReportRecipientAccountIDs(report, currentUserPersonalDetails.accountID); const reportRecipient = personalDetails[reportRecipientAcountIDs[0]]; const shouldUseFocusedColor = !isBlockedFromConcierge && !disabled && isFocused; @@ -460,5 +474,8 @@ export default compose( shouldShowComposeInput: { key: ONYXKEYS.SHOULD_SHOW_COMPOSE_INPUT, }, + modal: { + key: ONYXKEYS.MODAL, + }, }), )(ReportActionCompose); diff --git a/src/pages/home/report/ReportActionCompose/SuggestionEmoji.js b/src/pages/home/report/ReportActionCompose/SuggestionEmoji.js index 687570af12e6..018e8f36fc0e 100644 --- a/src/pages/home/report/ReportActionCompose/SuggestionEmoji.js +++ b/src/pages/home/report/ReportActionCompose/SuggestionEmoji.js @@ -85,6 +85,7 @@ function SuggestionEmoji({ // Used to decide whether to block the suggestions list from showing to prevent flickering const shouldBlockCalc = useRef(false); + const previousSuggestionValues = useRef(defaultSuggestionsValues); /** * Replace the code of emoji and update selection @@ -119,7 +120,14 @@ function SuggestionEmoji({ * Clean data related to suggestions */ const resetSuggestions = useCallback(() => { - setSuggestionValues(defaultSuggestionsValues); + setSuggestionValues((prev) => { + previousSuggestionValues.current = prev; + return defaultSuggestionsValues; + }); + }, []); + + const restoreSuggestions = useCallback(() => { + setSuggestionValues(previousSuggestionValues.current); }, []); const updateShouldShowSuggestionMenuToFalse = useCallback(() => { @@ -216,6 +224,7 @@ function SuggestionEmoji({ forwardedRef, () => ({ resetSuggestions, + restoreSuggestions, onSelectionChange, triggerHotkeyActions, setShouldBlockSuggestionCalc, diff --git a/src/pages/home/report/ReportActionCompose/SuggestionMention.js b/src/pages/home/report/ReportActionCompose/SuggestionMention.js index 79b5d1d66e36..998eeb013024 100644 --- a/src/pages/home/report/ReportActionCompose/SuggestionMention.js +++ b/src/pages/home/report/ReportActionCompose/SuggestionMention.js @@ -69,6 +69,8 @@ function SuggestionMention({ // Used to decide whether to block the suggestions list from showing to prevent flickering const shouldBlockCalc = useRef(false); + const previousSuggestionValues = useRef(defaultSuggestionsValues); + /** * Replace the code of mention and update selection * @param {Number} highlightedMentionIndex @@ -97,7 +99,14 @@ function SuggestionMention({ * Clean data related to suggestions */ const resetSuggestions = useCallback(() => { - setSuggestionValues(defaultSuggestionsValues); + setSuggestionValues((prev) => { + previousSuggestionValues.current = prev; + return defaultSuggestionsValues; + }); + }, []); + + const restoreSuggestions = useCallback(() => { + setSuggestionValues(previousSuggestionValues.current); }, []); /** @@ -262,6 +271,7 @@ function SuggestionMention({ forwardedRef, () => ({ resetSuggestions, + restoreSuggestions, onSelectionChange, triggerHotkeyActions, setShouldBlockSuggestionCalc, diff --git a/src/pages/home/report/ReportActionCompose/Suggestions.js b/src/pages/home/report/ReportActionCompose/Suggestions.js index ed2ab9586d52..a93dd497d072 100644 --- a/src/pages/home/report/ReportActionCompose/Suggestions.js +++ b/src/pages/home/report/ReportActionCompose/Suggestions.js @@ -53,6 +53,11 @@ function Suggestions({ suggestionMentionRef.current.resetSuggestions(); }, []); + const restoreSuggestions = useCallback(() => { + suggestionEmojiRef.current.restoreSuggestions(); + suggestionMentionRef.current.restoreSuggestions(); + }, []); + /** * Listens for keyboard shortcuts and applies the action * @@ -84,6 +89,7 @@ function Suggestions({ forwardedRef, () => ({ resetSuggestions, + restoreSuggestions, onSelectionChange, triggerHotkeyActions, updateShouldShowSuggestionMenuToFalse, From 9bc0b9ccaa14e61904444292d1ed41f7c7413acd Mon Sep 17 00:00:00 2001 From: s-alves10 Date: Mon, 11 Sep 2023 09:24:29 -0500 Subject: [PATCH 3/7] fix: lint error --- .../home/report/ReportActionCompose/ReportActionCompose.js | 7 ++++--- .../home/report/ReportActionCompose/SuggestionEmoji.js | 2 +- .../home/report/ReportActionCompose/SuggestionMention.js | 2 +- src/pages/home/report/ReportActionCompose/Suggestions.js | 2 +- 4 files changed, 7 insertions(+), 6 deletions(-) diff --git a/src/pages/home/report/ReportActionCompose/ReportActionCompose.js b/src/pages/home/report/ReportActionCompose/ReportActionCompose.js index 219ce9fa871a..0eda68b5c1d1 100644 --- a/src/pages/home/report/ReportActionCompose/ReportActionCompose.js +++ b/src/pages/home/report/ReportActionCompose/ReportActionCompose.js @@ -320,10 +320,11 @@ function ReportActionCompose({ ); useEffect(() => { - if (!modal.isVisible) { - focus(); + if (modal.isVisible) { + return; } - }, [modal.isVisible]) + focus(); + }, [modal.isVisible]); const reportRecipientAcountIDs = ReportUtils.getReportRecipientAccountIDs(report, currentUserPersonalDetails.accountID); const reportRecipient = personalDetails[reportRecipientAcountIDs[0]]; diff --git a/src/pages/home/report/ReportActionCompose/SuggestionEmoji.js b/src/pages/home/report/ReportActionCompose/SuggestionEmoji.js index 018e8f36fc0e..9ff4c2afb19f 100644 --- a/src/pages/home/report/ReportActionCompose/SuggestionEmoji.js +++ b/src/pages/home/report/ReportActionCompose/SuggestionEmoji.js @@ -230,7 +230,7 @@ function SuggestionEmoji({ setShouldBlockSuggestionCalc, updateShouldShowSuggestionMenuToFalse, }), - [onSelectionChange, resetSuggestions, setShouldBlockSuggestionCalc, triggerHotkeyActions, updateShouldShowSuggestionMenuToFalse], + [onSelectionChange, resetSuggestions, restoreSuggestions, setShouldBlockSuggestionCalc, triggerHotkeyActions, updateShouldShowSuggestionMenuToFalse], ); if (!isEmojiSuggestionsMenuVisible) { diff --git a/src/pages/home/report/ReportActionCompose/SuggestionMention.js b/src/pages/home/report/ReportActionCompose/SuggestionMention.js index 998eeb013024..517bd559f067 100644 --- a/src/pages/home/report/ReportActionCompose/SuggestionMention.js +++ b/src/pages/home/report/ReportActionCompose/SuggestionMention.js @@ -277,7 +277,7 @@ function SuggestionMention({ setShouldBlockSuggestionCalc, updateShouldShowSuggestionMenuToFalse, }), - [onSelectionChange, resetSuggestions, setShouldBlockSuggestionCalc, triggerHotkeyActions, updateShouldShowSuggestionMenuToFalse], + [onSelectionChange, resetSuggestions, restoreSuggestions, setShouldBlockSuggestionCalc, triggerHotkeyActions, updateShouldShowSuggestionMenuToFalse], ); if (!isMentionSuggestionsMenuVisible) { diff --git a/src/pages/home/report/ReportActionCompose/Suggestions.js b/src/pages/home/report/ReportActionCompose/Suggestions.js index a93dd497d072..a90c366df618 100644 --- a/src/pages/home/report/ReportActionCompose/Suggestions.js +++ b/src/pages/home/report/ReportActionCompose/Suggestions.js @@ -95,7 +95,7 @@ function Suggestions({ updateShouldShowSuggestionMenuToFalse, setShouldBlockSuggestionCalc, }), - [onSelectionChange, resetSuggestions, setShouldBlockSuggestionCalc, triggerHotkeyActions, updateShouldShowSuggestionMenuToFalse], + [onSelectionChange, resetSuggestions, restoreSuggestions, setShouldBlockSuggestionCalc, triggerHotkeyActions, updateShouldShowSuggestionMenuToFalse], ); const {windowHeight, isSmallScreenWidth} = useWindowDimensions(); From 167ef3b1b7ddd5b43a23c20dee603f5a57be159a Mon Sep 17 00:00:00 2001 From: s-alves10 Date: Mon, 11 Sep 2023 09:51:34 -0500 Subject: [PATCH 4/7] fix: add comments --- src/pages/home/report/ReportActionCompose/SuggestionEmoji.js | 5 ++++- .../home/report/ReportActionCompose/SuggestionMention.js | 5 ++++- src/pages/home/report/ReportActionCompose/Suggestions.js | 3 +++ 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/src/pages/home/report/ReportActionCompose/SuggestionEmoji.js b/src/pages/home/report/ReportActionCompose/SuggestionEmoji.js index 9ff4c2afb19f..b5994fc46d5e 100644 --- a/src/pages/home/report/ReportActionCompose/SuggestionEmoji.js +++ b/src/pages/home/report/ReportActionCompose/SuggestionEmoji.js @@ -117,7 +117,7 @@ function SuggestionEmoji({ ); /** - * Clean data related to suggestions + * Store the data related to suggestions and clean them */ const resetSuggestions = useCallback(() => { setSuggestionValues((prev) => { @@ -126,6 +126,9 @@ function SuggestionEmoji({ }); }, []); + /** + * Restore the previous suggestions data + */ const restoreSuggestions = useCallback(() => { setSuggestionValues(previousSuggestionValues.current); }, []); diff --git a/src/pages/home/report/ReportActionCompose/SuggestionMention.js b/src/pages/home/report/ReportActionCompose/SuggestionMention.js index 517bd559f067..145c98706254 100644 --- a/src/pages/home/report/ReportActionCompose/SuggestionMention.js +++ b/src/pages/home/report/ReportActionCompose/SuggestionMention.js @@ -96,7 +96,7 @@ function SuggestionMention({ ); /** - * Clean data related to suggestions + * Store the data related to suggestions and clean them */ const resetSuggestions = useCallback(() => { setSuggestionValues((prev) => { @@ -105,6 +105,9 @@ function SuggestionMention({ }); }, []); + /** + * Restore the previous suggestions data + */ const restoreSuggestions = useCallback(() => { setSuggestionValues(previousSuggestionValues.current); }, []); diff --git a/src/pages/home/report/ReportActionCompose/Suggestions.js b/src/pages/home/report/ReportActionCompose/Suggestions.js index a90c366df618..19912dc96d5d 100644 --- a/src/pages/home/report/ReportActionCompose/Suggestions.js +++ b/src/pages/home/report/ReportActionCompose/Suggestions.js @@ -53,6 +53,9 @@ function Suggestions({ suggestionMentionRef.current.resetSuggestions(); }, []); + /** + * Restore the previous suggestions data + */ const restoreSuggestions = useCallback(() => { suggestionEmojiRef.current.restoreSuggestions(); suggestionMentionRef.current.restoreSuggestions(); From c140802e2fe6f2d64ac26d66d86c21ce406e1590 Mon Sep 17 00:00:00 2001 From: s-alves10 Date: Mon, 11 Sep 2023 14:33:03 -0500 Subject: [PATCH 5/7] fix: remove modal props from ReportActionCompose --- .../ReportActionCompose/ReportActionCompose.js | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/src/pages/home/report/ReportActionCompose/ReportActionCompose.js b/src/pages/home/report/ReportActionCompose/ReportActionCompose.js index 0eda68b5c1d1..0be21d2d34fd 100644 --- a/src/pages/home/report/ReportActionCompose/ReportActionCompose.js +++ b/src/pages/home/report/ReportActionCompose/ReportActionCompose.js @@ -76,7 +76,6 @@ const propTypes = { }; const defaultProps = { - modal: {}, report: {}, blockedFromConcierge: {}, personalDetails: {}, @@ -107,7 +106,6 @@ function ReportActionCompose({ reportActions, shouldShowComposeInput, isCommentEmpty: isCommentEmptyProp, - modal, }) { const {translate} = useLocalize(); const {isMediumScreenWidth, isSmallScreenWidth} = useWindowDimensions(); @@ -319,13 +317,6 @@ function ReportActionCompose({ [], ); - useEffect(() => { - if (modal.isVisible) { - return; - } - focus(); - }, [modal.isVisible]); - const reportRecipientAcountIDs = ReportUtils.getReportRecipientAccountIDs(report, currentUserPersonalDetails.accountID); const reportRecipient = personalDetails[reportRecipientAcountIDs[0]]; const shouldUseFocusedColor = !isBlockedFromConcierge && !disabled && isFocused; @@ -475,8 +466,5 @@ export default compose( shouldShowComposeInput: { key: ONYXKEYS.SHOULD_SHOW_COMPOSE_INPUT, }, - modal: { - key: ONYXKEYS.MODAL, - }, }), )(ReportActionCompose); From 7b6570c96b4f5a5b79e27579fc1af67dfd804cee Mon Sep 17 00:00:00 2001 From: s-alves10 Date: Tue, 12 Sep 2023 08:03:19 -0500 Subject: [PATCH 6/7] fix: remove restoreSuggestions --- src/libs/isSelectionChangedOnFocus/index.js | 1 - .../isSelectionChangedOnFocus/index.native.js | 1 - .../ReportActionCompose/ReportActionCompose.js | 9 +-------- .../ReportActionCompose/SuggestionEmoji.js | 16 ++-------------- .../ReportActionCompose/SuggestionMention.js | 17 ++--------------- .../report/ReportActionCompose/Suggestions.js | 11 +---------- 6 files changed, 6 insertions(+), 49 deletions(-) delete mode 100644 src/libs/isSelectionChangedOnFocus/index.js delete mode 100644 src/libs/isSelectionChangedOnFocus/index.native.js diff --git a/src/libs/isSelectionChangedOnFocus/index.js b/src/libs/isSelectionChangedOnFocus/index.js deleted file mode 100644 index ff3177babdde..000000000000 --- a/src/libs/isSelectionChangedOnFocus/index.js +++ /dev/null @@ -1 +0,0 @@ -export default true; diff --git a/src/libs/isSelectionChangedOnFocus/index.native.js b/src/libs/isSelectionChangedOnFocus/index.native.js deleted file mode 100644 index 33136544dba2..000000000000 --- a/src/libs/isSelectionChangedOnFocus/index.native.js +++ /dev/null @@ -1 +0,0 @@ -export default false; diff --git a/src/pages/home/report/ReportActionCompose/ReportActionCompose.js b/src/pages/home/report/ReportActionCompose/ReportActionCompose.js index 0be21d2d34fd..89ed9ded787e 100644 --- a/src/pages/home/report/ReportActionCompose/ReportActionCompose.js +++ b/src/pages/home/report/ReportActionCompose/ReportActionCompose.js @@ -12,7 +12,6 @@ import ReportTypingIndicator from '../ReportTypingIndicator'; import AttachmentModal from '../../../../components/AttachmentModal'; import compose from '../../../../libs/compose'; import willBlurTextInputOnTapOutsideFunc from '../../../../libs/willBlurTextInputOnTapOutside'; -import isSelectionChangedOnFocus from '../../../../libs/isSelectionChangedOnFocus'; import canFocusInputOnScreenFocus from '../../../../libs/canFocusInputOnScreenFocus'; import CONST from '../../../../CONST'; import * as ReportUtils from '../../../../libs/ReportUtils'; @@ -179,17 +178,11 @@ function ReportActionCompose({ return; } composerRef.current.focus(true); - - // Restore the suggestions if onSelectionChange is not called on focused - if (isSelectionChangedOnFocus || !suggestionsRef.current) { - return; - } - suggestionsRef.current.restoreSuggestions(); }; const isKeyboardVisibleWhenShowingModalRef = useRef(false); const restoreKeyboardState = useCallback(() => { - if (!isKeyboardVisibleWhenShowingModalRef.current || !shouldFocusInputOnScreenFocus) { + if (!isKeyboardVisibleWhenShowingModalRef.current) { return; } focus(); diff --git a/src/pages/home/report/ReportActionCompose/SuggestionEmoji.js b/src/pages/home/report/ReportActionCompose/SuggestionEmoji.js index b5994fc46d5e..7a2fec966819 100644 --- a/src/pages/home/report/ReportActionCompose/SuggestionEmoji.js +++ b/src/pages/home/report/ReportActionCompose/SuggestionEmoji.js @@ -85,7 +85,6 @@ function SuggestionEmoji({ // Used to decide whether to block the suggestions list from showing to prevent flickering const shouldBlockCalc = useRef(false); - const previousSuggestionValues = useRef(defaultSuggestionsValues); /** * Replace the code of emoji and update selection @@ -120,17 +119,7 @@ function SuggestionEmoji({ * Store the data related to suggestions and clean them */ const resetSuggestions = useCallback(() => { - setSuggestionValues((prev) => { - previousSuggestionValues.current = prev; - return defaultSuggestionsValues; - }); - }, []); - - /** - * Restore the previous suggestions data - */ - const restoreSuggestions = useCallback(() => { - setSuggestionValues(previousSuggestionValues.current); + setSuggestionValues(defaultSuggestionsValues); }, []); const updateShouldShowSuggestionMenuToFalse = useCallback(() => { @@ -227,13 +216,12 @@ function SuggestionEmoji({ forwardedRef, () => ({ resetSuggestions, - restoreSuggestions, onSelectionChange, triggerHotkeyActions, setShouldBlockSuggestionCalc, updateShouldShowSuggestionMenuToFalse, }), - [onSelectionChange, resetSuggestions, restoreSuggestions, setShouldBlockSuggestionCalc, triggerHotkeyActions, updateShouldShowSuggestionMenuToFalse], + [onSelectionChange, resetSuggestions, setShouldBlockSuggestionCalc, triggerHotkeyActions, updateShouldShowSuggestionMenuToFalse], ); if (!isEmojiSuggestionsMenuVisible) { diff --git a/src/pages/home/report/ReportActionCompose/SuggestionMention.js b/src/pages/home/report/ReportActionCompose/SuggestionMention.js index 145c98706254..51f8f6850eb3 100644 --- a/src/pages/home/report/ReportActionCompose/SuggestionMention.js +++ b/src/pages/home/report/ReportActionCompose/SuggestionMention.js @@ -69,8 +69,6 @@ function SuggestionMention({ // Used to decide whether to block the suggestions list from showing to prevent flickering const shouldBlockCalc = useRef(false); - const previousSuggestionValues = useRef(defaultSuggestionsValues); - /** * Replace the code of mention and update selection * @param {Number} highlightedMentionIndex @@ -99,17 +97,7 @@ function SuggestionMention({ * Store the data related to suggestions and clean them */ const resetSuggestions = useCallback(() => { - setSuggestionValues((prev) => { - previousSuggestionValues.current = prev; - return defaultSuggestionsValues; - }); - }, []); - - /** - * Restore the previous suggestions data - */ - const restoreSuggestions = useCallback(() => { - setSuggestionValues(previousSuggestionValues.current); + setSuggestionValues(defaultSuggestionsValues); }, []); /** @@ -274,13 +262,12 @@ function SuggestionMention({ forwardedRef, () => ({ resetSuggestions, - restoreSuggestions, onSelectionChange, triggerHotkeyActions, setShouldBlockSuggestionCalc, updateShouldShowSuggestionMenuToFalse, }), - [onSelectionChange, resetSuggestions, restoreSuggestions, setShouldBlockSuggestionCalc, triggerHotkeyActions, updateShouldShowSuggestionMenuToFalse], + [onSelectionChange, resetSuggestions, setShouldBlockSuggestionCalc, triggerHotkeyActions, updateShouldShowSuggestionMenuToFalse], ); if (!isMentionSuggestionsMenuVisible) { diff --git a/src/pages/home/report/ReportActionCompose/Suggestions.js b/src/pages/home/report/ReportActionCompose/Suggestions.js index 19912dc96d5d..ed2ab9586d52 100644 --- a/src/pages/home/report/ReportActionCompose/Suggestions.js +++ b/src/pages/home/report/ReportActionCompose/Suggestions.js @@ -53,14 +53,6 @@ function Suggestions({ suggestionMentionRef.current.resetSuggestions(); }, []); - /** - * Restore the previous suggestions data - */ - const restoreSuggestions = useCallback(() => { - suggestionEmojiRef.current.restoreSuggestions(); - suggestionMentionRef.current.restoreSuggestions(); - }, []); - /** * Listens for keyboard shortcuts and applies the action * @@ -92,13 +84,12 @@ function Suggestions({ forwardedRef, () => ({ resetSuggestions, - restoreSuggestions, onSelectionChange, triggerHotkeyActions, updateShouldShowSuggestionMenuToFalse, setShouldBlockSuggestionCalc, }), - [onSelectionChange, resetSuggestions, restoreSuggestions, setShouldBlockSuggestionCalc, triggerHotkeyActions, updateShouldShowSuggestionMenuToFalse], + [onSelectionChange, resetSuggestions, setShouldBlockSuggestionCalc, triggerHotkeyActions, updateShouldShowSuggestionMenuToFalse], ); const {windowHeight, isSmallScreenWidth} = useWindowDimensions(); From 0d3f709fdc6ff2e77c9222e52774f4af8c5d170a Mon Sep 17 00:00:00 2001 From: s-alves10 Date: Tue, 12 Sep 2023 08:08:20 -0500 Subject: [PATCH 7/7] fix: update comments --- src/pages/home/report/ReportActionCompose/SuggestionEmoji.js | 2 +- src/pages/home/report/ReportActionCompose/SuggestionMention.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/pages/home/report/ReportActionCompose/SuggestionEmoji.js b/src/pages/home/report/ReportActionCompose/SuggestionEmoji.js index 7a2fec966819..687570af12e6 100644 --- a/src/pages/home/report/ReportActionCompose/SuggestionEmoji.js +++ b/src/pages/home/report/ReportActionCompose/SuggestionEmoji.js @@ -116,7 +116,7 @@ function SuggestionEmoji({ ); /** - * Store the data related to suggestions and clean them + * Clean data related to suggestions */ const resetSuggestions = useCallback(() => { setSuggestionValues(defaultSuggestionsValues); diff --git a/src/pages/home/report/ReportActionCompose/SuggestionMention.js b/src/pages/home/report/ReportActionCompose/SuggestionMention.js index 51f8f6850eb3..79b5d1d66e36 100644 --- a/src/pages/home/report/ReportActionCompose/SuggestionMention.js +++ b/src/pages/home/report/ReportActionCompose/SuggestionMention.js @@ -94,7 +94,7 @@ function SuggestionMention({ ); /** - * Store the data related to suggestions and clean them + * Clean data related to suggestions */ const resetSuggestions = useCallback(() => { setSuggestionValues(defaultSuggestionsValues);