From 651ebf6e75d2b9a601f2db8422e6b964c42b726e Mon Sep 17 00:00:00 2001 From: Carlos Martins Date: Mon, 9 Sep 2024 16:14:06 -0600 Subject: [PATCH] sort chats by descending date --- 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 1b1fcaee8682..e4e3bfcc69c5 100644 --- a/src/libs/SearchUtils.ts +++ b/src/libs/SearchUtils.ts @@ -307,7 +307,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[]); } @@ -356,6 +356,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;