diff --git a/src/libs/GroupChatUtils.ts b/src/libs/GroupChatUtils.ts index 5d925ae1c684..58a82de3df53 100644 --- a/src/libs/GroupChatUtils.ts +++ b/src/libs/GroupChatUtils.ts @@ -1,5 +1,6 @@ import type {OnyxEntry} from 'react-native-onyx'; import type {Report} from '@src/types/onyx'; +import localeCompare from './LocaleCompare'; import * as ReportUtils from './ReportUtils'; /** @@ -11,7 +12,7 @@ function getGroupChatName(report: OnyxEntry): string | undefined { return participants .map((participant) => ReportUtils.getDisplayNameForParticipant(participant, isMultipleParticipantReport)) - .sort((first, second) => first?.localeCompare(second ?? '') ?? 0) + .sort((first, second) => localeCompare(first ?? '', second ?? '')) .filter(Boolean) .join(', '); } diff --git a/src/libs/KeyboardShortcut/index.ts b/src/libs/KeyboardShortcut/index.ts index 44ba54953c40..0571f5e271ab 100644 --- a/src/libs/KeyboardShortcut/index.ts +++ b/src/libs/KeyboardShortcut/index.ts @@ -1,6 +1,7 @@ import Str from 'expensify-common/lib/str'; import * as KeyCommand from 'react-native-key-command'; import getOperatingSystem from '@libs/getOperatingSystem'; +import localeCompare from '@libs/LocaleCompare'; import CONST from '@src/CONST'; import bindHandlerToKeydownEvent from './bindHandlerToKeydownEvent'; @@ -32,7 +33,7 @@ type Shortcut = { const documentedShortcuts: Record = {}; function getDocumentedShortcuts(): Shortcut[] { - return Object.values(documentedShortcuts).sort((a, b) => a.displayName.localeCompare(b.displayName)); + return Object.values(documentedShortcuts).sort((a, b) => localeCompare(a.displayName, b.displayName)); } const keyInputEnter = KeyCommand?.constants?.keyInputEnter?.toString() ?? 'keyInputEnter'; diff --git a/src/libs/OptionsListUtils.ts b/src/libs/OptionsListUtils.ts index 97b4fc0144c8..5b40ae315aa4 100644 --- a/src/libs/OptionsListUtils.ts +++ b/src/libs/OptionsListUtils.ts @@ -34,6 +34,7 @@ import times from '@src/utils/times'; import Timing from './actions/Timing'; import * as CollectionUtils from './CollectionUtils'; import * as ErrorUtils from './ErrorUtils'; +import localeCompare from './LocaleCompare'; import * as LocalePhoneNumber from './LocalePhoneNumber'; import * as Localize from './Localize'; import * as LoginUtils from './LoginUtils'; @@ -871,9 +872,9 @@ function sortTags(tags: Record | Tag[]) { let sortedTags; if (Array.isArray(tags)) { - sortedTags = tags.sort((a, b) => a.name.localeCompare(b.name)); + sortedTags = tags.sort((a, b) => localeCompare(a.name, b.name)); } else { - sortedTags = Object.values(tags).sort((a, b) => a.name.localeCompare(b.name)); + sortedTags = Object.values(tags).sort((a, b) => localeCompare(a.name, b.name)); } return sortedTags; diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index ae6e02e70d29..ad2da34c39d4 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -52,6 +52,7 @@ import * as CollectionUtils from './CollectionUtils'; import * as CurrencyUtils from './CurrencyUtils'; import DateUtils from './DateUtils'; import isReportMessageAttachment from './isReportMessageAttachment'; +import localeCompare from './LocaleCompare'; import * as LocalePhoneNumber from './LocalePhoneNumber'; import * as Localize from './Localize'; import linkingConfig from './Navigation/linkingConfig'; @@ -1443,7 +1444,7 @@ function getIconsForParticipants(participants: number[], personalDetails: OnyxCo const sortedParticipantDetails = participantDetails.sort((first, second) => { // First sort by displayName/login - const displayNameLoginOrder = first[1].localeCompare(second[1]); + const displayNameLoginOrder = localeCompare(first[1], second[1]); if (displayNameLoginOrder !== 0) { return displayNameLoginOrder; } @@ -1701,7 +1702,7 @@ function getDisplayNamesWithTooltips( }) .sort((first, second) => { // First sort by displayName/login - const displayNameLoginOrder = first.displayName.localeCompare(second.displayName); + const displayNameLoginOrder = localeCompare(first.displayName, second.displayName); if (displayNameLoginOrder !== 0) { return displayNameLoginOrder; } diff --git a/src/pages/ReportParticipantsPage.tsx b/src/pages/ReportParticipantsPage.tsx index 15490455ce09..48c147822f9b 100755 --- a/src/pages/ReportParticipantsPage.tsx +++ b/src/pages/ReportParticipantsPage.tsx @@ -8,6 +8,7 @@ import OptionsList from '@components/OptionsList'; import ScreenWrapper from '@components/ScreenWrapper'; import useLocalize from '@hooks/useLocalize'; import useThemeStyles from '@hooks/useThemeStyles'; +import localeCompare from '@libs/LocaleCompare'; import * as LocalePhoneNumber from '@libs/LocalePhoneNumber'; import type * as Localize from '@libs/Localize'; import Navigation from '@libs/Navigation/Navigation'; @@ -69,7 +70,7 @@ const getAllParticipants = ( reportID: report?.reportID ?? '', }; }) - .sort((a, b) => a.displayName.localeCompare(b.displayName.toLowerCase())); + .sort((a, b) => localeCompare(a.displayName, b.displayName)); function ReportParticipantsPage({report, personalDetails}: ReportParticipantsPageProps) { const {translate} = useLocalize(); diff --git a/src/pages/RoomMembersPage.tsx b/src/pages/RoomMembersPage.tsx index 7593857536a6..557211dc0235 100644 --- a/src/pages/RoomMembersPage.tsx +++ b/src/pages/RoomMembersPage.tsx @@ -17,6 +17,7 @@ import withCurrentUserPersonalDetails from '@components/withCurrentUserPersonalD import useLocalize from '@hooks/useLocalize'; import useThemeStyles from '@hooks/useThemeStyles'; import * as DeviceCapabilities from '@libs/DeviceCapabilities'; +import localeCompare from '@libs/LocaleCompare'; import Log from '@libs/Log'; import Navigation from '@libs/Navigation/Navigation'; import type {RoomMembersNavigatorParamList} from '@libs/Navigation/types'; @@ -201,7 +202,7 @@ function RoomMembersPage({report, session, policies}: RoomMembersPageProps) { }); }); - result = result.sort((value1, value2) => value1.text.localeCompare(value2.text.toLowerCase())); + result = result.sort((value1, value2) => localeCompare(value1.text, value2.text)); return result; }; diff --git a/src/pages/workspace/WorkspaceNewRoomPage.tsx b/src/pages/workspace/WorkspaceNewRoomPage.tsx index 73107d7e3eba..1be4e6f486b0 100644 --- a/src/pages/workspace/WorkspaceNewRoomPage.tsx +++ b/src/pages/workspace/WorkspaceNewRoomPage.tsx @@ -23,6 +23,7 @@ import usePrevious from '@hooks/usePrevious'; import useThemeStyles from '@hooks/useThemeStyles'; import useWindowDimensions from '@hooks/useWindowDimensions'; import * as ErrorUtils from '@libs/ErrorUtils'; +import localeCompare from '@libs/LocaleCompare'; import Navigation from '@libs/Navigation/Navigation'; import * as PolicyUtils from '@libs/PolicyUtils'; import * as ReportUtils from '@libs/ReportUtils'; @@ -77,7 +78,7 @@ function WorkspaceNewRoomPage({policies, reports, formState, session, activePoli label: policy.name, value: policy.id, })) - .sort((a, b) => a.label.toLowerCase().localeCompare(b.label.toLowerCase())) ?? [], + .sort((a, b) => localeCompare(a.label, b.label)) ?? [], [policies], ); const [policyID, setPolicyID] = useState(() => { diff --git a/src/pages/workspace/WorkspacesListPage.tsx b/src/pages/workspace/WorkspacesListPage.tsx index 88ea1bf1ec54..d1edf7f2f783 100755 --- a/src/pages/workspace/WorkspacesListPage.tsx +++ b/src/pages/workspace/WorkspacesListPage.tsx @@ -23,6 +23,7 @@ import useNetwork from '@hooks/useNetwork'; import useTheme from '@hooks/useTheme'; import useThemeStyles from '@hooks/useThemeStyles'; import useWindowDimensions from '@hooks/useWindowDimensions'; +import localeCompare from '@libs/LocaleCompare'; import Navigation from '@libs/Navigation/Navigation'; import * as PolicyUtils from '@libs/PolicyUtils'; import * as ReportUtils from '@libs/ReportUtils'; @@ -308,7 +309,7 @@ function WorkspacesListPage({policies, allPolicyMembers, reimbursementAccount, r type: policy.type, }), ) - .sort((a, b) => a.title.toLowerCase().localeCompare(b.title.toLowerCase())); + .sort((a, b) => localeCompare(a.title, b.title)); }, [reimbursementAccount?.errors, policies, isOffline, theme.textLight, allPolicyMembers, policyRooms]); if (isEmptyObject(workspaces)) {