From 35505183d8bccb52acbf53f45931d0133b69584c Mon Sep 17 00:00:00 2001 From: chiragsalian Date: Wed, 4 Aug 2021 18:36:16 -0700 Subject: [PATCH 1/4] Attempt at fixing race --- .../Navigation/AppNavigator/AuthScreens.js | 19 ----------------- src/libs/actions/PersonalDetails.js | 21 +++++++++++++++++++ 2 files changed, 21 insertions(+), 19 deletions(-) diff --git a/src/libs/Navigation/AppNavigator/AuthScreens.js b/src/libs/Navigation/AppNavigator/AuthScreens.js index dbbe137bafeeb..8f2360d4b421f 100644 --- a/src/libs/Navigation/AppNavigator/AuthScreens.js +++ b/src/libs/Navigation/AppNavigator/AuthScreens.js @@ -1,9 +1,5 @@ import React from 'react'; import PropTypes from 'prop-types'; -import Onyx, {withOnyx} from 'react-native-onyx'; -import moment from 'moment'; -import _ from 'underscore'; -import lodashGet from 'lodash/get'; import styles, {getNavigationModalCardStyle} from '../../../styles/styles'; import withWindowDimensions, {windowDimensionsPropTypes} from '../../../components/withWindowDimensions'; import CONST from '../../../CONST'; @@ -67,21 +63,6 @@ import ValidateLogin2FANewWorkspacePage from '../../../pages/ValidateLogin2FANew import WorkspaceSettingsDrawerNavigator from './WorkspaceSettingsDrawerNavigator'; import defaultScreenOptions from './defaultScreenOptions'; -Onyx.connect({ - key: ONYXKEYS.MY_PERSONAL_DETAILS, - callback: (val) => { - const timezone = lodashGet(val, 'timezone', {}); - const currentTimezone = moment.tz.guess(true); - - // If the current timezone is different than the user's timezone, and their timezone is set to automatic - // then update their timezone. - if (_.isObject(timezone) && timezone.automatic && timezone.selected !== currentTimezone) { - timezone.selected = currentTimezone; - PersonalDetails.setPersonalDetails({timezone}); - } - }, -}); - const RootStack = createCustomModalStackNavigator(); // We want to delay the re-rendering for components(e.g. ReportActionCompose) diff --git a/src/libs/actions/PersonalDetails.js b/src/libs/actions/PersonalDetails.js index 269e021b95a44..a14f8fde10f07 100644 --- a/src/libs/actions/PersonalDetails.js +++ b/src/libs/actions/PersonalDetails.js @@ -3,6 +3,7 @@ import lodashGet from 'lodash/get'; import lodashMerge from 'lodash/merge'; import Onyx from 'react-native-onyx'; import Str from 'expensify-common/lib/str'; +import moment from 'moment'; import ONYXKEYS from '../../ONYXKEYS'; import CONST from '../../CONST'; import NetworkConnection from '../NetworkConnection'; @@ -23,6 +24,26 @@ Onyx.connect({ callback: val => personalDetails = val, }); +Onyx.connect({ + key: ONYXKEYS.MY_PERSONAL_DETAILS, + callback: (val) => { + if (!val) { + return; + } + + const timezone = lodashGet(val, 'timezone', {}); + const currentTimezone = moment.tz.guess(true); + + // If the current timezone is different than the user's timezone, and their timezone is set to automatic + // then update their timezone. + if (_.isObject(timezone) && timezone.automatic && timezone.selected !== currentTimezone) { + timezone.selected = currentTimezone; + // eslint-disable-next-line no-use-before-define + setPersonalDetails({timezone}); + } + }, +}); + /** * Returns the URL for a user's avatar and handles someone not having any avatar at all * From eb49d80fca5ede473d0e1172b5e0014d9bfb4c34 Mon Sep 17 00:00:00 2001 From: chiragsalian Date: Wed, 4 Aug 2021 18:43:03 -0700 Subject: [PATCH 2/4] oops, getting back withOnyx --- src/libs/Navigation/AppNavigator/AuthScreens.js | 1 + 1 file changed, 1 insertion(+) diff --git a/src/libs/Navigation/AppNavigator/AuthScreens.js b/src/libs/Navigation/AppNavigator/AuthScreens.js index 8f2360d4b421f..01711bcd38949 100644 --- a/src/libs/Navigation/AppNavigator/AuthScreens.js +++ b/src/libs/Navigation/AppNavigator/AuthScreens.js @@ -1,5 +1,6 @@ import React from 'react'; import PropTypes from 'prop-types'; +import {withOnyx} from 'react-native-onyx'; import styles, {getNavigationModalCardStyle} from '../../../styles/styles'; import withWindowDimensions, {windowDimensionsPropTypes} from '../../../components/withWindowDimensions'; import CONST from '../../../CONST'; From 7374a3d050b4f08c04f86b64886c7f1a3167abfa Mon Sep 17 00:00:00 2001 From: chiragsalian Date: Thu, 5 Aug 2021 10:29:52 -0700 Subject: [PATCH 3/4] some code reverts testing if it helps with jest --- .../Navigation/AppNavigator/AuthScreens.js | 25 ++++++++++++++++++- src/libs/actions/PersonalDetails.js | 21 ---------------- 2 files changed, 24 insertions(+), 22 deletions(-) diff --git a/src/libs/Navigation/AppNavigator/AuthScreens.js b/src/libs/Navigation/AppNavigator/AuthScreens.js index 01711bcd38949..fbd5ca5673549 100644 --- a/src/libs/Navigation/AppNavigator/AuthScreens.js +++ b/src/libs/Navigation/AppNavigator/AuthScreens.js @@ -1,6 +1,9 @@ import React from 'react'; import PropTypes from 'prop-types'; -import {withOnyx} from 'react-native-onyx'; +import Onyx, {withOnyx} from 'react-native-onyx'; +import moment from 'moment'; +import _ from 'underscore'; +import lodashGet from 'lodash/get'; import styles, {getNavigationModalCardStyle} from '../../../styles/styles'; import withWindowDimensions, {windowDimensionsPropTypes} from '../../../components/withWindowDimensions'; import CONST from '../../../CONST'; @@ -64,6 +67,26 @@ import ValidateLogin2FANewWorkspacePage from '../../../pages/ValidateLogin2FANew import WorkspaceSettingsDrawerNavigator from './WorkspaceSettingsDrawerNavigator'; import defaultScreenOptions from './defaultScreenOptions'; +Onyx.connect({ + key: ONYXKEYS.MY_PERSONAL_DETAILS, + callback: (val) => { + if (!val) { + return; + } + + const timezone = lodashGet(val, 'timezone', {}); + const currentTimezone = moment.tz.guess(true); + + // If the current timezone is different than the user's timezone, and their timezone is set to automatic + // then update their timezone. + if (_.isObject(timezone) && timezone.automatic && timezone.selected !== currentTimezone) { + timezone.selected = currentTimezone; + // eslint-disable-next-line no-use-before-define + PersonalDetails.setPersonalDetails({timezone}); + } + }, +}); + const RootStack = createCustomModalStackNavigator(); // We want to delay the re-rendering for components(e.g. ReportActionCompose) diff --git a/src/libs/actions/PersonalDetails.js b/src/libs/actions/PersonalDetails.js index a14f8fde10f07..269e021b95a44 100644 --- a/src/libs/actions/PersonalDetails.js +++ b/src/libs/actions/PersonalDetails.js @@ -3,7 +3,6 @@ import lodashGet from 'lodash/get'; import lodashMerge from 'lodash/merge'; import Onyx from 'react-native-onyx'; import Str from 'expensify-common/lib/str'; -import moment from 'moment'; import ONYXKEYS from '../../ONYXKEYS'; import CONST from '../../CONST'; import NetworkConnection from '../NetworkConnection'; @@ -24,26 +23,6 @@ Onyx.connect({ callback: val => personalDetails = val, }); -Onyx.connect({ - key: ONYXKEYS.MY_PERSONAL_DETAILS, - callback: (val) => { - if (!val) { - return; - } - - const timezone = lodashGet(val, 'timezone', {}); - const currentTimezone = moment.tz.guess(true); - - // If the current timezone is different than the user's timezone, and their timezone is set to automatic - // then update their timezone. - if (_.isObject(timezone) && timezone.automatic && timezone.selected !== currentTimezone) { - timezone.selected = currentTimezone; - // eslint-disable-next-line no-use-before-define - setPersonalDetails({timezone}); - } - }, -}); - /** * Returns the URL for a user's avatar and handles someone not having any avatar at all * From 918edfc51daee0d2bd61ca48c02d91a4877f78c2 Mon Sep 17 00:00:00 2001 From: chiragsalian Date: Thu, 5 Aug 2021 10:41:59 -0700 Subject: [PATCH 4/4] remove useless eslint --- src/libs/Navigation/AppNavigator/AuthScreens.js | 1 - 1 file changed, 1 deletion(-) diff --git a/src/libs/Navigation/AppNavigator/AuthScreens.js b/src/libs/Navigation/AppNavigator/AuthScreens.js index fbd5ca5673549..d07c214aced7c 100644 --- a/src/libs/Navigation/AppNavigator/AuthScreens.js +++ b/src/libs/Navigation/AppNavigator/AuthScreens.js @@ -81,7 +81,6 @@ Onyx.connect({ // then update their timezone. if (_.isObject(timezone) && timezone.automatic && timezone.selected !== currentTimezone) { timezone.selected = currentTimezone; - // eslint-disable-next-line no-use-before-define PersonalDetails.setPersonalDetails({timezone}); } },