From ff8e3b90e82ee1a7b529f97351c47aa7390ee558 Mon Sep 17 00:00:00 2001 From: dukenv0307 Date: Fri, 2 Jun 2023 23:47:12 +0700 Subject: [PATCH 1/6] Fix page not found appears for a second when user opens a thread --- src/libs/actions/Report.js | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/libs/actions/Report.js b/src/libs/actions/Report.js index 7910f0e5e798..945db6b51b64 100644 --- a/src/libs/actions/Report.js +++ b/src/libs/actions/Report.js @@ -380,6 +380,14 @@ function openReport(reportID, participantList = [], newReportObject = {}, parent params.shouldRetry = false; } + const report = allReports[reportID]; + + // If we open an exist report, but it is not present in Onyx yet, we should change the method to set for this report + // and we need data to be available when we navigate to the chat page + if (_.isEmpty(report)) { + optimisticReportData.onyxMethod = Onyx.METHOD.SET; + } + // If we are creating a new report, we need to add the optimistic report data and a report action if (!_.isEmpty(newReportObject)) { // Change the method to set for new reports because it doesn't exist yet, is faster, From e4ef1de930e8a4389a67ae179222f8a06d017573 Mon Sep 17 00:00:00 2001 From: dukenv0307 Date: Sat, 3 Jun 2023 01:30:41 +0700 Subject: [PATCH 2/6] refactor condition --- src/libs/actions/Report.js | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/libs/actions/Report.js b/src/libs/actions/Report.js index 945db6b51b64..cb3eefda7eb2 100644 --- a/src/libs/actions/Report.js +++ b/src/libs/actions/Report.js @@ -380,11 +380,9 @@ function openReport(reportID, participantList = [], newReportObject = {}, parent params.shouldRetry = false; } - const report = allReports[reportID]; - // If we open an exist report, but it is not present in Onyx yet, we should change the method to set for this report // and we need data to be available when we navigate to the chat page - if (_.isEmpty(report)) { + if (_.isEmpty(allReports[reportID])) { optimisticReportData.onyxMethod = Onyx.METHOD.SET; } From cbe74ba783b39e8ecc092d78004cd481390f6124 Mon Sep 17 00:00:00 2001 From: dukenv0307 Date: Sat, 3 Jun 2023 08:59:22 +0700 Subject: [PATCH 3/6] create get report function --- src/libs/ReportUtils.js | 11 +++++++++++ src/libs/actions/Report.js | 2 +- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/src/libs/ReportUtils.js b/src/libs/ReportUtils.js index 8231886e8632..d1cd77a29971 100644 --- a/src/libs/ReportUtils.js +++ b/src/libs/ReportUtils.js @@ -1041,6 +1041,16 @@ function getReportName(report) { return _.map(participantsWithoutCurrentUser, (login) => getDisplayNameForParticipant(login, isMultipleParticipantReport)).join(', '); } +/** + * Get the report for a reportID + * + * @param {String} reportID + * @returns {Object} + */ +function getReport(reportID) { + return allReports[`${ONYXKEYS.COLLECTION.REPORT}${reportID}`]; +} + /** * Navigate to the details page of a given report * @@ -2182,6 +2192,7 @@ export { getRoomWelcomeMessage, getDisplayNamesWithTooltips, getReportName, + getReport, getReportIDFromLink, getRouteFromLink, navigateToDetailsPage, diff --git a/src/libs/actions/Report.js b/src/libs/actions/Report.js index cb3eefda7eb2..3fed19272708 100644 --- a/src/libs/actions/Report.js +++ b/src/libs/actions/Report.js @@ -382,7 +382,7 @@ function openReport(reportID, participantList = [], newReportObject = {}, parent // If we open an exist report, but it is not present in Onyx yet, we should change the method to set for this report // and we need data to be available when we navigate to the chat page - if (_.isEmpty(allReports[reportID])) { + if (_.isEmpty(ReportUtils.getReport(reportID))) { optimisticReportData.onyxMethod = Onyx.METHOD.SET; } From ba1e2dc0e9494426ed409e5a4c4ca18c884e5019 Mon Sep 17 00:00:00 2001 From: dukenv0307 Date: Sat, 3 Jun 2023 09:49:05 +0700 Subject: [PATCH 4/6] add reportID to optimistic report data --- src/libs/actions/Report.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/libs/actions/Report.js b/src/libs/actions/Report.js index 3fed19272708..65a04eb4cbb8 100644 --- a/src/libs/actions/Report.js +++ b/src/libs/actions/Report.js @@ -384,6 +384,10 @@ function openReport(reportID, participantList = [], newReportObject = {}, parent // and we need data to be available when we navigate to the chat page if (_.isEmpty(ReportUtils.getReport(reportID))) { optimisticReportData.onyxMethod = Onyx.METHOD.SET; + optimisticReportData.value = { + ...optimisticReportData.value, + reportID, + } } // If we are creating a new report, we need to add the optimistic report data and a report action From da206000fe506485ebde7c45980a5a0323b1d3cc Mon Sep 17 00:00:00 2001 From: dukenv0307 Date: Sat, 3 Jun 2023 10:03:55 +0700 Subject: [PATCH 5/6] convert reportID to string --- src/libs/actions/Report.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libs/actions/Report.js b/src/libs/actions/Report.js index 65a04eb4cbb8..038dbfecc654 100644 --- a/src/libs/actions/Report.js +++ b/src/libs/actions/Report.js @@ -386,7 +386,7 @@ function openReport(reportID, participantList = [], newReportObject = {}, parent optimisticReportData.onyxMethod = Onyx.METHOD.SET; optimisticReportData.value = { ...optimisticReportData.value, - reportID, + reportID: reportID.toString(), } } From 5a85f7d0a0265a10f189f363e894b0ab65869909 Mon Sep 17 00:00:00 2001 From: dukenv0307 Date: Sat, 3 Jun 2023 10:14:25 +0700 Subject: [PATCH 6/6] format code --- src/libs/actions/Report.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libs/actions/Report.js b/src/libs/actions/Report.js index 038dbfecc654..dddbf703d6b0 100644 --- a/src/libs/actions/Report.js +++ b/src/libs/actions/Report.js @@ -387,7 +387,7 @@ function openReport(reportID, participantList = [], newReportObject = {}, parent optimisticReportData.value = { ...optimisticReportData.value, reportID: reportID.toString(), - } + }; } // If we are creating a new report, we need to add the optimistic report data and a report action