From 7804843840e80f51d15f74adf41fbc86ae4ade70 Mon Sep 17 00:00:00 2001 From: DylanDylann Date: Thu, 16 Nov 2023 16:26:50 +0700 Subject: [PATCH 01/27] fix incorrect group displayed --- .../BaseCentralPaneNavigator.js | 13 ++++++++++++- src/libs/ReportUtils.js | 4 ++++ src/libs/actions/Report.js | 12 ++++++++++++ 3 files changed, 28 insertions(+), 1 deletion(-) diff --git a/src/libs/Navigation/AppNavigator/Navigators/CentralPaneNavigator/BaseCentralPaneNavigator.js b/src/libs/Navigation/AppNavigator/Navigators/CentralPaneNavigator/BaseCentralPaneNavigator.js index a1646011e560..5e4b916342d5 100644 --- a/src/libs/Navigation/AppNavigator/Navigators/CentralPaneNavigator/BaseCentralPaneNavigator.js +++ b/src/libs/Navigation/AppNavigator/Navigators/CentralPaneNavigator/BaseCentralPaneNavigator.js @@ -1,8 +1,10 @@ import {createStackNavigator} from '@react-navigation/stack'; +import lodashGet from 'lodash/get'; import React from 'react'; import ReportScreenWrapper from '@libs/Navigation/AppNavigator/ReportScreenWrapper'; import getCurrentUrl from '@libs/Navigation/currentUrl'; import styles from '@styles/styles'; +import * as Report from '@userActions/Report'; import SCREENS from '@src/SCREENS'; const Stack = createStackNavigator(); @@ -12,7 +14,16 @@ const openOnAdminRoom = url ? new URL(url).searchParams.get('openOnAdminRoom') : function BaseCentralPaneNavigator() { return ( - + { + const reportID = lodashGet(e, 'data.state.routes[0].params.reportID', ''); + if (reportID) { + Report.updateLastVisitTime(reportID); + } + }, + }} + > { + const lastReadTime = lodashGet(report, 'lastVisitTime') || lodashGet(report, 'lastReadTime'); + return {...report, lastReadTime}; + }) .toArray() .filter((report) => report && report.reportID && report.lastReadTime) .sortBy('lastReadTime') diff --git a/src/libs/actions/Report.js b/src/libs/actions/Report.js index 22a1bc5441e6..55d6a5c242d7 100644 --- a/src/libs/actions/Report.js +++ b/src/libs/actions/Report.js @@ -2503,6 +2503,17 @@ function searchInServer(searchInput) { debouncedSearchInServer(searchInput); } +/** + * @param {String} reportID + */ + +function updateLastVisitTime(reportID) { + if (!ReportUtils.isValidReportIDFromPath(reportID)) { + return; + } + Onyx.merge(`${ONYXKEYS.COLLECTION.REPORT}${reportID}`, {lastVisitTime: DateUtils.getDBTime()}); +} + export { searchInServer, addComment, @@ -2564,4 +2575,5 @@ export { openRoomMembersPage, savePrivateNotesDraft, getDraftPrivateNote, + updateLastVisitTime, }; From 2252f7ca2d08462adca23201c6be65d591de36cd Mon Sep 17 00:00:00 2001 From: DylanDylann Date: Fri, 24 Nov 2023 05:51:00 +0700 Subject: [PATCH 02/27] fix merge main --- .../BaseCentralPaneNavigator.js | 13 +------------ src/pages/home/ReportScreen.js | 8 ++++++++ 2 files changed, 9 insertions(+), 12 deletions(-) diff --git a/src/libs/Navigation/AppNavigator/Navigators/CentralPaneNavigator/BaseCentralPaneNavigator.js b/src/libs/Navigation/AppNavigator/Navigators/CentralPaneNavigator/BaseCentralPaneNavigator.js index 5e4b916342d5..a1646011e560 100644 --- a/src/libs/Navigation/AppNavigator/Navigators/CentralPaneNavigator/BaseCentralPaneNavigator.js +++ b/src/libs/Navigation/AppNavigator/Navigators/CentralPaneNavigator/BaseCentralPaneNavigator.js @@ -1,10 +1,8 @@ import {createStackNavigator} from '@react-navigation/stack'; -import lodashGet from 'lodash/get'; import React from 'react'; import ReportScreenWrapper from '@libs/Navigation/AppNavigator/ReportScreenWrapper'; import getCurrentUrl from '@libs/Navigation/currentUrl'; import styles from '@styles/styles'; -import * as Report from '@userActions/Report'; import SCREENS from '@src/SCREENS'; const Stack = createStackNavigator(); @@ -14,16 +12,7 @@ const openOnAdminRoom = url ? new URL(url).searchParams.get('openOnAdminRoom') : function BaseCentralPaneNavigator() { return ( - { - const reportID = lodashGet(e, 'data.state.routes[0].params.reportID', ''); - if (reportID) { - Report.updateLastVisitTime(reportID); - } - }, - }} - > + { + if (!reportID) { + return; + } + Report.updateLastVisitTime(reportID); + }, [reportID]); + const {addWorkspaceRoomOrChatPendingAction, addWorkspaceRoomOrChatErrors} = ReportUtils.getReportOfflinePendingActionAndErrors(report); const screenWrapperStyle = [styles.appContent, styles.flex1, {marginTop: viewportOffsetTop}]; From cb0782fcd9b168ca0aef906396baabb416b2a82e Mon Sep 17 00:00:00 2001 From: DylanDylann Date: Mon, 27 Nov 2023 19:19:09 +0700 Subject: [PATCH 03/27] fix does not update timestamp with empty report --- src/pages/home/ReportScreen.js | 10 +++++----- src/pages/home/report/ReportFooter.js | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/pages/home/ReportScreen.js b/src/pages/home/ReportScreen.js index 92d81a0fae10..3bf8887f1b32 100644 --- a/src/pages/home/ReportScreen.js +++ b/src/pages/home/ReportScreen.js @@ -1,3 +1,4 @@ +import {useIsFocused} from '@react-navigation/native'; import lodashGet from 'lodash/get'; import PropTypes from 'prop-types'; import React, {useCallback, useEffect, useMemo, useRef, useState} from 'react'; @@ -161,12 +162,13 @@ function ReportScreen({ const reportID = getReportID(route); + const isFocused = useIsFocused(); useEffect(() => { - if (!reportID) { + if (!report.reportID || !isFocused) { return; } - Report.updateLastVisitTime(reportID); - }, [reportID]); + Report.updateLastVisitTime(report.reportID); + }, [report.reportID, isFocused]); const {addWorkspaceRoomOrChatPendingAction, addWorkspaceRoomOrChatErrors} = ReportUtils.getReportOfflinePendingActionAndErrors(report); const screenWrapperStyle = [styles.appContent, styles.flex1, {marginTop: viewportOffsetTop}]; @@ -240,7 +242,6 @@ function ReportScreen({ const fetchReportIfNeeded = useCallback(() => { const reportIDFromPath = getReportID(route); - // Report ID will be empty when the reports collection is empty. // This could happen when we are loading the collection for the first time after logging in. if (!ReportUtils.isValidReportIDFromPath(reportIDFromPath)) { @@ -253,7 +254,6 @@ function ReportScreen({ if (report.reportID && report.reportID === getReportID(route) && !isLoadingInitialReportActions) { return; } - Report.openReport(reportIDFromPath); }, [report.reportID, route, isLoadingInitialReportActions]); diff --git a/src/pages/home/report/ReportFooter.js b/src/pages/home/report/ReportFooter.js index e5dd5da19ad5..a3bd27cff160 100644 --- a/src/pages/home/report/ReportFooter.js +++ b/src/pages/home/report/ReportFooter.js @@ -72,7 +72,7 @@ function ReportFooter(props) { const isSmallSizeLayout = props.windowWidth - (props.isSmallScreenWidth ? 0 : variables.sideBarWidth) < variables.anonymousReportFooterBreakpoint; const hideComposer = !ReportUtils.canUserPerformWriteAction(props.report); - + return ( <> {hideComposer && ( From 798897370283911fc66b8ee38e3a45083a63f2e6 Mon Sep 17 00:00:00 2001 From: DylanDylann Date: Tue, 28 Nov 2023 20:50:28 +0700 Subject: [PATCH 04/27] fix lint --- src/pages/home/report/ReportFooter.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pages/home/report/ReportFooter.js b/src/pages/home/report/ReportFooter.js index a3bd27cff160..e5dd5da19ad5 100644 --- a/src/pages/home/report/ReportFooter.js +++ b/src/pages/home/report/ReportFooter.js @@ -72,7 +72,7 @@ function ReportFooter(props) { const isSmallSizeLayout = props.windowWidth - (props.isSmallScreenWidth ? 0 : variables.sideBarWidth) < variables.anonymousReportFooterBreakpoint; const hideComposer = !ReportUtils.canUserPerformWriteAction(props.report); - + return ( <> {hideComposer && ( From 87f5f0e847c0147cd0fe688a70e32b91ad409d75 Mon Sep 17 00:00:00 2001 From: DylanDylann Date: Thu, 30 Nov 2023 22:46:30 +0700 Subject: [PATCH 05/27] fix add comment --- src/pages/home/ReportScreen.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/pages/home/ReportScreen.js b/src/pages/home/ReportScreen.js index 09e15db06c02..51707033cce5 100644 --- a/src/pages/home/ReportScreen.js +++ b/src/pages/home/ReportScreen.js @@ -167,7 +167,10 @@ function ReportScreen({ const reportID = getReportID(route); const isFocused = useIsFocused(); + + // Update the lastVisitTime when the report is focused useEffect(() => { + // We don't want to update the lastVisitTime if the report did not exist or if the report is not focused if (!report.reportID || !isFocused) { return; } From cadc71648498b30cbde5b9beb014cd3728ede69a Mon Sep 17 00:00:00 2001 From: DylanDylann Date: Thu, 30 Nov 2023 22:56:23 +0700 Subject: [PATCH 06/27] fix add comment --- src/pages/home/ReportScreen.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/pages/home/ReportScreen.js b/src/pages/home/ReportScreen.js index 51707033cce5..6b5cd213d916 100644 --- a/src/pages/home/ReportScreen.js +++ b/src/pages/home/ReportScreen.js @@ -168,9 +168,9 @@ function ReportScreen({ const isFocused = useIsFocused(); - // Update the lastVisitTime when the report is focused + // We need to update the lastVisitTime every time the report is focused + // because lastReadTime does not have up-to-date time stamp every time the user visits a report. useEffect(() => { - // We don't want to update the lastVisitTime if the report did not exist or if the report is not focused if (!report.reportID || !isFocused) { return; } From 410e3d44e1e6725cb1c6182eb29cf1ff660225f6 Mon Sep 17 00:00:00 2001 From: DylanDylann Date: Fri, 1 Dec 2023 21:29:48 +0700 Subject: [PATCH 07/27] fix add comments to logic --- src/libs/actions/Report.js | 1 - src/pages/home/ReportScreen.js | 2 +- src/types/onyx/Report.ts | 2 +- 3 files changed, 2 insertions(+), 3 deletions(-) diff --git a/src/libs/actions/Report.js b/src/libs/actions/Report.js index 72f2b79081e1..6dd1fdc57d04 100644 --- a/src/libs/actions/Report.js +++ b/src/libs/actions/Report.js @@ -2505,7 +2505,6 @@ function searchInServer(searchInput) { /** * @param {String} reportID */ - function updateLastVisitTime(reportID) { if (!ReportUtils.isValidReportIDFromPath(reportID)) { return; diff --git a/src/pages/home/ReportScreen.js b/src/pages/home/ReportScreen.js index 392d840528a1..4a99ec0e2bab 100644 --- a/src/pages/home/ReportScreen.js +++ b/src/pages/home/ReportScreen.js @@ -170,7 +170,7 @@ function ReportScreen({ const isFocused = useIsFocused(); // We need to update the lastVisitTime every time the report is focused - // because lastReadTime does not have up-to-date time stamp every time the user visits a report. + // because lastReadTime is not updated every time the user visits a report. useEffect(() => { if (!report.reportID || !isFocused) { return; diff --git a/src/types/onyx/Report.ts b/src/types/onyx/Report.ts index dd244e9a3754..2a5e91a6de34 100644 --- a/src/types/onyx/Report.ts +++ b/src/types/onyx/Report.ts @@ -34,7 +34,7 @@ type Report = { /** The time of the last read of the report */ lastReadCreated?: string; - /** The last time the report was visited */ + /** The time when user read the last message */ lastReadTime?: string; /** The time of the last visit of the report */ From 5a89b4118aea1d41ac926222cf435f212989dc2a Mon Sep 17 00:00:00 2001 From: DylanDylann Date: Fri, 1 Dec 2023 22:15:23 +0700 Subject: [PATCH 08/27] fix additional space --- src/pages/home/ReportScreen.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/pages/home/ReportScreen.js b/src/pages/home/ReportScreen.js index 4a99ec0e2bab..631aa4b9808a 100644 --- a/src/pages/home/ReportScreen.js +++ b/src/pages/home/ReportScreen.js @@ -250,6 +250,7 @@ function ReportScreen({ const fetchReportIfNeeded = useCallback(() => { const reportIDFromPath = getReportID(route); + // Report ID will be empty when the reports collection is empty. // This could happen when we are loading the collection for the first time after logging in. if (!ReportUtils.isValidReportIDFromPath(reportIDFromPath)) { @@ -262,6 +263,7 @@ function ReportScreen({ if (report.reportID && report.reportID === getReportID(route) && !isLoadingInitialReportActions) { return; } + Report.openReport(reportIDFromPath); }, [report.reportID, route, isLoadingInitialReportActions]); From 335527917346b753059ee13867517c078a6ae5bd Mon Sep 17 00:00:00 2001 From: DylanDylann Date: Sat, 2 Dec 2023 00:24:34 +0700 Subject: [PATCH 09/27] fix try to fix performance issue --- src/libs/OnyxSelectors/reportWithoutHasDraftSelector.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/libs/OnyxSelectors/reportWithoutHasDraftSelector.ts b/src/libs/OnyxSelectors/reportWithoutHasDraftSelector.ts index 9fd89cfdf146..d78a26ba52c1 100644 --- a/src/libs/OnyxSelectors/reportWithoutHasDraftSelector.ts +++ b/src/libs/OnyxSelectors/reportWithoutHasDraftSelector.ts @@ -5,5 +5,6 @@ export default function reportWithoutHasDraftSelector(report: OnyxKeyValue<'repo return report; } const {hasDraft, ...reportWithoutHasDraft} = report; - return reportWithoutHasDraft; + const {lastVisitTime, ...reportWithoutHasDraftAndLastVisitTime} = reportWithoutHasDraft; + return reportWithoutHasDraftAndLastVisitTime; } From 6ac934c65b6e841d7a8ea23ed54314dad8dd846c Mon Sep 17 00:00:00 2001 From: DylanDylann Date: Tue, 5 Dec 2023 23:15:11 +0700 Subject: [PATCH 10/27] fix try to fix performance regression --- .../OnyxSelectors/reportWithoutHasDraftSelector.ts | 3 +-- src/libs/actions/Report.js | 7 +++++++ src/pages/home/ReportScreen.js | 12 ------------ src/pages/home/report/ReportActionsView.js | 1 + 4 files changed, 9 insertions(+), 14 deletions(-) diff --git a/src/libs/OnyxSelectors/reportWithoutHasDraftSelector.ts b/src/libs/OnyxSelectors/reportWithoutHasDraftSelector.ts index d78a26ba52c1..9fd89cfdf146 100644 --- a/src/libs/OnyxSelectors/reportWithoutHasDraftSelector.ts +++ b/src/libs/OnyxSelectors/reportWithoutHasDraftSelector.ts @@ -5,6 +5,5 @@ export default function reportWithoutHasDraftSelector(report: OnyxKeyValue<'repo return report; } const {hasDraft, ...reportWithoutHasDraft} = report; - const {lastVisitTime, ...reportWithoutHasDraftAndLastVisitTime} = reportWithoutHasDraft; - return reportWithoutHasDraftAndLastVisitTime; + return reportWithoutHasDraft; } diff --git a/src/libs/actions/Report.js b/src/libs/actions/Report.js index d88a3a0f8495..3f8175c6ca60 100644 --- a/src/libs/actions/Report.js +++ b/src/libs/actions/Report.js @@ -489,6 +489,13 @@ function openReport(reportID, participantLoginList = [], newReportObject = {}, p isLoadingNewerReportActions: false, }, }, + { + onyxMethod: Onyx.METHOD.MERGE, + key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${reportID}`, + value: { + lastVisitTime: DateUtils.getDBTime(), + }, + }, ]; const reportSuccessData = [ diff --git a/src/pages/home/ReportScreen.js b/src/pages/home/ReportScreen.js index 92a6a99d16e7..d9ccad121f74 100644 --- a/src/pages/home/ReportScreen.js +++ b/src/pages/home/ReportScreen.js @@ -1,4 +1,3 @@ -import {useIsFocused} from '@react-navigation/native'; import lodashGet from 'lodash/get'; import PropTypes from 'prop-types'; import React, {useCallback, useEffect, useMemo, useRef, useState} from 'react'; @@ -167,17 +166,6 @@ function ReportScreen({ const reportID = getReportID(route); - const isFocused = useIsFocused(); - - // We need to update the lastVisitTime every time the report is focused - // because lastReadTime is not updated every time the user visits a report. - useEffect(() => { - if (!report.reportID || !isFocused) { - return; - } - Report.updateLastVisitTime(report.reportID); - }, [report.reportID, isFocused]); - const {addWorkspaceRoomOrChatPendingAction, addWorkspaceRoomOrChatErrors} = ReportUtils.getReportOfflinePendingActionAndErrors(report); const screenWrapperStyle = [styles.appContent, styles.flex1, {marginTop: viewportOffsetTop}]; diff --git a/src/pages/home/report/ReportActionsView.js b/src/pages/home/report/ReportActionsView.js index 607d98039070..8ba4bedf197b 100755 --- a/src/pages/home/report/ReportActionsView.js +++ b/src/pages/home/report/ReportActionsView.js @@ -106,6 +106,7 @@ function ReportActionsView(props) { const createChatError = _.get(props.report, ['errorFields', 'createChat']); // If the report is optimistic (AKA not yet created) we don't need to call openReport again if (props.report.isOptimisticReport || !_.isEmpty(createChatError)) { + Report.updateLastVisitTime(reportID); return; } From 9ae4d5bd07b1929789e043fa73d3a642c1f3549c Mon Sep 17 00:00:00 2001 From: DylanDylann Date: Tue, 5 Dec 2023 23:17:33 +0700 Subject: [PATCH 11/27] fix remove space --- src/pages/home/ReportScreen.js | 1 - 1 file changed, 1 deletion(-) diff --git a/src/pages/home/ReportScreen.js b/src/pages/home/ReportScreen.js index d9ccad121f74..e9b79c41dcd7 100644 --- a/src/pages/home/ReportScreen.js +++ b/src/pages/home/ReportScreen.js @@ -165,7 +165,6 @@ function ReportScreen({ const [scrollPosition, setScrollPosition] = useState({}); const reportID = getReportID(route); - const {addWorkspaceRoomOrChatPendingAction, addWorkspaceRoomOrChatErrors} = ReportUtils.getReportOfflinePendingActionAndErrors(report); const screenWrapperStyle = [styles.appContent, styles.flex1, {marginTop: viewportOffsetTop}]; From 8423ed6ab7fe7f5630f2671ff51e12d8b921b080 Mon Sep 17 00:00:00 2001 From: DylanDylann Date: Wed, 6 Dec 2023 00:02:59 +0700 Subject: [PATCH 12/27] fix update when going back --- src/pages/home/report/ReportActionsView.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/pages/home/report/ReportActionsView.js b/src/pages/home/report/ReportActionsView.js index 8ba4bedf197b..ff00d260accc 100755 --- a/src/pages/home/report/ReportActionsView.js +++ b/src/pages/home/report/ReportActionsView.js @@ -114,9 +114,12 @@ function ReportActionsView(props) { }; useEffect(() => { + if (!isFocused) { + return; + } openReportIfNecessary(); // eslint-disable-next-line react-hooks/exhaustive-deps - }, []); + }, [isFocused]); useEffect(() => { const prevNetwork = prevNetworkRef.current; From 7cd02ab669c9abe45e76418d3a40380fabdecfc0 Mon Sep 17 00:00:00 2001 From: DylanDylann Date: Wed, 6 Dec 2023 00:33:03 +0700 Subject: [PATCH 13/27] fix jest test 1 --- src/libs/actions/Report.js | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/src/libs/actions/Report.js b/src/libs/actions/Report.js index 3f8175c6ca60..0f8219ebf0db 100644 --- a/src/libs/actions/Report.js +++ b/src/libs/actions/Report.js @@ -475,9 +475,10 @@ function openReport(reportID, participantLoginList = [], newReportObject = {}, p onyxMethod: Onyx.METHOD.MERGE, key: `${ONYXKEYS.COLLECTION.REPORT}${reportID}`, value: reportActionsExist(reportID) - ? {} + ? {lastVisitTime: DateUtils.getDBTime()} : { reportName: lodashGet(allReports, [reportID, 'reportName'], CONST.REPORT.DEFAULT_REPORT_NAME), + lastVisitTime: DateUtils.getDBTime(), }, }, { @@ -489,13 +490,6 @@ function openReport(reportID, participantLoginList = [], newReportObject = {}, p isLoadingNewerReportActions: false, }, }, - { - onyxMethod: Onyx.METHOD.MERGE, - key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${reportID}`, - value: { - lastVisitTime: DateUtils.getDBTime(), - }, - }, ]; const reportSuccessData = [ From 4da05209df8ac70fcd7da57596ec625ff94dd83f Mon Sep 17 00:00:00 2001 From: DylanDylann Date: Wed, 6 Dec 2023 00:35:13 +0700 Subject: [PATCH 14/27] fix jest test 1 --- src/libs/actions/Report.js | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/libs/actions/Report.js b/src/libs/actions/Report.js index 0f8219ebf0db..0458186b78ae 100644 --- a/src/libs/actions/Report.js +++ b/src/libs/actions/Report.js @@ -475,10 +475,9 @@ function openReport(reportID, participantLoginList = [], newReportObject = {}, p onyxMethod: Onyx.METHOD.MERGE, key: `${ONYXKEYS.COLLECTION.REPORT}${reportID}`, value: reportActionsExist(reportID) - ? {lastVisitTime: DateUtils.getDBTime()} + ? {} : { reportName: lodashGet(allReports, [reportID, 'reportName'], CONST.REPORT.DEFAULT_REPORT_NAME), - lastVisitTime: DateUtils.getDBTime(), }, }, { @@ -490,6 +489,13 @@ function openReport(reportID, participantLoginList = [], newReportObject = {}, p isLoadingNewerReportActions: false, }, }, + { + onyxMethod: Onyx.METHOD.MERGE, + key: `${ONYXKEYS.COLLECTION.REPORT}${reportID}`, + value: { + lastVisitTime: DateUtils.getDBTime(), + }, + }, ]; const reportSuccessData = [ From 07f8ea566e40e422cafccf0eaae8facbe987465f Mon Sep 17 00:00:00 2001 From: DylanDylann Date: Wed, 6 Dec 2023 00:51:33 +0700 Subject: [PATCH 15/27] fix disable update timestamp when back --- src/pages/home/report/ReportActionsView.js | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/pages/home/report/ReportActionsView.js b/src/pages/home/report/ReportActionsView.js index ff00d260accc..8ba4bedf197b 100755 --- a/src/pages/home/report/ReportActionsView.js +++ b/src/pages/home/report/ReportActionsView.js @@ -114,12 +114,9 @@ function ReportActionsView(props) { }; useEffect(() => { - if (!isFocused) { - return; - } openReportIfNecessary(); // eslint-disable-next-line react-hooks/exhaustive-deps - }, [isFocused]); + }, []); useEffect(() => { const prevNetwork = prevNetworkRef.current; From 37f11e570f05e35784fd2e96e924a6dc11f205f3 Mon Sep 17 00:00:00 2001 From: DylanDylann Date: Wed, 6 Dec 2023 01:24:07 +0700 Subject: [PATCH 16/27] fix performance regression --- src/libs/actions/Report.js | 10 ++-------- src/pages/home/report/ReportActionsView.js | 5 ++++- 2 files changed, 6 insertions(+), 9 deletions(-) diff --git a/src/libs/actions/Report.js b/src/libs/actions/Report.js index 0458186b78ae..0f8219ebf0db 100644 --- a/src/libs/actions/Report.js +++ b/src/libs/actions/Report.js @@ -475,9 +475,10 @@ function openReport(reportID, participantLoginList = [], newReportObject = {}, p onyxMethod: Onyx.METHOD.MERGE, key: `${ONYXKEYS.COLLECTION.REPORT}${reportID}`, value: reportActionsExist(reportID) - ? {} + ? {lastVisitTime: DateUtils.getDBTime()} : { reportName: lodashGet(allReports, [reportID, 'reportName'], CONST.REPORT.DEFAULT_REPORT_NAME), + lastVisitTime: DateUtils.getDBTime(), }, }, { @@ -489,13 +490,6 @@ function openReport(reportID, participantLoginList = [], newReportObject = {}, p isLoadingNewerReportActions: false, }, }, - { - onyxMethod: Onyx.METHOD.MERGE, - key: `${ONYXKEYS.COLLECTION.REPORT}${reportID}`, - value: { - lastVisitTime: DateUtils.getDBTime(), - }, - }, ]; const reportSuccessData = [ diff --git a/src/pages/home/report/ReportActionsView.js b/src/pages/home/report/ReportActionsView.js index 8ba4bedf197b..ff00d260accc 100755 --- a/src/pages/home/report/ReportActionsView.js +++ b/src/pages/home/report/ReportActionsView.js @@ -114,9 +114,12 @@ function ReportActionsView(props) { }; useEffect(() => { + if (!isFocused) { + return; + } openReportIfNecessary(); // eslint-disable-next-line react-hooks/exhaustive-deps - }, []); + }, [isFocused]); useEffect(() => { const prevNetwork = prevNetworkRef.current; From 34dc79ff7ccda8530fa7b99662baf552acada55e Mon Sep 17 00:00:00 2001 From: DylanDylann Date: Wed, 6 Dec 2023 09:19:06 +0700 Subject: [PATCH 17/27] fix reassure error --- src/pages/home/report/ReportActionsView.js | 8 -------- 1 file changed, 8 deletions(-) diff --git a/src/pages/home/report/ReportActionsView.js b/src/pages/home/report/ReportActionsView.js index ff00d260accc..60fc38776d2a 100755 --- a/src/pages/home/report/ReportActionsView.js +++ b/src/pages/home/report/ReportActionsView.js @@ -113,14 +113,6 @@ function ReportActionsView(props) { Report.openReport(reportID); }; - useEffect(() => { - if (!isFocused) { - return; - } - openReportIfNecessary(); - // eslint-disable-next-line react-hooks/exhaustive-deps - }, [isFocused]); - useEffect(() => { const prevNetwork = prevNetworkRef.current; // When returning from offline to online state we want to trigger a request to OpenReport which From 32400c42394560b02363c9324f49d6d2c16789f5 Mon Sep 17 00:00:00 2001 From: DylanDylann Date: Wed, 6 Dec 2023 09:27:17 +0700 Subject: [PATCH 18/27] fix reassure regression --- src/pages/home/report/ReportActionsView.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/pages/home/report/ReportActionsView.js b/src/pages/home/report/ReportActionsView.js index 60fc38776d2a..8ba4bedf197b 100755 --- a/src/pages/home/report/ReportActionsView.js +++ b/src/pages/home/report/ReportActionsView.js @@ -113,6 +113,11 @@ function ReportActionsView(props) { Report.openReport(reportID); }; + useEffect(() => { + openReportIfNecessary(); + // eslint-disable-next-line react-hooks/exhaustive-deps + }, []); + useEffect(() => { const prevNetwork = prevNetworkRef.current; // When returning from offline to online state we want to trigger a request to OpenReport which From b80d70e3cc1dc4e3e5f14e0043e7debfc138d48b Mon Sep 17 00:00:00 2001 From: DylanDylann Date: Fri, 15 Dec 2023 15:58:32 +0700 Subject: [PATCH 19/27] fix merge main --- .../AppNavigator/ReportScreenIDSetter.ts | 17 ++++++++++++----- src/libs/ReportUtils.ts | 15 +++++++++------ src/libs/actions/Report.ts | 13 ++----------- src/pages/home/ReportScreen.js | 10 ++++++++++ src/pages/home/report/ReportActionsView.js | 1 - src/types/onyx/Report.ts | 3 --- src/types/onyx/ReportMetadata.ts | 3 +++ 7 files changed, 36 insertions(+), 26 deletions(-) diff --git a/src/libs/Navigation/AppNavigator/ReportScreenIDSetter.ts b/src/libs/Navigation/AppNavigator/ReportScreenIDSetter.ts index 8be512962981..380c193500fc 100644 --- a/src/libs/Navigation/AppNavigator/ReportScreenIDSetter.ts +++ b/src/libs/Navigation/AppNavigator/ReportScreenIDSetter.ts @@ -4,7 +4,7 @@ import usePermissions from '@hooks/usePermissions'; import * as ReportUtils from '@libs/ReportUtils'; import * as App from '@userActions/App'; import ONYXKEYS from '@src/ONYXKEYS'; -import type {Policy, Report} from '@src/types/onyx'; +import type {Policy, Report, ReportMetadata} from '@src/types/onyx'; import type {ReportScreenWrapperProps} from './ReportScreenWrapper'; type ReportScreenIDSetterComponentProps = { @@ -16,6 +16,9 @@ type ReportScreenIDSetterComponentProps = { /** Whether user is a new user */ isFirstTimeNewExpensifyUser: OnyxEntry; + + /** */ + reportsMetadata: OnyxCollection; }; type ReportScreenIDSetterProps = ReportScreenIDSetterComponentProps & ReportScreenWrapperProps; @@ -29,15 +32,15 @@ const getLastAccessedReportID = ( policies: OnyxCollection, isFirstTimeNewExpensifyUser: OnyxEntry, openOnAdminRoom: boolean, + reportsMetadata: OnyxCollection, ): string | undefined => { - const lastReport = ReportUtils.findLastAccessedReport(reports, ignoreDefaultRooms, policies, !!isFirstTimeNewExpensifyUser, openOnAdminRoom); + const lastReport = ReportUtils.findLastAccessedReport(reports, ignoreDefaultRooms, policies, !!isFirstTimeNewExpensifyUser, openOnAdminRoom, reportsMetadata); return lastReport?.reportID; }; // This wrapper is reponsible for opening the last accessed report if there is no reportID specified in the route params -function ReportScreenIDSetter({route, reports, policies, navigation, isFirstTimeNewExpensifyUser = false}: ReportScreenIDSetterProps) { +function ReportScreenIDSetter({route, reports, policies, navigation, isFirstTimeNewExpensifyUser = false, reportsMetadata}: ReportScreenIDSetterProps) { const {canUseDefaultRooms} = usePermissions(); - useEffect(() => { // Don't update if there is a reportID in the params already if (route?.params?.reportID) { @@ -46,7 +49,7 @@ function ReportScreenIDSetter({route, reports, policies, navigation, isFirstTime } // If there is no reportID in route, try to find last accessed and use it for setParams - const reportID = getLastAccessedReportID(reports, !canUseDefaultRooms, policies, isFirstTimeNewExpensifyUser, !!reports?.params?.openOnAdminRoom); + const reportID = getLastAccessedReportID(reports, !canUseDefaultRooms, policies, isFirstTimeNewExpensifyUser, !!reports?.params?.openOnAdminRoom, reportsMetadata); // It's possible that reports aren't fully loaded yet // in that case the reportID is undefined @@ -77,4 +80,8 @@ export default withOnyx): boolean { /** * Given a collection of reports returns them sorted by last read */ -function sortReportsByLastRead(reports: OnyxCollection): Array> { +function sortReportsByLastRead(reports: OnyxCollection, reportsMetadata: OnyxCollection): Array> { return Object.values(reports ?? {}) - .filter((report) => !!report?.reportID && (!!report?.lastVisitTime || !!report?.lastReadTime)) + .filter( + (report) => !!report?.reportID && ((reportsMetadata && !!reportsMetadata[`${ONYXKEYS.COLLECTION.REPORT_METADATA}${report.reportID}`]?.lastVisitTime) || !!report?.lastReadTime), + ) .sort((a, b) => { - const aTime = new Date(a?.lastVisitTime ?? a?.lastReadTime ?? ''); - const bTime = new Date(b?.lastVisitTime ?? b?.lastReadTime ?? ''); + const aTime = new Date((reportsMetadata && a && reportsMetadata[`${ONYXKEYS.COLLECTION.REPORT_METADATA}${a.reportID}`]?.lastVisitTime) ?? a?.lastReadTime ?? ''); + const bTime = new Date((reportsMetadata && b && reportsMetadata[`${ONYXKEYS.COLLECTION.REPORT_METADATA}${b.reportID}`]?.lastVisitTime) ?? b?.lastReadTime ?? ''); return aTime.valueOf() - bTime.valueOf(); }); @@ -839,13 +841,14 @@ function findLastAccessedReport( policies: OnyxCollection, isFirstTimeNewExpensifyUser: boolean, openOnAdminRoom = false, + reportsMetadata: OnyxCollection, ): OnyxEntry { // If it's the user's first time using New Expensify, then they could either have: // - just a Concierge report, if so we'll return that // - their Concierge report, and a separate report that must have deeplinked them to the app before they created their account. // If it's the latter, we'll use the deeplinked report over the Concierge report, // since the Concierge report would be incorrectly selected over the deep-linked report in the logic below. - let sortedReports = sortReportsByLastRead(reports); + let sortedReports = sortReportsByLastRead(reports, reportsMetadata); let adminReport: OnyxEntry | undefined; if (openOnAdminRoom) { diff --git a/src/libs/actions/Report.ts b/src/libs/actions/Report.ts index ec460a54f1ee..7aa3f4e50f71 100644 --- a/src/libs/actions/Report.ts +++ b/src/libs/actions/Report.ts @@ -497,12 +497,6 @@ function openReport( isLoadingInitialReportActions: true, isLoadingOlderReportActions: false, isLoadingNewerReportActions: false, - }, - }, - { - onyxMethod: Onyx.METHOD.MERGE, - key: `${ONYXKEYS.COLLECTION.REPORT}${reportID}`, - value: { lastVisitTime: DateUtils.getDBTime(), }, }, @@ -2524,14 +2518,11 @@ function searchInServer(searchInput: string) { debouncedSearchInServer(searchInput); } -/** - * @param {String} reportID - */ -function updateLastVisitTime(reportID) { +function updateLastVisitTime(reportID: string) { if (!ReportUtils.isValidReportIDFromPath(reportID)) { return; } - Onyx.merge(`${ONYXKEYS.COLLECTION.REPORT}${reportID}`, {lastVisitTime: DateUtils.getDBTime()}); + Onyx.merge(`${ONYXKEYS.COLLECTION.REPORT_METADATA}${reportID}`, {lastVisitTime: DateUtils.getDBTime()}); } function clearNewRoomFormError() { diff --git a/src/pages/home/ReportScreen.js b/src/pages/home/ReportScreen.js index c910f170cc2b..36759a544d2c 100644 --- a/src/pages/home/ReportScreen.js +++ b/src/pages/home/ReportScreen.js @@ -1,3 +1,4 @@ +import {useIsFocused} from '@react-navigation/native'; import lodashGet from 'lodash/get'; import PropTypes from 'prop-types'; import React, {useCallback, useEffect, useMemo, useRef, useState} from 'react'; @@ -238,6 +239,15 @@ function ReportScreen({ return reportIDFromPath !== '' && report.reportID && !isTransitioning; }, [route, report]); + const isFocused = useIsFocused(); + useEffect(() => { + if (!report.reportID || !isFocused) { + return; + } + console.log("////////", report.reportID) + Report.updateLastVisitTime(report.reportID); + }, [report.reportID, isFocused]); + const fetchReportIfNeeded = useCallback(() => { const reportIDFromPath = getReportID(route); diff --git a/src/pages/home/report/ReportActionsView.js b/src/pages/home/report/ReportActionsView.js index 6d0891fa2a81..2758437a3962 100755 --- a/src/pages/home/report/ReportActionsView.js +++ b/src/pages/home/report/ReportActionsView.js @@ -107,7 +107,6 @@ function ReportActionsView(props) { const createChatError = _.get(props.report, ['errorFields', 'createChat']); // If the report is optimistic (AKA not yet created) we don't need to call openReport again if (props.report.isOptimisticReport || !_.isEmpty(createChatError)) { - Report.updateLastVisitTime(reportID); return; } diff --git a/src/types/onyx/Report.ts b/src/types/onyx/Report.ts index 5fffaa9f032a..9d3e011d1a60 100644 --- a/src/types/onyx/Report.ts +++ b/src/types/onyx/Report.ts @@ -47,9 +47,6 @@ type Report = { /** The time when user read the last message */ lastReadTime?: string; - /** The time of the last visit of the report */ - lastVisitTime?: string; - /** The sequence number of the last report visit */ lastReadSequenceNumber?: number; diff --git a/src/types/onyx/ReportMetadata.ts b/src/types/onyx/ReportMetadata.ts index 8c13e0f127b8..c139f66a7367 100644 --- a/src/types/onyx/ReportMetadata.ts +++ b/src/types/onyx/ReportMetadata.ts @@ -7,6 +7,9 @@ type ReportMetadata = { /** Flag to check if the report actions data are loading */ isLoadingInitialReportActions?: boolean; + + /** The time of the last visit of the report */ + lastVisitTime?: string; }; export default ReportMetadata; From e64c615d9e598c33cce7650f71e76d2a0e68ff4e Mon Sep 17 00:00:00 2001 From: DylanDylann Date: Fri, 15 Dec 2023 15:59:31 +0700 Subject: [PATCH 20/27] fix remove console log --- src/pages/home/ReportScreen.js | 1 - 1 file changed, 1 deletion(-) diff --git a/src/pages/home/ReportScreen.js b/src/pages/home/ReportScreen.js index 36759a544d2c..2a0ef4354a23 100644 --- a/src/pages/home/ReportScreen.js +++ b/src/pages/home/ReportScreen.js @@ -244,7 +244,6 @@ function ReportScreen({ if (!report.reportID || !isFocused) { return; } - console.log("////////", report.reportID) Report.updateLastVisitTime(report.reportID); }, [report.reportID, isFocused]); From 1f8552c8ec8237159308a47ec723be7284b44b41 Mon Sep 17 00:00:00 2001 From: DylanDylann Date: Fri, 15 Dec 2023 16:01:07 +0700 Subject: [PATCH 21/27] fix remove comment --- src/libs/Navigation/AppNavigator/ReportScreenIDSetter.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/src/libs/Navigation/AppNavigator/ReportScreenIDSetter.ts b/src/libs/Navigation/AppNavigator/ReportScreenIDSetter.ts index 380c193500fc..e8d9c6108752 100644 --- a/src/libs/Navigation/AppNavigator/ReportScreenIDSetter.ts +++ b/src/libs/Navigation/AppNavigator/ReportScreenIDSetter.ts @@ -17,7 +17,6 @@ type ReportScreenIDSetterComponentProps = { /** Whether user is a new user */ isFirstTimeNewExpensifyUser: OnyxEntry; - /** */ reportsMetadata: OnyxCollection; }; From 17a67d7cc578cb5f4b14e3f4e61ba122bee554e2 Mon Sep 17 00:00:00 2001 From: DylanDylann Date: Fri, 15 Dec 2023 16:20:02 +0700 Subject: [PATCH 22/27] fix lint --- src/libs/Navigation/AppNavigator/ReportScreenIDSetter.ts | 2 +- src/libs/ReportUtils.ts | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/libs/Navigation/AppNavigator/ReportScreenIDSetter.ts b/src/libs/Navigation/AppNavigator/ReportScreenIDSetter.ts index e8d9c6108752..cb3c40393d9c 100644 --- a/src/libs/Navigation/AppNavigator/ReportScreenIDSetter.ts +++ b/src/libs/Navigation/AppNavigator/ReportScreenIDSetter.ts @@ -57,7 +57,7 @@ function ReportScreenIDSetter({route, reports, policies, navigation, isFirstTime } else { App.confirmReadyToOpenApp(); } - }, [route, navigation, reports, canUseDefaultRooms, policies, isFirstTimeNewExpensifyUser]); + }, [route, navigation, reports, canUseDefaultRooms, policies, isFirstTimeNewExpensifyUser, reportsMetadata]); // The ReportScreen without the reportID set will display a skeleton // until the reportID is loaded and set in the route param diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index 9a3e34277c3b..16887150677e 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -573,7 +573,7 @@ function isDraftExpenseReport(report: OnyxEntry): boolean { function sortReportsByLastRead(reports: OnyxCollection, reportsMetadata: OnyxCollection): Array> { return Object.values(reports ?? {}) .filter( - (report) => !!report?.reportID && ((reportsMetadata && !!reportsMetadata[`${ONYXKEYS.COLLECTION.REPORT_METADATA}${report.reportID}`]?.lastVisitTime) || !!report?.lastReadTime), + (report) => !!report?.reportID && ((reportsMetadata && !!reportsMetadata[`${ONYXKEYS.COLLECTION.REPORT_METADATA}${report.reportID}`]?.lastVisitTime) ?? !!report?.lastReadTime), ) .sort((a, b) => { const aTime = new Date((reportsMetadata && a && reportsMetadata[`${ONYXKEYS.COLLECTION.REPORT_METADATA}${a.reportID}`]?.lastVisitTime) ?? a?.lastReadTime ?? ''); @@ -841,7 +841,7 @@ function findLastAccessedReport( policies: OnyxCollection, isFirstTimeNewExpensifyUser: boolean, openOnAdminRoom = false, - reportsMetadata: OnyxCollection, + reportsMetadata: OnyxCollection = {}, ): OnyxEntry { // If it's the user's first time using New Expensify, then they could either have: // - just a Concierge report, if so we'll return that From 06dfd199d86c899674175e5efd55a1c6a86d50fd Mon Sep 17 00:00:00 2001 From: DylanDylann <141406735+DylanDylann@users.noreply.github.com> Date: Thu, 21 Dec 2023 11:07:52 +0700 Subject: [PATCH 23/27] fix filter function Co-authored-by: Shubham Agrawal <58412969+shubham1206agra@users.noreply.github.com> --- src/libs/ReportUtils.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index 0916864beaa3..a92d2001eb85 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -553,7 +553,7 @@ function isDraftExpenseReport(report: OnyxEntry): boolean { function sortReportsByLastRead(reports: OnyxCollection, reportsMetadata: OnyxCollection): Array> { return Object.values(reports ?? {}) .filter( - (report) => !!report?.reportID && ((reportsMetadata && !!reportsMetadata[`${ONYXKEYS.COLLECTION.REPORT_METADATA}${report.reportID}`]?.lastVisitTime) ?? !!report?.lastReadTime), + (report) => !!report?.reportID && !!(reportsMetadata?.[`${ONYXKEYS.COLLECTION.REPORT_METADATA}${report.reportID}`]?.lastVisitTime ?? report?.lastReadTime) ) .sort((a, b) => { const aTime = new Date((reportsMetadata && a && reportsMetadata[`${ONYXKEYS.COLLECTION.REPORT_METADATA}${a.reportID}`]?.lastVisitTime) ?? a?.lastReadTime ?? ''); From 3959145e26bbbd949490f4b338cbd19422d92a8f Mon Sep 17 00:00:00 2001 From: DylanDylann <141406735+DylanDylann@users.noreply.github.com> Date: Thu, 21 Dec 2023 11:08:09 +0700 Subject: [PATCH 24/27] fix sort function Co-authored-by: Shubham Agrawal <58412969+shubham1206agra@users.noreply.github.com> --- 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 a92d2001eb85..42c3b7fad1d2 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -556,8 +556,8 @@ function sortReportsByLastRead(reports: OnyxCollection, reportsMetadata: (report) => !!report?.reportID && !!(reportsMetadata?.[`${ONYXKEYS.COLLECTION.REPORT_METADATA}${report.reportID}`]?.lastVisitTime ?? report?.lastReadTime) ) .sort((a, b) => { - const aTime = new Date((reportsMetadata && a && reportsMetadata[`${ONYXKEYS.COLLECTION.REPORT_METADATA}${a.reportID}`]?.lastVisitTime) ?? a?.lastReadTime ?? ''); - const bTime = new Date((reportsMetadata && b && reportsMetadata[`${ONYXKEYS.COLLECTION.REPORT_METADATA}${b.reportID}`]?.lastVisitTime) ?? b?.lastReadTime ?? ''); + const aTime = new Date(reportsMetadata?.[`${ONYXKEYS.COLLECTION.REPORT_METADATA}${a?.reportID}`]?.lastVisitTime ?? a?.lastReadTime ?? ''); + const bTime = new Date(reportsMetadata?.[`${ONYXKEYS.COLLECTION.REPORT_METADATA}${b?.reportID}`]?.lastVisitTime ?? b?.lastReadTime ?? ''); return aTime.valueOf() - bTime.valueOf(); }); From 9feb1d2c4824489457194e37d6829fbecfd1cb84 Mon Sep 17 00:00:00 2001 From: DylanDylann Date: Thu, 21 Dec 2023 11:15:56 +0700 Subject: [PATCH 25/27] fix lint issue --- src/libs/ReportUtils.ts | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index 42c3b7fad1d2..b5eec2f0e6b8 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -552,9 +552,7 @@ function isDraftExpenseReport(report: OnyxEntry): boolean { */ function sortReportsByLastRead(reports: OnyxCollection, reportsMetadata: OnyxCollection): Array> { return Object.values(reports ?? {}) - .filter( - (report) => !!report?.reportID && !!(reportsMetadata?.[`${ONYXKEYS.COLLECTION.REPORT_METADATA}${report.reportID}`]?.lastVisitTime ?? report?.lastReadTime) - ) + .filter((report) => !!report?.reportID && !!(reportsMetadata?.[`${ONYXKEYS.COLLECTION.REPORT_METADATA}${report.reportID}`]?.lastVisitTime ?? report?.lastReadTime)) .sort((a, b) => { const aTime = new Date(reportsMetadata?.[`${ONYXKEYS.COLLECTION.REPORT_METADATA}${a?.reportID}`]?.lastVisitTime ?? a?.lastReadTime ?? ''); const bTime = new Date(reportsMetadata?.[`${ONYXKEYS.COLLECTION.REPORT_METADATA}${b?.reportID}`]?.lastVisitTime ?? b?.lastReadTime ?? ''); From 324026477b1b90ee87b5d1af396e32fa365c01e9 Mon Sep 17 00:00:00 2001 From: DylanDylann Date: Wed, 27 Dec 2023 01:45:15 +0700 Subject: [PATCH 26/27] fix comment --- .../AppNavigator/ReportScreenIDSetter.ts | 14 +++++++------- src/libs/ReportUtils.ts | 12 ++++++------ src/pages/reportPropTypes.js | 2 +- src/types/onyx/ReportMetadata.ts | 2 +- 4 files changed, 15 insertions(+), 15 deletions(-) diff --git a/src/libs/Navigation/AppNavigator/ReportScreenIDSetter.ts b/src/libs/Navigation/AppNavigator/ReportScreenIDSetter.ts index cb3c40393d9c..4fe86753094a 100644 --- a/src/libs/Navigation/AppNavigator/ReportScreenIDSetter.ts +++ b/src/libs/Navigation/AppNavigator/ReportScreenIDSetter.ts @@ -17,7 +17,7 @@ type ReportScreenIDSetterComponentProps = { /** Whether user is a new user */ isFirstTimeNewExpensifyUser: OnyxEntry; - reportsMetadata: OnyxCollection; + reportMetadata: OnyxCollection; }; type ReportScreenIDSetterProps = ReportScreenIDSetterComponentProps & ReportScreenWrapperProps; @@ -31,14 +31,14 @@ const getLastAccessedReportID = ( policies: OnyxCollection, isFirstTimeNewExpensifyUser: OnyxEntry, openOnAdminRoom: boolean, - reportsMetadata: OnyxCollection, + reportMetadata: OnyxCollection, ): string | undefined => { - const lastReport = ReportUtils.findLastAccessedReport(reports, ignoreDefaultRooms, policies, !!isFirstTimeNewExpensifyUser, openOnAdminRoom, reportsMetadata); + const lastReport = ReportUtils.findLastAccessedReport(reports, ignoreDefaultRooms, policies, !!isFirstTimeNewExpensifyUser, openOnAdminRoom, reportMetadata); return lastReport?.reportID; }; // This wrapper is reponsible for opening the last accessed report if there is no reportID specified in the route params -function ReportScreenIDSetter({route, reports, policies, navigation, isFirstTimeNewExpensifyUser = false, reportsMetadata}: ReportScreenIDSetterProps) { +function ReportScreenIDSetter({route, reports, policies, navigation, isFirstTimeNewExpensifyUser = false, reportMetadata}: ReportScreenIDSetterProps) { const {canUseDefaultRooms} = usePermissions(); useEffect(() => { // Don't update if there is a reportID in the params already @@ -48,7 +48,7 @@ function ReportScreenIDSetter({route, reports, policies, navigation, isFirstTime } // If there is no reportID in route, try to find last accessed and use it for setParams - const reportID = getLastAccessedReportID(reports, !canUseDefaultRooms, policies, isFirstTimeNewExpensifyUser, !!reports?.params?.openOnAdminRoom, reportsMetadata); + const reportID = getLastAccessedReportID(reports, !canUseDefaultRooms, policies, isFirstTimeNewExpensifyUser, !!reports?.params?.openOnAdminRoom, reportMetadata); // It's possible that reports aren't fully loaded yet // in that case the reportID is undefined @@ -57,7 +57,7 @@ function ReportScreenIDSetter({route, reports, policies, navigation, isFirstTime } else { App.confirmReadyToOpenApp(); } - }, [route, navigation, reports, canUseDefaultRooms, policies, isFirstTimeNewExpensifyUser, reportsMetadata]); + }, [route, navigation, reports, canUseDefaultRooms, policies, isFirstTimeNewExpensifyUser, reportMetadata]); // The ReportScreen without the reportID set will display a skeleton // until the reportID is loaded and set in the route param @@ -79,7 +79,7 @@ export default withOnyx): boolean { /** * Given a collection of reports returns them sorted by last read */ -function sortReportsByLastRead(reports: OnyxCollection, reportsMetadata: OnyxCollection): Array> { +function sortReportsByLastRead(reports: OnyxCollection, reportMetadata: OnyxCollection): Array> { return Object.values(reports ?? {}) - .filter((report) => !!report?.reportID && !!(reportsMetadata?.[`${ONYXKEYS.COLLECTION.REPORT_METADATA}${report.reportID}`]?.lastVisitTime ?? report?.lastReadTime)) + .filter((report) => !!report?.reportID && !!(reportMetadata?.[`${ONYXKEYS.COLLECTION.REPORT_METADATA}${report.reportID}`]?.lastVisitTime ?? report?.lastReadTime)) .sort((a, b) => { - const aTime = new Date(reportsMetadata?.[`${ONYXKEYS.COLLECTION.REPORT_METADATA}${a?.reportID}`]?.lastVisitTime ?? a?.lastReadTime ?? ''); - const bTime = new Date(reportsMetadata?.[`${ONYXKEYS.COLLECTION.REPORT_METADATA}${b?.reportID}`]?.lastVisitTime ?? b?.lastReadTime ?? ''); + const aTime = new Date(reportMetadata?.[`${ONYXKEYS.COLLECTION.REPORT_METADATA}${a?.reportID}`]?.lastVisitTime ?? a?.lastReadTime ?? ''); + const bTime = new Date(reportMetadata?.[`${ONYXKEYS.COLLECTION.REPORT_METADATA}${b?.reportID}`]?.lastVisitTime ?? b?.lastReadTime ?? ''); return aTime.valueOf() - bTime.valueOf(); }); @@ -819,14 +819,14 @@ function findLastAccessedReport( policies: OnyxCollection, isFirstTimeNewExpensifyUser: boolean, openOnAdminRoom = false, - reportsMetadata: OnyxCollection = {}, + reportMetadata: OnyxCollection = {}, ): OnyxEntry { // If it's the user's first time using New Expensify, then they could either have: // - just a Concierge report, if so we'll return that // - their Concierge report, and a separate report that must have deeplinked them to the app before they created their account. // If it's the latter, we'll use the deeplinked report over the Concierge report, // since the Concierge report would be incorrectly selected over the deep-linked report in the logic below. - let sortedReports = sortReportsByLastRead(reports, reportsMetadata); + let sortedReports = sortReportsByLastRead(reports, reportMetadata); let adminReport: OnyxEntry | undefined; if (openOnAdminRoom) { diff --git a/src/pages/reportPropTypes.js b/src/pages/reportPropTypes.js index c89ea761f582..d2d7bb480ed6 100644 --- a/src/pages/reportPropTypes.js +++ b/src/pages/reportPropTypes.js @@ -28,7 +28,7 @@ export default PropTypes.shape({ /** The time of the last message on the report */ lastVisibleActionCreated: PropTypes.string, - /** The last time the report was visited */ + /** The time when user read the last message */ lastReadTime: PropTypes.string, /** The current user's notification preference for this report */ diff --git a/src/types/onyx/ReportMetadata.ts b/src/types/onyx/ReportMetadata.ts index c139f66a7367..c6484705553c 100644 --- a/src/types/onyx/ReportMetadata.ts +++ b/src/types/onyx/ReportMetadata.ts @@ -8,7 +8,7 @@ type ReportMetadata = { /** Flag to check if the report actions data are loading */ isLoadingInitialReportActions?: boolean; - /** The time of the last visit of the report */ + /** The time when user last visited the report */ lastVisitTime?: string; }; From d9dd28692cd59c9c82d686aff900cf7e3119a70d Mon Sep 17 00:00:00 2001 From: DylanDylann Date: Fri, 29 Dec 2023 17:53:11 +0700 Subject: [PATCH 27/27] fix add comment to prop --- src/libs/Navigation/AppNavigator/ReportScreenIDSetter.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/libs/Navigation/AppNavigator/ReportScreenIDSetter.ts b/src/libs/Navigation/AppNavigator/ReportScreenIDSetter.ts index 4fe86753094a..6ae6bb0a2516 100644 --- a/src/libs/Navigation/AppNavigator/ReportScreenIDSetter.ts +++ b/src/libs/Navigation/AppNavigator/ReportScreenIDSetter.ts @@ -17,6 +17,7 @@ type ReportScreenIDSetterComponentProps = { /** Whether user is a new user */ isFirstTimeNewExpensifyUser: OnyxEntry; + /** The report metadata */ reportMetadata: OnyxCollection; };