From 3aaf2cca7a0163bddfa264736a0485d0f26fbc3d Mon Sep 17 00:00:00 2001 From: Amal Nazeem Date: Thu, 15 Jul 2021 14:19:19 -0400 Subject: [PATCH 1/2] Load policies after we load betas as well --- src/libs/Navigation/AppNavigator/AuthScreens.js | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/libs/Navigation/AppNavigator/AuthScreens.js b/src/libs/Navigation/AppNavigator/AuthScreens.js index ba720e3f789a..e17294abf3ca 100644 --- a/src/libs/Navigation/AppNavigator/AuthScreens.js +++ b/src/libs/Navigation/AppNavigator/AuthScreens.js @@ -96,6 +96,8 @@ const modalScreenListeners = { }, }; +let hasLoadedPolicies = false; + const propTypes = { /** Information about the network */ network: PropTypes.shape({ @@ -142,9 +144,11 @@ class AuthScreens extends React.Component { fetchCountryCodeByRequestIP(); UnreadIndicatorUpdater.listenForReportChanges(); + // When removing the free plan beta, this whole check and the logic in componentDidUpdate can be removed if (Permissions.canUseFreePlan(this.props.betas) || Permissions.canUseDefaultRooms(this.props.betas)) { getPolicyList(); getPolicySummaries(); + hasLoadedPolicies = true; } // Refresh the personal details, timezone and betas every 30 minutes @@ -186,9 +190,21 @@ class AuthScreens extends React.Component { return true; } + if (nextProps.betas !== this.props.betas) { + return true; + } + return false; } + componentDidUpdate() { + if (!hasLoadedPolicies && (Permissions.canUseFreePlan(this.props.betas) || Permissions.canUseDefaultRooms(this.props.betas))) { + getPolicyList(); + getPolicySummaries(); + hasLoadedPolicies = true; + } + } + componentWillUnmount() { KeyboardShortcut.unsubscribe('K'); NetworkConnection.stopListeningForReconnect(); From ece1ff48a56e72e5401a8a381aa72712c9d5cfad Mon Sep 17 00:00:00 2001 From: Amal Nazeem Date: Thu, 15 Jul 2021 14:48:54 -0400 Subject: [PATCH 2/2] Some DRY for repeated code --- .../Navigation/AppNavigator/AuthScreens.js | 27 +++++++++++-------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/src/libs/Navigation/AppNavigator/AuthScreens.js b/src/libs/Navigation/AppNavigator/AuthScreens.js index e17294abf3ca..ff370c7ef42e 100644 --- a/src/libs/Navigation/AppNavigator/AuthScreens.js +++ b/src/libs/Navigation/AppNavigator/AuthScreens.js @@ -98,6 +98,20 @@ const modalScreenListeners = { let hasLoadedPolicies = false; +/** + * We want to only load policy info if you are in the freePlan beta. + * @param {Array} betas + */ +function loadPoliciesBehindBeta(betas) { + // When removing the freePlan beta, simply load the policyList and the policySummaries in componentDidMount(). + // Policy info loading should not be blocked behind the defaultRooms beta alone. + if (!hasLoadedPolicies && (Permissions.canUseFreePlan(betas) || Permissions.canUseDefaultRooms(betas))) { + getPolicyList(); + getPolicySummaries(); + hasLoadedPolicies = true; + } +} + const propTypes = { /** Information about the network */ network: PropTypes.shape({ @@ -144,12 +158,7 @@ class AuthScreens extends React.Component { fetchCountryCodeByRequestIP(); UnreadIndicatorUpdater.listenForReportChanges(); - // When removing the free plan beta, this whole check and the logic in componentDidUpdate can be removed - if (Permissions.canUseFreePlan(this.props.betas) || Permissions.canUseDefaultRooms(this.props.betas)) { - getPolicyList(); - getPolicySummaries(); - hasLoadedPolicies = true; - } + loadPoliciesBehindBeta(this.props.betas); // Refresh the personal details, timezone and betas every 30 minutes // There is no pusher event that sends updated personal details data yet @@ -198,11 +207,7 @@ class AuthScreens extends React.Component { } componentDidUpdate() { - if (!hasLoadedPolicies && (Permissions.canUseFreePlan(this.props.betas) || Permissions.canUseDefaultRooms(this.props.betas))) { - getPolicyList(); - getPolicySummaries(); - hasLoadedPolicies = true; - } + loadPoliciesBehindBeta(this.props.betas); } componentWillUnmount() {