From 2fc6f72e41e252749f32f70e2d7acbcae151cf2a Mon Sep 17 00:00:00 2001 From: tienifr Date: Sat, 4 May 2024 15:49:42 +0700 Subject: [PATCH 1/4] deleted workspace room display in task share somewhere --- src/components/OptionListContextProvider.tsx | 15 ++------------- 1 file changed, 2 insertions(+), 13 deletions(-) diff --git a/src/components/OptionListContextProvider.tsx b/src/components/OptionListContextProvider.tsx index 4eef9e93f188..4df741be448a 100644 --- a/src/components/OptionListContextProvider.tsx +++ b/src/components/OptionListContextProvider.tsx @@ -64,22 +64,11 @@ function OptionsListContextProvider({reports, children}: OptionsListProviderProp return; } - const lastUpdatedReport = ReportUtils.getLastUpdatedReport(); - - if (!lastUpdatedReport) { - return; - } - - const newOption = OptionsListUtils.createOptionFromReport(lastUpdatedReport, personalDetails); - const replaceIndex = options.reports.findIndex((option) => option.reportID === lastUpdatedReport.reportID); - - if (replaceIndex === -1) { - return; - } + const newReports = OptionsListUtils.createOptionList({}, reports).reports; setOptions((prevOptions) => { const newOptions = {...prevOptions}; - newOptions.reports[replaceIndex] = newOption; + newOptions.reports = newReports; return newOptions; }); // eslint-disable-next-line react-hooks/exhaustive-deps From 3bbf651928b2d63979e8f18e3b2205dc06c21d0c Mon Sep 17 00:00:00 2001 From: tienifr Date: Mon, 6 May 2024 16:46:21 +0700 Subject: [PATCH 2/4] cache last 5 reports --- src/components/OptionListContextProvider.tsx | 21 ++++++++++++++++++-- src/libs/ReportUtils.ts | 14 ++++++++----- 2 files changed, 28 insertions(+), 7 deletions(-) diff --git a/src/components/OptionListContextProvider.tsx b/src/components/OptionListContextProvider.tsx index 4df741be448a..269e67fdd43b 100644 --- a/src/components/OptionListContextProvider.tsx +++ b/src/components/OptionListContextProvider.tsx @@ -64,11 +64,28 @@ function OptionsListContextProvider({reports, children}: OptionsListProviderProp return; } - const newReports = OptionsListUtils.createOptionList({}, reports).reports; + const lastUpdatedReports = ReportUtils.getLastUpdatedReports(); + + if (!lastUpdatedReports.length) { + return; + } setOptions((prevOptions) => { const newOptions = {...prevOptions}; - newOptions.reports = newReports; + 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; + }); return newOptions; }); // eslint-disable-next-line react-hooks/exhaustive-deps diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index 3451e14e388b..21b3bc46b439 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -557,7 +557,8 @@ Onyx.connect({ }, }); -let lastUpdatedReport: OnyxEntry; +const MAX_UPDATE_DEPTH = 5; +let lastUpdatedReports: Array>; Onyx.connect({ key: ONYXKEYS.COLLECTION.REPORT, @@ -566,12 +567,15 @@ Onyx.connect({ return; } - lastUpdatedReport = value; + if (lastUpdatedReports.length >= MAX_UPDATE_DEPTH) { + lastUpdatedReports.shift(); + } + lastUpdatedReports.push(value); }, }); -function getLastUpdatedReport(): OnyxEntry { - return lastUpdatedReport; +function getLastUpdatedReports(): Array> { + return lastUpdatedReports ?? []; } function getCurrentUserAvatarOrDefault(): UserUtils.AvatarSource { @@ -6544,7 +6548,7 @@ export { getIcons, getIconsForParticipants, getIndicatedMissingPaymentMethod, - getLastUpdatedReport, + getLastUpdatedReports, getLastVisibleMessage, getMoneyRequestOptions, getMoneyRequestSpendBreakdown, From a7a0f2bc8fff73cedc9e8470470de9f4a2615e3b Mon Sep 17 00:00:00 2001 From: tienifr Date: Mon, 6 May 2024 17:11:54 +0700 Subject: [PATCH 3/4] fix test --- src/libs/ReportUtils.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index 21b3bc46b439..bb1b39df8dd9 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -558,7 +558,7 @@ Onyx.connect({ }); const MAX_UPDATE_DEPTH = 5; -let lastUpdatedReports: Array>; +const lastUpdatedReports: Array> = []; Onyx.connect({ key: ONYXKEYS.COLLECTION.REPORT, @@ -575,7 +575,7 @@ Onyx.connect({ }); function getLastUpdatedReports(): Array> { - return lastUpdatedReports ?? []; + return lastUpdatedReports; } function getCurrentUserAvatarOrDefault(): UserUtils.AvatarSource { From c7f128bdb6462fe725b9cc3dfa6f119e7520187f Mon Sep 17 00:00:00 2001 From: tienifr Date: Wed, 8 May 2024 15:50:45 +0700 Subject: [PATCH 4/4] revert: cache last 5 reports --- src/components/OptionListContextProvider.tsx | 21 ++------------------ src/libs/ReportUtils.ts | 14 +++++-------- 2 files changed, 7 insertions(+), 28 deletions(-) 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,