From ef2f82543fd1c408a1aa6fe0a968bdfc69132b92 Mon Sep 17 00:00:00 2001 From: Srikar Parsi <48188732+srikarparsi@users.noreply.github.com> Date: Mon, 9 Sep 2024 19:38:49 -0400 Subject: [PATCH] Merge pull request #48846 from Expensify/cmartins-sortChatsByDate Sort chats by descending date (cherry picked from commit 37749d3684d3359b52787cc4e1772bbd1d9022a6) (CP triggered by luacmartins) --- src/libs/SearchUtils.ts | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/libs/SearchUtils.ts b/src/libs/SearchUtils.ts index 21d1606bc838..549cdfc3b52d 100644 --- a/src/libs/SearchUtils.ts +++ b/src/libs/SearchUtils.ts @@ -312,7 +312,7 @@ function getSections(type: SearchDataTypes, status: SearchStatus, data: OnyxType function getSortedSections(type: SearchDataTypes, status: SearchStatus, data: ListItemDataType, sortBy?: SearchColumnType, sortOrder?: SortOrder) { if (type === CONST.SEARCH.DATA_TYPES.CHAT) { - return data; + return getSortedReportActionData(data as ReportActionListItemType[]); } return status === CONST.SEARCH.STATUS.EXPENSE.ALL ? getSortedTransactionData(data as TransactionListItemType[], sortBy, sortOrder) : getSortedReportData(data as ReportListItemType[]); } @@ -361,6 +361,19 @@ function getSortedReportData(data: ReportListItemType[]) { }); } +function getSortedReportActionData(data: ReportActionListItemType[]) { + return data.sort((a, b) => { + const aValue = a?.created; + const bValue = b?.created; + + if (aValue === undefined || bValue === undefined) { + return 0; + } + + return bValue.toLowerCase().localeCompare(aValue); + }); +} + function getCurrentSearchParams() { const rootState = navigationRef.getRootState() as State;