Skip to content

Commit

Permalink
Merge pull request #41729 from tienifr/fix/40608
Browse files Browse the repository at this point in the history
Performance: reduce SearchForReport requests
  • Loading branch information
techievivek authored May 28, 2024
2 parents 2514f29 + 00f2190 commit 67c36b2
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions src/pages/ChatFinderPage/index.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type {StackScreenProps} from '@react-navigation/stack';
import isEmpty from 'lodash/isEmpty';
import React, {useEffect, useMemo, useState} from 'react';
import React, {useCallback, useEffect, useMemo, useState} from 'react';
import type {OnyxEntry} from 'react-native-onyx';
import {withOnyx} from 'react-native-onyx';
import HeaderWithBackButton from '@components/HeaderWithBackButton';
Expand Down Expand Up @@ -61,15 +61,23 @@ function ChatFinderPage({betas, isSearchingForReports, navigation}: ChatFinderPa
const offlineMessage: MaybePhraseKey = isOffline ? [`${translate('common.youAppearToBeOffline')} ${translate('search.resultsAreLimited')}`, {isTranslated: true}] : '';

const [searchValue, debouncedSearchValue, setSearchValue] = useDebouncedState('');
const [, debouncedSearchValueInServer, setSearchValueInServer] = useDebouncedState('', 500);
const updateSearchValue = useCallback(
(value: string) => {
setSearchValue(value);
setSearchValueInServer(value);
},
[setSearchValue, setSearchValueInServer],
);

useEffect(() => {
Timing.start(CONST.TIMING.CHAT_FINDER_RENDER);
Performance.markStart(CONST.TIMING.CHAT_FINDER_RENDER);
}, []);

useEffect(() => {
Report.searchInServer(debouncedSearchValue.trim());
}, [debouncedSearchValue]);
Report.searchInServer(debouncedSearchValueInServer.trim());
}, [debouncedSearchValueInServer]);

const searchOptions = useMemo(() => {
if (!areOptionsInitialized || !isScreenTransitionEnd) {
Expand Down Expand Up @@ -144,7 +152,7 @@ function ChatFinderPage({betas, isSearchingForReports, navigation}: ChatFinderPa
}

if (option.reportID) {
setSearchValue('');
updateSearchValue('');
Navigation.dismissModal(option.reportID);
} else {
Report.navigateToAndOpenReport(option.login ? [option.login] : []);
Expand Down Expand Up @@ -175,7 +183,7 @@ function ChatFinderPage({betas, isSearchingForReports, navigation}: ChatFinderPa
textInputValue={searchValue}
textInputLabel={translate('selectionList.nameEmailOrPhoneNumber')}
textInputHint={offlineMessage}
onChangeText={setSearchValue}
onChangeText={updateSearchValue}
headerMessage={headerMessage}
onLayout={setPerformanceTimersEnd}
onSelectRow={selectReport}
Expand Down

0 comments on commit 67c36b2

Please sign in to comment.