From a2e6182b577687256ebac93a916c449ddf60a3a1 Mon Sep 17 00:00:00 2001 From: Marc Glasser Date: Thu, 28 Apr 2022 12:16:44 -1000 Subject: [PATCH 01/12] Remove setTimeout from code --- src/libs/actions/WelcomeActions.js | 52 ++++++++++++------------- src/pages/home/sidebar/SidebarScreen.js | 4 +- 2 files changed, 26 insertions(+), 30 deletions(-) diff --git a/src/libs/actions/WelcomeActions.js b/src/libs/actions/WelcomeActions.js index c67fab49f2e7..1f1d970cb656 100644 --- a/src/libs/actions/WelcomeActions.js +++ b/src/libs/actions/WelcomeActions.js @@ -45,39 +45,35 @@ Onyx.connect({ * * @param {Object} params * @param {Object} params.routes - * @param {Function} params.hideCreateMenu + * @param {Function} params.showCreateMenu */ -function show({routes, hideCreateMenu}) { - // NOTE: This setTimeout is required due to a bug in react-navigation where modals do not display properly in a drawerContent - // This is a short-term workaround, see this issue for updates on a long-term solution: https://github.com/Expensify/App/issues/5296 - setTimeout(() => { - if (!isFirstTimeNewExpensifyUser) { - return; - } +function show({routes, showCreateMenu}) { + if (!isFirstTimeNewExpensifyUser) { + return; + } - // Set the NVP back to false so we don't automatically run welcome actions again - NameValuePair.set(CONST.NVP.IS_FIRST_TIME_NEW_EXPENSIFY_USER, false, ONYXKEYS.NVP_IS_FIRST_TIME_NEW_EXPENSIFY_USER); + // Set the NVP back to false so we don't automatically run welcome actions again + NameValuePair.set(CONST.NVP.IS_FIRST_TIME_NEW_EXPENSIFY_USER, false, ONYXKEYS.NVP_IS_FIRST_TIME_NEW_EXPENSIFY_USER); - // We want to display the Workspace chat first since that means a user is already in a Workspace and doesn't need to create another one - const workspaceChatReport = _.find(allReports, report => ReportUtils.isPolicyExpenseChat(report)); - if (workspaceChatReport) { - Navigation.navigate(ROUTES.getReportRoute(workspaceChatReport.reportID)); - return; - } + // We want to display the Workspace chat first since that means a user is already in a Workspace and doesn't need to create another one + const workspaceChatReport = _.find(allReports, report => ReportUtils.isPolicyExpenseChat(report)); + if (workspaceChatReport) { + Navigation.navigate(ROUTES.getReportRoute(workspaceChatReport.reportID)); + return; + } - // If we are rendering the SidebarScreen at the same time as a workspace route that means we've already created a workspace via workspace/new and should not open the global - // create menu right now. - const topRouteName = lodashGet(_.last(routes), 'name', ''); - const loginWithShortLivedTokenRoute = _.find(routes, route => route.name === 'LogInWithShortLivedToken'); - const exitingToWorkspaceRoute = lodashGet(loginWithShortLivedTokenRoute, 'params.exitTo', '') === 'workspace/new'; - const isDisplayingWorkspaceRoute = topRouteName.toLowerCase().includes('workspace') || exitingToWorkspaceRoute; + // If we are rendering the SidebarScreen at the same time as a workspace route that means we've already created a workspace via workspace/new and should not open the global + // create menu right now. + const topRouteName = lodashGet(_.last(routes), 'name', ''); + const loginWithShortLivedTokenRoute = _.find(routes, route => route.name === 'LogInWithShortLivedToken'); + const exitingToWorkspaceRoute = lodashGet(loginWithShortLivedTokenRoute, 'params.exitTo', '') === 'workspace/new'; + const isDisplayingWorkspaceRoute = topRouteName.toLowerCase().includes('workspace') || exitingToWorkspaceRoute; - // It's also possible that we already have a workspace policy. In either case we will not hide the menu but do still want to set the NVP in this case - // since the user does not need to create a workspace. - if (!Policy.isAdminOfFreePolicy(allPolicies) && !isDisplayingWorkspaceRoute) { - hideCreateMenu(); - } - }, 1500); + // It's also possible that we already have a workspace policy. In either case we will not hide the menu but do still want to set the NVP in this case + // since the user does not need to create a workspace. + if (!Policy.isAdminOfFreePolicy(allPolicies) && !isDisplayingWorkspaceRoute) { + showCreateMenu(); + } } export { diff --git a/src/pages/home/sidebar/SidebarScreen.js b/src/pages/home/sidebar/SidebarScreen.js index 158ba45a26ac..5953d89314c4 100755 --- a/src/pages/home/sidebar/SidebarScreen.js +++ b/src/pages/home/sidebar/SidebarScreen.js @@ -22,7 +22,7 @@ import Permissions from '../../../libs/Permissions'; import ONYXKEYS from '../../../ONYXKEYS'; import * as Policy from '../../../libs/actions/Policy'; import Performance from '../../../libs/Performance'; -import * as WelcomeAction from '../../../libs/actions/WelcomeActions'; +import * as WelcomeActions from '../../../libs/actions/WelcomeActions'; const propTypes = { /* Beta features list */ @@ -58,7 +58,7 @@ class SidebarScreen extends Component { Timing.start(CONST.TIMING.SIDEBAR_LOADED, true); const routes = lodashGet(this.props.navigation.getState(), 'routes', []); - WelcomeAction.show({routes, hideCreateMenu: this.hideCreateMenu}); + WelcomeActions.show({routes, showCreateMenu: this.showCreateMenu}); } /** From 3bd6c560caa87f3bf7c9e4cdda2159e056ce24a3 Mon Sep 17 00:00:00 2001 From: Marc Glasser Date: Thu, 28 Apr 2022 12:26:15 -1000 Subject: [PATCH 02/12] Fix comment --- src/libs/actions/WelcomeActions.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/libs/actions/WelcomeActions.js b/src/libs/actions/WelcomeActions.js index 1f1d970cb656..a383b34a386c 100644 --- a/src/libs/actions/WelcomeActions.js +++ b/src/libs/actions/WelcomeActions.js @@ -69,8 +69,8 @@ function show({routes, showCreateMenu}) { const exitingToWorkspaceRoute = lodashGet(loginWithShortLivedTokenRoute, 'params.exitTo', '') === 'workspace/new'; const isDisplayingWorkspaceRoute = topRouteName.toLowerCase().includes('workspace') || exitingToWorkspaceRoute; - // It's also possible that we already have a workspace policy. In either case we will not hide the menu but do still want to set the NVP in this case - // since the user does not need to create a workspace. + // If user is not already an admin of a free policy and we are not navigating them to their workspace or creating a new workspace via workspace/new then + // we will show the create menu. if (!Policy.isAdminOfFreePolicy(allPolicies) && !isDisplayingWorkspaceRoute) { showCreateMenu(); } From 96a2a0f03de2f361c16abc8370d2d98be05832d0 Mon Sep 17 00:00:00 2001 From: Marc Glasser Date: Thu, 28 Apr 2022 12:47:46 -1000 Subject: [PATCH 03/12] Move subscriptions to SidebarScreen --- src/libs/actions/WelcomeActions.js | 36 +++---------------------- src/pages/home/sidebar/SidebarScreen.js | 16 ++++++++++- 2 files changed, 18 insertions(+), 34 deletions(-) diff --git a/src/libs/actions/WelcomeActions.js b/src/libs/actions/WelcomeActions.js index a383b34a386c..93d464e623a4 100644 --- a/src/libs/actions/WelcomeActions.js +++ b/src/libs/actions/WelcomeActions.js @@ -1,4 +1,3 @@ -import Onyx from 'react-native-onyx'; import _ from 'underscore'; import lodashGet from 'lodash/get'; import Navigation from '../Navigation/Navigation'; @@ -9,37 +8,6 @@ import ONYXKEYS from '../../ONYXKEYS'; import NameValuePair from './NameValuePair'; import CONST from '../../CONST'; -/* Flag for new users used to show welcome actions on first load */ -let isFirstTimeNewExpensifyUser = false; -Onyx.connect({ - key: ONYXKEYS.NVP_IS_FIRST_TIME_NEW_EXPENSIFY_USER, - callback: val => isFirstTimeNewExpensifyUser = val, -}); - -const allReports = {}; -Onyx.connect({ - key: ONYXKEYS.COLLECTION.REPORT, - callback: (val, key) => { - if (!val || !key) { - return; - } - - allReports[key] = {...allReports[key], ...val}; - }, -}); - -const allPolicies = {}; -Onyx.connect({ - key: ONYXKEYS.COLLECTION.REPORT, - callback: (val, key) => { - if (!val || !key) { - return; - } - - allPolicies[key] = {...allPolicies[key], ...val}; - }, -}); - /** * Shows a welcome action on first login * @@ -47,7 +15,9 @@ Onyx.connect({ * @param {Object} params.routes * @param {Function} params.showCreateMenu */ -function show({routes, showCreateMenu}) { +function show({ + routes, showCreateMenu, isFirstTimeNewExpensifyUser, allReports, allPolicies, +}) { if (!isFirstTimeNewExpensifyUser) { return; } diff --git a/src/pages/home/sidebar/SidebarScreen.js b/src/pages/home/sidebar/SidebarScreen.js index 5953d89314c4..cfb744694a0e 100755 --- a/src/pages/home/sidebar/SidebarScreen.js +++ b/src/pages/home/sidebar/SidebarScreen.js @@ -58,7 +58,15 @@ class SidebarScreen extends Component { Timing.start(CONST.TIMING.SIDEBAR_LOADED, true); const routes = lodashGet(this.props.navigation.getState(), 'routes', []); - WelcomeActions.show({routes, showCreateMenu: this.showCreateMenu}); + WelcomeActions.show({ + routes, + showCreateMenu: this.showCreateMenu, + isFirstTimeNewExpensifyUser: _.isBoolean(this.props.isFirstTimeNewExpensifyUser) + ? this.props.isFirstTimeNewExpensifyUser + : true, + allPolicies: this.props.allPolicies, + allReports: this.props.allReports, + }); } /** @@ -195,11 +203,17 @@ export default compose( allPolicies: { key: ONYXKEYS.COLLECTION.POLICY, }, + allReports: { + key: ONYXKEYS.COLLECTION.REPORT, + }, betas: { key: ONYXKEYS.BETAS, }, isCreatingWorkspace: { key: ONYXKEYS.IS_CREATING_WORKSPACE, }, + isFirstTimeNewExpensifyUser: { + key: ONYXKEYS.NVP_IS_FIRST_TIME_NEW_EXPENSIFY_USER, + }, }), )(SidebarScreen); From af7232e2f12b6b11f6057b9599f8844042c8e260 Mon Sep 17 00:00:00 2001 From: Marc Glasser Date: Fri, 29 Apr 2022 06:12:52 -1000 Subject: [PATCH 04/12] Add extra params --- src/libs/actions/WelcomeActions.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/libs/actions/WelcomeActions.js b/src/libs/actions/WelcomeActions.js index 93d464e623a4..9c57cb6cf509 100644 --- a/src/libs/actions/WelcomeActions.js +++ b/src/libs/actions/WelcomeActions.js @@ -14,6 +14,9 @@ import CONST from '../../CONST'; * @param {Object} params * @param {Object} params.routes * @param {Function} params.showCreateMenu + * @param {Boolean} params.isFirstTimeNewExpensifyUser + * @param {Object} params.allReports + * @param {Object} params.allPolicies */ function show({ routes, showCreateMenu, isFirstTimeNewExpensifyUser, allReports, allPolicies, From 095f8bd32c0f53ac9b64ec8a7855e688e607085d Mon Sep 17 00:00:00 2001 From: Marc Glasser Date: Fri, 29 Apr 2022 10:46:27 -1000 Subject: [PATCH 05/12] Welcome actions are dependent on having certain data loaded or else they cannot run reliably --- src/ONYXKEYS.js | 3 + src/libs/actions/Policy.js | 10 +- src/libs/actions/WelcomeActions.js | 122 ++++++++++++++++++------ src/pages/home/sidebar/SidebarScreen.js | 8 -- 4 files changed, 104 insertions(+), 39 deletions(-) diff --git a/src/ONYXKEYS.js b/src/ONYXKEYS.js index 0bb4ed4ea3f4..e3ec98b6052e 100755 --- a/src/ONYXKEYS.js +++ b/src/ONYXKEYS.js @@ -170,6 +170,9 @@ export default { // Is report data loading? IS_LOADING_REPORT_DATA: 'isLoadingReportData', + // Is policy data loading? + IS_LOADING_POLICY_DATA: 'isLoadingPolicyData', + // Are we loading the create policy room command IS_LOADING_CREATE_POLICY_ROOM: 'isLoadingCratePolicyRoom', diff --git a/src/libs/actions/Policy.js b/src/libs/actions/Policy.js index dfbbac1ffda7..57f3e062e139 100644 --- a/src/libs/actions/Policy.js +++ b/src/libs/actions/Policy.js @@ -101,19 +101,24 @@ function getSimplifiedPolicyObject(fullPolicyOrPolicySummary, isFromFullPolicy) * @param {Object} policyCollection - object of policy key and partial policy object */ function updateAllPolicies(policyCollection) { + const onyxActions = []; + // Clear out locally cached policies that have been deleted (i.e. they exist locally but not in our new policy collection object) _.each(allPolicies, (policy, key) => { if (policyCollection[key]) { return; } - Onyx.set(key, null); + onyxActions.push(Onyx.set(key, null)); }); // Set all the policies _.each(policyCollection, (policyData, key) => { - Onyx.merge(key, {...policyData, alertMessage: '', errors: null}); + onyxActions.push(Onyx.merge(key, {...policyData, alertMessage: '', errors: null})); }); + + Promise.all(onyxActions) + .then(() => Onyx.set(ONYXKEYS.IS_LOADING_POLICY_DATA, false)); } /** @@ -209,6 +214,7 @@ function deletePolicy(policyID) { * and we also don't have to wait for full policies to load before navigating to the new policy. */ function getPolicyList() { + Onyx.set(ONYXKEYS.IS_LOADING_POLICY_DATA, true); API.GetPolicySummaryList() .then((data) => { if (data.jsonCode !== 200) { diff --git a/src/libs/actions/WelcomeActions.js b/src/libs/actions/WelcomeActions.js index 9c57cb6cf509..6a213867cb53 100644 --- a/src/libs/actions/WelcomeActions.js +++ b/src/libs/actions/WelcomeActions.js @@ -1,3 +1,4 @@ +import Onyx from 'react-native-onyx'; import _ from 'underscore'; import lodashGet from 'lodash/get'; import Navigation from '../Navigation/Navigation'; @@ -7,6 +8,72 @@ import * as Policy from './Policy'; import ONYXKEYS from '../../ONYXKEYS'; import NameValuePair from './NameValuePair'; import CONST from '../../CONST'; +import createOnReadyTask from '../createOnReadyTask'; + +const [isReady, setReady] = createOnReadyTask(); + +let isFirstTimeNewExpensifyUser; +let isLoadingReportData = true; +let isLoadingPolicyData = true; + +function checkOnReady() { + if (!_.isBoolean(isFirstTimeNewExpensifyUser) || isLoadingPolicyData || isLoadingReportData) { + return; + } + + setReady(); +} + +Onyx.connect({ + key: ONYXKEYS.NVP_IS_FIRST_TIME_NEW_EXPENSIFY_USER, + initWithStoredValues: false, + callback: (val) => { + isFirstTimeNewExpensifyUser = val; + }, +}); + +Onyx.connect({ + key: ONYXKEYS.IS_LOADING_REPORT_DATA, + initWithStoredValues: false, + callback: (val) => { + isLoadingReportData = val; + checkOnReady(); + }, +}); + +Onyx.connect({ + key: ONYXKEYS.IS_LOADING_POLICY_DATA, + initWithStoredValues: false, + callback: (val) => { + isLoadingPolicyData = val; + checkOnReady(); + }, +}); + +const allReports = {}; +Onyx.connect({ + key: ONYXKEYS.COLLECTION.REPORT, + initWithStoredValues: false, + callback: (val, key) => { + if (!val || !key) { + return; + } + + allReports[key] = {...allReports[key], ...val}; + }, +}); + +const allPolicies = {}; +Onyx.connect({ + key: ONYXKEYS.COLLECTION.REPORT, + callback: (val, key) => { + if (!val || !key) { + return; + } + + allPolicies[key] = {...allPolicies[key], ...val}; + }, +}); /** * Shows a welcome action on first login @@ -14,39 +81,36 @@ import CONST from '../../CONST'; * @param {Object} params * @param {Object} params.routes * @param {Function} params.showCreateMenu - * @param {Boolean} params.isFirstTimeNewExpensifyUser - * @param {Object} params.allReports - * @param {Object} params.allPolicies */ -function show({ - routes, showCreateMenu, isFirstTimeNewExpensifyUser, allReports, allPolicies, -}) { - if (!isFirstTimeNewExpensifyUser) { - return; - } +function show({routes, showCreateMenu}) { + isReady().then(() => { + if (!isFirstTimeNewExpensifyUser) { + return; + } - // Set the NVP back to false so we don't automatically run welcome actions again - NameValuePair.set(CONST.NVP.IS_FIRST_TIME_NEW_EXPENSIFY_USER, false, ONYXKEYS.NVP_IS_FIRST_TIME_NEW_EXPENSIFY_USER); + // Set the NVP back to false so we don't automatically run welcome actions again + NameValuePair.set(CONST.NVP.IS_FIRST_TIME_NEW_EXPENSIFY_USER, false, ONYXKEYS.NVP_IS_FIRST_TIME_NEW_EXPENSIFY_USER); - // We want to display the Workspace chat first since that means a user is already in a Workspace and doesn't need to create another one - const workspaceChatReport = _.find(allReports, report => ReportUtils.isPolicyExpenseChat(report)); - if (workspaceChatReport) { - Navigation.navigate(ROUTES.getReportRoute(workspaceChatReport.reportID)); - return; - } + // We want to display the Workspace chat first since that means a user is already in a Workspace and doesn't need to create another one + const workspaceChatReport = _.find(allReports, report => ReportUtils.isPolicyExpenseChat(report)); + if (workspaceChatReport) { + Navigation.navigate(ROUTES.getReportRoute(workspaceChatReport.reportID)); + return; + } - // If we are rendering the SidebarScreen at the same time as a workspace route that means we've already created a workspace via workspace/new and should not open the global - // create menu right now. - const topRouteName = lodashGet(_.last(routes), 'name', ''); - const loginWithShortLivedTokenRoute = _.find(routes, route => route.name === 'LogInWithShortLivedToken'); - const exitingToWorkspaceRoute = lodashGet(loginWithShortLivedTokenRoute, 'params.exitTo', '') === 'workspace/new'; - const isDisplayingWorkspaceRoute = topRouteName.toLowerCase().includes('workspace') || exitingToWorkspaceRoute; - - // If user is not already an admin of a free policy and we are not navigating them to their workspace or creating a new workspace via workspace/new then - // we will show the create menu. - if (!Policy.isAdminOfFreePolicy(allPolicies) && !isDisplayingWorkspaceRoute) { - showCreateMenu(); - } + // If we are rendering the SidebarScreen at the same time as a workspace route that means we've already created a workspace via workspace/new and should not open the global + // create menu right now. + const topRouteName = lodashGet(_.last(routes), 'name', ''); + const loginWithShortLivedTokenRoute = _.find(routes, route => route.name === 'LogInWithShortLivedToken'); + const exitingToWorkspaceRoute = lodashGet(loginWithShortLivedTokenRoute, 'params.exitTo', '') === 'workspace/new'; + const isDisplayingWorkspaceRoute = topRouteName.toLowerCase().includes('workspace') || exitingToWorkspaceRoute; + + // If user is not already an admin of a free policy and we are not navigating them to their workspace or creating a new workspace via workspace/new then + // we will show the create menu. + if (!Policy.isAdminOfFreePolicy(allPolicies) && !isDisplayingWorkspaceRoute) { + showCreateMenu(); + } + }); } export { diff --git a/src/pages/home/sidebar/SidebarScreen.js b/src/pages/home/sidebar/SidebarScreen.js index cfb744694a0e..42d5555f48b3 100755 --- a/src/pages/home/sidebar/SidebarScreen.js +++ b/src/pages/home/sidebar/SidebarScreen.js @@ -61,11 +61,6 @@ class SidebarScreen extends Component { WelcomeActions.show({ routes, showCreateMenu: this.showCreateMenu, - isFirstTimeNewExpensifyUser: _.isBoolean(this.props.isFirstTimeNewExpensifyUser) - ? this.props.isFirstTimeNewExpensifyUser - : true, - allPolicies: this.props.allPolicies, - allReports: this.props.allReports, }); } @@ -212,8 +207,5 @@ export default compose( isCreatingWorkspace: { key: ONYXKEYS.IS_CREATING_WORKSPACE, }, - isFirstTimeNewExpensifyUser: { - key: ONYXKEYS.NVP_IS_FIRST_TIME_NEW_EXPENSIFY_USER, - }, }), )(SidebarScreen); From 49510a41d6a44551d4cf4d42151b543a993d6d46 Mon Sep 17 00:00:00 2001 From: Marc Glasser Date: Fri, 29 Apr 2022 11:11:59 -1000 Subject: [PATCH 06/12] remove allReports from sidebarScreen --- src/pages/home/sidebar/SidebarScreen.js | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/pages/home/sidebar/SidebarScreen.js b/src/pages/home/sidebar/SidebarScreen.js index 42d5555f48b3..84257a935378 100755 --- a/src/pages/home/sidebar/SidebarScreen.js +++ b/src/pages/home/sidebar/SidebarScreen.js @@ -198,9 +198,6 @@ export default compose( allPolicies: { key: ONYXKEYS.COLLECTION.POLICY, }, - allReports: { - key: ONYXKEYS.COLLECTION.REPORT, - }, betas: { key: ONYXKEYS.BETAS, }, From d62833fc9a6c4ff88c22559a5593e1bbb11bebdd Mon Sep 17 00:00:00 2001 From: Marc Glasser Date: Fri, 29 Apr 2022 11:15:00 -1000 Subject: [PATCH 07/12] add comment --- src/libs/actions/WelcomeActions.js | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/libs/actions/WelcomeActions.js b/src/libs/actions/WelcomeActions.js index 6a213867cb53..ec6f505ce1f8 100644 --- a/src/libs/actions/WelcomeActions.js +++ b/src/libs/actions/WelcomeActions.js @@ -16,6 +16,13 @@ let isFirstTimeNewExpensifyUser; let isLoadingReportData = true; let isLoadingPolicyData = true; +/** + * Check that a few requests have completed so that the welcome action can proceed: + * + * - Whether we are a first time new expensify user + * - Whether we have loaded all policies the server knows about + * - Whether we have loaded all reports the server knows about + */ function checkOnReady() { if (!_.isBoolean(isFirstTimeNewExpensifyUser) || isLoadingPolicyData || isLoadingReportData) { return; From 9e7c70c2c92a6c17721fa3dbb18992a69069f954 Mon Sep 17 00:00:00 2001 From: Marc Glasser Date: Fri, 29 Apr 2022 11:19:35 -1000 Subject: [PATCH 08/12] remove policy stuff I think the cache means we dont have to wait for those promises --- src/libs/actions/Policy.js | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/src/libs/actions/Policy.js b/src/libs/actions/Policy.js index 57f3e062e139..8fc878298961 100644 --- a/src/libs/actions/Policy.js +++ b/src/libs/actions/Policy.js @@ -101,24 +101,19 @@ function getSimplifiedPolicyObject(fullPolicyOrPolicySummary, isFromFullPolicy) * @param {Object} policyCollection - object of policy key and partial policy object */ function updateAllPolicies(policyCollection) { - const onyxActions = []; - // Clear out locally cached policies that have been deleted (i.e. they exist locally but not in our new policy collection object) _.each(allPolicies, (policy, key) => { if (policyCollection[key]) { return; } - onyxActions.push(Onyx.set(key, null)); + Onyx.set(key, null); }); // Set all the policies _.each(policyCollection, (policyData, key) => { - onyxActions.push(Onyx.merge(key, {...policyData, alertMessage: '', errors: null})); + Onyx.merge(key, {...policyData, alertMessage: '', errors: null}); }); - - Promise.all(onyxActions) - .then(() => Onyx.set(ONYXKEYS.IS_LOADING_POLICY_DATA, false)); } /** @@ -218,6 +213,7 @@ function getPolicyList() { API.GetPolicySummaryList() .then((data) => { if (data.jsonCode !== 200) { + Onyx.set(ONYXKEYS.IS_LOADING_POLICY_DATA, false); return; } @@ -229,6 +225,8 @@ function getPolicyList() { if (!_.isEmpty(policyCollection)) { updateAllPolicies(policyCollection); } + + Onyx.set(ONYXKEYS.IS_LOADING_POLICY_DATA, false); }); } From d3eebfa3f38ba26988b2147ed7844f4dc476d6c9 Mon Sep 17 00:00:00 2001 From: Marc Glasser Date: Fri, 29 Apr 2022 11:20:43 -1000 Subject: [PATCH 09/12] use single line --- src/pages/home/sidebar/SidebarScreen.js | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/pages/home/sidebar/SidebarScreen.js b/src/pages/home/sidebar/SidebarScreen.js index 84257a935378..5953d89314c4 100755 --- a/src/pages/home/sidebar/SidebarScreen.js +++ b/src/pages/home/sidebar/SidebarScreen.js @@ -58,10 +58,7 @@ class SidebarScreen extends Component { Timing.start(CONST.TIMING.SIDEBAR_LOADED, true); const routes = lodashGet(this.props.navigation.getState(), 'routes', []); - WelcomeActions.show({ - routes, - showCreateMenu: this.showCreateMenu, - }); + WelcomeActions.show({routes, showCreateMenu: this.showCreateMenu}); } /** From 00a207a801f65fc66b075797661c0615d5786cc9 Mon Sep 17 00:00:00 2001 From: Marc Glasser Date: Fri, 29 Apr 2022 11:21:26 -1000 Subject: [PATCH 10/12] add missing check --- src/libs/actions/WelcomeActions.js | 1 + 1 file changed, 1 insertion(+) diff --git a/src/libs/actions/WelcomeActions.js b/src/libs/actions/WelcomeActions.js index ec6f505ce1f8..e347213ee461 100644 --- a/src/libs/actions/WelcomeActions.js +++ b/src/libs/actions/WelcomeActions.js @@ -36,6 +36,7 @@ Onyx.connect({ initWithStoredValues: false, callback: (val) => { isFirstTimeNewExpensifyUser = val; + checkOnReady(); }, }); From e11e3627d5c8f345c29f7cb470190a58df0afc54 Mon Sep 17 00:00:00 2001 From: Marc Glasser Date: Fri, 29 Apr 2022 12:04:30 -1000 Subject: [PATCH 11/12] rename WelcomeActions to Welcome --- src/libs/actions/{WelcomeActions.js => Welcome.js} | 0 src/pages/home/sidebar/SidebarScreen.js | 4 ++-- 2 files changed, 2 insertions(+), 2 deletions(-) rename src/libs/actions/{WelcomeActions.js => Welcome.js} (100%) diff --git a/src/libs/actions/WelcomeActions.js b/src/libs/actions/Welcome.js similarity index 100% rename from src/libs/actions/WelcomeActions.js rename to src/libs/actions/Welcome.js diff --git a/src/pages/home/sidebar/SidebarScreen.js b/src/pages/home/sidebar/SidebarScreen.js index 5953d89314c4..c2f55f3d1826 100755 --- a/src/pages/home/sidebar/SidebarScreen.js +++ b/src/pages/home/sidebar/SidebarScreen.js @@ -22,7 +22,7 @@ import Permissions from '../../../libs/Permissions'; import ONYXKEYS from '../../../ONYXKEYS'; import * as Policy from '../../../libs/actions/Policy'; import Performance from '../../../libs/Performance'; -import * as WelcomeActions from '../../../libs/actions/WelcomeActions'; +import * as Welcome from '../../../libs/actions/Welcome'; const propTypes = { /* Beta features list */ @@ -58,7 +58,7 @@ class SidebarScreen extends Component { Timing.start(CONST.TIMING.SIDEBAR_LOADED, true); const routes = lodashGet(this.props.navigation.getState(), 'routes', []); - WelcomeActions.show({routes, showCreateMenu: this.showCreateMenu}); + Welcome.show({routes, showCreateMenu: this.showCreateMenu}); } /** From 5230617ca0c1960d129016189497204c39b88385 Mon Sep 17 00:00:00 2001 From: Marc Glasser Date: Tue, 3 May 2022 07:45:18 -1000 Subject: [PATCH 12/12] Update to use new signature of task and reset when user signs out --- src/libs/actions/Session/index.js | 2 ++ src/libs/actions/Welcome.js | 12 ++++++++---- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/src/libs/actions/Session/index.js b/src/libs/actions/Session/index.js index 8d21d8ff73d5..ddccec8d71bd 100644 --- a/src/libs/actions/Session/index.js +++ b/src/libs/actions/Session/index.js @@ -20,6 +20,7 @@ import NetworkConnection from '../../NetworkConnection'; import * as User from '../User'; import * as ValidationUtils from '../../ValidationUtils'; import * as Authentication from '../../Authentication'; +import * as Welcome from '../Welcome'; let credentials = {}; Onyx.connect({ @@ -347,6 +348,7 @@ function cleanupSession() { PushNotification.clearNotifications(); Pusher.disconnect(); Timers.clearAll(); + Welcome.resetReadyCheck(); } function clearAccountMessages() { diff --git a/src/libs/actions/Welcome.js b/src/libs/actions/Welcome.js index e347213ee461..58935bcf54bd 100644 --- a/src/libs/actions/Welcome.js +++ b/src/libs/actions/Welcome.js @@ -10,7 +10,7 @@ import NameValuePair from './NameValuePair'; import CONST from '../../CONST'; import createOnReadyTask from '../createOnReadyTask'; -const [isReady, setReady] = createOnReadyTask(); +const readyTask = createOnReadyTask(); let isFirstTimeNewExpensifyUser; let isLoadingReportData = true; @@ -28,7 +28,7 @@ function checkOnReady() { return; } - setReady(); + readyTask.setIsReady(); } Onyx.connect({ @@ -91,7 +91,7 @@ Onyx.connect({ * @param {Function} params.showCreateMenu */ function show({routes, showCreateMenu}) { - isReady().then(() => { + readyTask.isReady().then(() => { if (!isFirstTimeNewExpensifyUser) { return; } @@ -121,7 +121,11 @@ function show({routes, showCreateMenu}) { }); } +function resetReadyCheck() { + readyTask.reset(); +} + export { - // eslint-disable-next-line import/prefer-default-export show, + resetReadyCheck, };