Skip to content

Commit b270cac

Browse files
Refactored localeCompare in SidebarUtils
1 parent b73ebe2 commit b270cac

2 files changed

Lines changed: 6 additions & 3 deletions

File tree

src/hooks/useSidebarOrderedReports.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import type * as OnyxTypes from '@src/types/onyx';
1010
import mapOnyxCollectionItems from '@src/utils/mapOnyxCollectionItems';
1111
import useCurrentReportID from './useCurrentReportID';
1212
import useCurrentUserPersonalDetails from './useCurrentUserPersonalDetails';
13+
import useLocalize from './useLocalize';
1314
import useOnyx from './useOnyx';
1415
import usePrevious from './usePrevious';
1516
import useResponsiveLayout from './useResponsiveLayout';
@@ -55,6 +56,7 @@ function SidebarOrderedReportsContextProvider({
5556
*/
5657
currentReportIDForTests,
5758
}: SidebarOrderedReportsContextProviderProps) {
59+
const {localeCompare} = useLocalize();
5860
const [priorityMode = CONST.PRIORITY_MODE.DEFAULT] = useOnyx(ONYXKEYS.NVP_PRIORITY_MODE, {canBeMissing: true});
5961
const [chatReports, {sourceValue: reportUpdates}] = useOnyx(ONYXKEYS.COLLECTION.REPORT, {canBeMissing: true});
6062
const [policies, {sourceValue: policiesUpdates}] = useOnyx(ONYXKEYS.COLLECTION.POLICY, {selector: (c) => mapOnyxCollectionItems(c, policySelector), canBeMissing: true});
@@ -173,10 +175,10 @@ function SidebarOrderedReportsContextProvider({
173175
}, [reportsToDisplayInLHN]);
174176

175177
const getOrderedReportIDs = useCallback(
176-
() => SidebarUtils.sortReportsToDisplayInLHN(reportsToDisplayInLHN, priorityMode, reportNameValuePairs, reportAttributes),
178+
() => SidebarUtils.sortReportsToDisplayInLHN(reportsToDisplayInLHN, priorityMode, localeCompare, reportNameValuePairs, reportAttributes),
177179
// Rule disabled intentionally - reports should be sorted only when the reportsToDisplayInLHN changes
178180
// eslint-disable-next-line react-compiler/react-compiler, react-hooks/exhaustive-deps
179-
[reportsToDisplayInLHN],
181+
[reportsToDisplayInLHN, localeCompare],
180182
);
181183

182184
const orderedReportIDs = useMemo(() => getOrderedReportIDs(), [getOrderedReportIDs]);

src/libs/SidebarUtils.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import {Str} from 'expensify-common';
22
import type {OnyxCollection, OnyxEntry} from 'react-native-onyx';
33
import Onyx from 'react-native-onyx';
44
import type {ValueOf} from 'type-fest';
5+
import type {LocaleContextProps} from '@components/LocaleContextProvider';
56
import type {PartialPolicyForSidebar, ReportsToDisplayInLHN} from '@hooks/useSidebarOrderedReports';
67
import CONST from '@src/CONST';
78
import ONYXKEYS from '@src/ONYXKEYS';
@@ -16,7 +17,6 @@ import type ReportAction from '@src/types/onyx/ReportAction';
1617
import {getExpensifyCardFromReportAction} from './CardMessageUtils';
1718
import {extractCollectionItemID} from './CollectionUtils';
1819
import {hasValidDraftComment} from './DraftCommentUtils';
19-
import localeCompare from './LocaleCompare';
2020
import {translateLocal} from './Localize';
2121
import {getLastActorDisplayName, getLastMessageTextForReport, getPersonalDetailsForAccountIDs, shouldShowLastActorDisplayName} from './OptionsListUtils';
2222
import Parser from './Parser';
@@ -344,6 +344,7 @@ function updateReportsToDisplayInLHN(
344344
function sortReportsToDisplayInLHN(
345345
reportsToDisplay: ReportsToDisplayInLHN,
346346
priorityMode: OnyxEntry<PriorityMode>,
347+
localeCompare: LocaleContextProps['localeCompare'],
347348
reportNameValuePairs?: OnyxCollection<ReportNameValuePairs>,
348349
reportAttributes?: ReportAttributesDerivedValue['reports'],
349350
): string[] {

0 commit comments

Comments
 (0)