Skip to content

Commit 90a58c4

Browse files
authored
Merge pull request Expensify#76158 from linhvovan29546/fix/74937-v2-debounce-calculate-emoji-suggestion
Debounce calculateEmojiSuggestion
2 parents 1069f90 + 7eb07af commit 90a58c4

3 files changed

Lines changed: 15 additions & 4 deletions

File tree

src/CONST/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1649,7 +1649,7 @@ const CONST = {
16491649
TRIE_INITIALIZATION: 'trie_initialization',
16501650
COMMENT_LENGTH_DEBOUNCE_TIME: 1500,
16511651
SEARCH_OPTION_LIST_DEBOUNCE_TIME: 300,
1652-
MENTION_SUGGESTION_DEBOUNCE_TIME: 100,
1652+
SUGGESTION_DEBOUNCE_TIME: 100,
16531653
RESIZE_DEBOUNCE_TIME: 100,
16541654
UNREAD_UPDATE_DEBOUNCE_TIME: 300,
16551655
SEARCH_FILTER_OPTIONS: 'search_filter_options',

src/pages/home/report/ReportActionCompose/SuggestionEmoji.tsx

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import React, {useCallback, useEffect, useImperativeHandle, useRef, useState} fr
22
import type {Emoji} from '@assets/emojis/types';
33
import EmojiSuggestions from '@components/EmojiSuggestions';
44
import useArrowKeyFocusManager from '@hooks/useArrowKeyFocusManager';
5+
import useDebounce from '@hooks/useDebounce';
56
import useLocalize from '@hooks/useLocalize';
67
import useOnyx from '@hooks/useOnyx';
78
import {getPreferredSkinToneIndex, suggestEmojis} from '@libs/EmojiUtils';
@@ -175,13 +176,23 @@ function SuggestionEmoji({
175176
[preferredLocale, setHighlightedEmojiIndex, resetSuggestions],
176177
);
177178

179+
const debouncedCalculateEmojiSuggestion = useDebounce(
180+
useCallback(
181+
(newValue: string, selectionStart?: number, selectionEnd?: number) => {
182+
calculateEmojiSuggestion(newValue, selectionStart, selectionEnd);
183+
},
184+
[calculateEmojiSuggestion],
185+
),
186+
CONST.TIMING.SUGGESTION_DEBOUNCE_TIME,
187+
);
188+
178189
useEffect(() => {
179190
if (!isComposerFocused) {
180191
return;
181192
}
182193

183-
calculateEmojiSuggestion(value, selection.start, selection.end);
184-
}, [value, selection, calculateEmojiSuggestion, isComposerFocused]);
194+
debouncedCalculateEmojiSuggestion(value, selection.start, selection.end);
195+
}, [value, selection.start, selection.end, debouncedCalculateEmojiSuggestion, isComposerFocused]);
185196

186197
const setShouldBlockSuggestionCalc = useCallback(
187198
(shouldBlockSuggestionCalc: boolean) => {

src/pages/home/report/ReportActionCompose/SuggestionMention.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -440,7 +440,7 @@ function SuggestionMention({
440440
},
441441
[calculateMentionSuggestion],
442442
),
443-
CONST.TIMING.MENTION_SUGGESTION_DEBOUNCE_TIME,
443+
CONST.TIMING.SUGGESTION_DEBOUNCE_TIME,
444444
);
445445

446446
useEffect(() => {

0 commit comments

Comments
 (0)