From a733043269cf09b2554864c15b311c96342dff55 Mon Sep 17 00:00:00 2001 From: Talha Javed Mukhtar Date: Tue, 5 Dec 2023 09:51:37 +0500 Subject: [PATCH 1/5] [Bug resolved]: Conversation disappears from LHN when creating an IOU with a new user in offline mode --- src/pages/home/sidebar/SidebarLinksData.js | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/pages/home/sidebar/SidebarLinksData.js b/src/pages/home/sidebar/SidebarLinksData.js index 088eb5c0092a..6dddcb542506 100644 --- a/src/pages/home/sidebar/SidebarLinksData.js +++ b/src/pages/home/sidebar/SidebarLinksData.js @@ -16,6 +16,9 @@ import useThemeStyles from '@styles/useThemeStyles'; import CONST from '@src/CONST'; import ONYXKEYS from '@src/ONYXKEYS'; import SidebarLinks, {basePropTypes} from './SidebarLinks'; +import networkPropTypes from '@components/networkPropTypes'; +import {withNetwork} from '@components/OnyxProvider'; + const propTypes = { ...basePropTypes, @@ -49,6 +52,8 @@ const propTypes = { /** Beta features list */ betas: PropTypes.arrayOf(PropTypes.string), + network: networkPropTypes.isRequired, + /** The policies which the user has access to */ // eslint-disable-next-line react/forbid-prop-types policies: PropTypes.object, @@ -63,7 +68,7 @@ const defaultProps = { policies: {}, }; -function SidebarLinksData({isFocused, allReportActions, betas, chatReports, currentReportID, insets, isLoadingReportData, onLinkClick, policies, priorityMode}) { +function SidebarLinksData({isFocused, allReportActions, betas, chatReports, currentReportID, insets, isLoadingReportData, onLinkClick, policies, priorityMode, network}) { const styles = useThemeStyles(); const {translate} = useLocalize(); @@ -71,16 +76,18 @@ function SidebarLinksData({isFocused, allReportActions, betas, chatReports, curr const isLoading = SessionUtils.didUserLogInDuringSession() && isLoadingReportData; const optionListItems = useMemo(() => { const reportIDs = SidebarUtils.getOrderedReportIDs(null, chatReports, betas, policies, priorityMode, allReportActions); + if (deepEqual(reportIDsRef.current, reportIDs)) { return reportIDsRef.current; } // We need to update existing reports only once while loading because they are updated several times during loading and causes this regression: https://github.com/Expensify/App/issues/24596#issuecomment-1681679531 - if (!isLoading || !reportIDsRef.current) { + // However, if the user is offline, we need to update the reports unconditionally, since the loading of report data might be stuck in this case. + if (!isLoading || !reportIDsRef.current || network.isOffline) { reportIDsRef.current = reportIDs; } return reportIDsRef.current || []; - }, [allReportActions, betas, chatReports, policies, priorityMode, isLoading]); + }, [allReportActions, betas, chatReports, policies, priorityMode, isLoading, network]); // We need to make sure the current report is in the list of reports, but we do not want // to have to re-generate the list every time the currentReportID changes. To do that @@ -195,6 +202,7 @@ const policySelector = (policy) => export default compose( withCurrentReportID, withNavigationFocus, + withNetwork(), withOnyx({ chatReports: { key: ONYXKEYS.COLLECTION.REPORT, From 22dd63a1130f25b60e3f76d9e2c17f99e977f7f6 Mon Sep 17 00:00:00 2001 From: Talha Javed Mukhtar Date: Thu, 7 Dec 2023 17:28:41 +0500 Subject: [PATCH 2/5] Made useMemo's offline dependency more specific --- src/pages/home/sidebar/SidebarLinksData.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pages/home/sidebar/SidebarLinksData.js b/src/pages/home/sidebar/SidebarLinksData.js index 6dddcb542506..ce0388a16303 100644 --- a/src/pages/home/sidebar/SidebarLinksData.js +++ b/src/pages/home/sidebar/SidebarLinksData.js @@ -87,7 +87,7 @@ function SidebarLinksData({isFocused, allReportActions, betas, chatReports, curr reportIDsRef.current = reportIDs; } return reportIDsRef.current || []; - }, [allReportActions, betas, chatReports, policies, priorityMode, isLoading, network]); + }, [allReportActions, betas, chatReports, policies, priorityMode, isLoading, network.isOffline]); // We need to make sure the current report is in the list of reports, but we do not want // to have to re-generate the list every time the currentReportID changes. To do that From e8f9fbc94ffcfa7462464db23d915172f80cd63c Mon Sep 17 00:00:00 2001 From: Talha Javed Mukhtar Date: Fri, 8 Dec 2023 08:57:11 +0500 Subject: [PATCH 3/5] Update src/pages/home/sidebar/SidebarLinksData.js edit SidebarLinksData props Co-authored-by: Andrew Rosiclair --- src/pages/home/sidebar/SidebarLinksData.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pages/home/sidebar/SidebarLinksData.js b/src/pages/home/sidebar/SidebarLinksData.js index e9fb1c2857a8..8c4d6a5bd027 100644 --- a/src/pages/home/sidebar/SidebarLinksData.js +++ b/src/pages/home/sidebar/SidebarLinksData.js @@ -67,7 +67,7 @@ const defaultProps = { policies: {}, }; -function SidebarLinksData({isFocused, allReportActions, betas, chatReports, currentReportID, insets, isLoadingReportData, onLinkClick, policies, priorityMode, network}) { +function SidebarLinksData({isFocused, allReportActions, betas, chatReports, currentReportID, insets, isLoadingApp, onLinkClick, policies, priorityMode, network}) { const styles = useThemeStyles(); const {translate} = useLocalize(); From bffe64a769b46f585fad25980271c5de47c7acf2 Mon Sep 17 00:00:00 2001 From: Talha Javed Mukhtar Date: Fri, 8 Dec 2023 09:03:05 +0500 Subject: [PATCH 4/5] Fixed linting errors --- src/pages/home/sidebar/SidebarLinksData.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pages/home/sidebar/SidebarLinksData.js b/src/pages/home/sidebar/SidebarLinksData.js index 8c4d6a5bd027..c005cfee6ed6 100644 --- a/src/pages/home/sidebar/SidebarLinksData.js +++ b/src/pages/home/sidebar/SidebarLinksData.js @@ -14,9 +14,9 @@ import reportPropTypes from '@pages/reportPropTypes'; import useThemeStyles from '@styles/useThemeStyles'; import CONST from '@src/CONST'; import ONYXKEYS from '@src/ONYXKEYS'; -import SidebarLinks, {basePropTypes} from './SidebarLinks'; import networkPropTypes from '@components/networkPropTypes'; import {withNetwork} from '@components/OnyxProvider'; +import SidebarLinks, {basePropTypes} from './SidebarLinks'; const propTypes = { From 812630fdc89b574fce9d0577af1d6e8cb0cc6669 Mon Sep 17 00:00:00 2001 From: Talha Javed Mukhtar Date: Fri, 8 Dec 2023 18:45:02 +0500 Subject: [PATCH 5/5] Ran prettier --- src/pages/home/sidebar/SidebarLinksData.js | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/pages/home/sidebar/SidebarLinksData.js b/src/pages/home/sidebar/SidebarLinksData.js index c005cfee6ed6..4f55d5eafca9 100644 --- a/src/pages/home/sidebar/SidebarLinksData.js +++ b/src/pages/home/sidebar/SidebarLinksData.js @@ -5,6 +5,8 @@ import React, {useCallback, useMemo, useRef} from 'react'; import {View} from 'react-native'; import {withOnyx} from 'react-native-onyx'; import _ from 'underscore'; +import networkPropTypes from '@components/networkPropTypes'; +import {withNetwork} from '@components/OnyxProvider'; import withCurrentReportID from '@components/withCurrentReportID'; import withNavigationFocus from '@components/withNavigationFocus'; import useLocalize from '@hooks/useLocalize'; @@ -14,11 +16,8 @@ import reportPropTypes from '@pages/reportPropTypes'; import useThemeStyles from '@styles/useThemeStyles'; import CONST from '@src/CONST'; import ONYXKEYS from '@src/ONYXKEYS'; -import networkPropTypes from '@components/networkPropTypes'; -import {withNetwork} from '@components/OnyxProvider'; import SidebarLinks, {basePropTypes} from './SidebarLinks'; - const propTypes = { ...basePropTypes,