diff --git a/src/components/OptionListContextProvider.tsx b/src/components/OptionListContextProvider.tsx index 269e67fdd43b..4df741be448a 100644 --- a/src/components/OptionListContextProvider.tsx +++ b/src/components/OptionListContextProvider.tsx @@ -64,28 +64,11 @@ function OptionsListContextProvider({reports, children}: OptionsListProviderProp return; } - const lastUpdatedReports = ReportUtils.getLastUpdatedReports(); - - if (!lastUpdatedReports.length) { - return; - } + const newReports = OptionsListUtils.createOptionList({}, reports).reports; setOptions((prevOptions) => { const newOptions = {...prevOptions}; - lastUpdatedReports.forEach((lastUpdatedReport) => { - if (!lastUpdatedReport) { - return; - } - - const newOption = OptionsListUtils.createOptionFromReport(lastUpdatedReport, personalDetails); - const replaceIndex = options.reports.findIndex((option) => option.reportID === lastUpdatedReport.reportID); - - if (replaceIndex === -1) { - return; - } - - newOptions.reports[replaceIndex] = newOption; - }); + newOptions.reports = newReports; return newOptions; }); // eslint-disable-next-line react-hooks/exhaustive-deps diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index 44286a9c5f14..64b77cae6313 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -570,8 +570,7 @@ Onyx.connect({ }, }); -const MAX_UPDATE_DEPTH = 5; -const lastUpdatedReports: Array> = []; +let lastUpdatedReport: OnyxEntry; Onyx.connect({ key: ONYXKEYS.COLLECTION.REPORT, @@ -580,15 +579,12 @@ Onyx.connect({ return; } - if (lastUpdatedReports.length >= MAX_UPDATE_DEPTH) { - lastUpdatedReports.shift(); - } - lastUpdatedReports.push(value); + lastUpdatedReport = value; }, }); -function getLastUpdatedReports(): Array> { - return lastUpdatedReports; +function getLastUpdatedReport(): OnyxEntry { + return lastUpdatedReport; } function getCurrentUserAvatarOrDefault(): UserUtils.AvatarSource { @@ -6597,7 +6593,7 @@ export { getIcons, getIconsForParticipants, getIndicatedMissingPaymentMethod, - getLastUpdatedReports, + getLastUpdatedReport, getLastVisibleMessage, getMoneyRequestOptions, getMoneyRequestSpendBreakdown,