Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 0 additions & 23 deletions src/hooks/useAutoUpdateTimezone.ts

This file was deleted.

72 changes: 57 additions & 15 deletions src/libs/Navigation/AppNavigator/AuthScreens.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
import {useNavigation} from '@react-navigation/native';
import type {StackCardInterpolationProps} from '@react-navigation/stack';
import React, {memo, useContext, useEffect, useMemo, useRef, useState} from 'react';
import type {OnyxEntry} from 'react-native-onyx';
import Onyx from 'react-native-onyx';
import ComposeProviders from '@components/ComposeProviders';
import DelegateNoAccessModalProvider from '@components/DelegateNoAccessModalProvider';
import FullScreenLoadingIndicator from '@components/FullscreenLoadingIndicator';
Expand All @@ -12,7 +14,6 @@
import {SearchContextProvider} from '@components/Search/SearchContext';
import {useSearchRouterContext} from '@components/Search/SearchRouter/SearchRouterContext';
import SearchRouterModal from '@components/Search/SearchRouter/SearchRouterModal';
import useAutoUpdateTimezone from '@hooks/useAutoUpdateTimezone';
import useCurrentUserPersonalDetails from '@hooks/useCurrentUserPersonalDetails';
import useOnboardingFlowRouter from '@hooks/useOnboardingFlow';
import useOnyx from '@hooks/useOnyx';
Expand Down Expand Up @@ -50,6 +51,7 @@
import * as App from '@userActions/App';
import * as Download from '@userActions/Download';
import * as Modal from '@userActions/Modal';
import * as PersonalDetails from '@userActions/PersonalDetails';
import * as Report from '@userActions/Report';
import * as Session from '@userActions/Session';
import * as User from '@userActions/User';
Expand All @@ -61,6 +63,8 @@
import ROUTES from '@src/ROUTES';
import SCREENS from '@src/SCREENS';
import type * as OnyxTypes from '@src/types/onyx';
import type {SelectedTimezone, Timezone} from '@src/types/onyx/PersonalDetails';
import {isEmptyObject} from '@src/types/utils/EmptyObject';
import type ReactComponentModule from '@src/types/utils/ReactComponentModule';
import attachmentModalScreenOptions from './attachmentModalScreenOptions';
import createRootStackNavigator from './createRootStackNavigator';
Expand Down Expand Up @@ -105,8 +109,58 @@
User.subscribeToUserEvents();
});
}
let timezone: Timezone | null;
let currentAccountID = -1;
let lastUpdateIDAppliedToClient: OnyxEntry<number>;

Onyx.connect({

Check warning on line 116 in src/libs/Navigation/AppNavigator/AuthScreens.tsx

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.SESSION,
callback: (value) => {
// When signed out, val hasn't accountID
if (!(value && 'accountID' in value)) {
currentAccountID = -1;
timezone = null;
return;
}

currentAccountID = value.accountID ?? CONST.DEFAULT_NUMBER_ID;

if (Navigation.isActiveRoute(ROUTES.SIGN_IN_MODAL)) {
// This means sign in in RHP was successful, so we can subscribe to user events
initializePusher();
}
},
});

Onyx.connect({

Check warning on line 135 in src/libs/Navigation/AppNavigator/AuthScreens.tsx

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.PERSONAL_DETAILS_LIST,
callback: (value) => {
if (!value || !isEmptyObject(timezone)) {
return;
}

timezone = value?.[currentAccountID]?.timezone ?? {};
const currentTimezone = Intl.DateTimeFormat().resolvedOptions().timeZone as SelectedTimezone;

// If the current timezone is different than the user's timezone, and their timezone is set to automatic
// then update their timezone.
if (!isEmptyObject(currentTimezone) && timezone?.automatic && timezone?.selected !== currentTimezone) {
PersonalDetails.updateAutomaticTimezone({
automatic: true,
selected: currentTimezone,
});
}
},
});

Onyx.connect({

Check warning on line 156 in src/libs/Navigation/AppNavigator/AuthScreens.tsx

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.ONYX_UPDATES_LAST_UPDATE_ID_APPLIED_TO_CLIENT,
callback: (value) => {
lastUpdateIDAppliedToClient = value;
},
});

function handleNetworkReconnect(lastUpdateIDAppliedToClient: number | undefined, isLoadingApp: boolean) {
function handleNetworkReconnect(isLoadingApp: boolean) {
if (isLoadingApp) {
App.openApp();
} else {
Expand Down Expand Up @@ -158,7 +212,6 @@
const {shouldUseNarrowLayout} = useResponsiveLayout();
const rootNavigatorScreenOptions = useRootNavigatorScreenOptions();
const currentUserPersonalDetails = useCurrentUserPersonalDetails();
const [lastUpdateIDAppliedToClient] = useOnyx(ONYXKEYS.ONYX_UPDATES_LAST_UPDATE_ID_APPLIED_TO_CLIENT, {canBeMissing: true});
const [isLoadingApp] = useOnyx(ONYXKEYS.IS_LOADING_APP, {canBeMissing: true});
const {toggleSearch} = useSearchRouterContext();
const currentUrl = getCurrentUrl();
Expand Down Expand Up @@ -200,17 +253,6 @@
);
}, [onboardingCompanySize, isOnboardingCompleted, isOnboardingLoading, prevIsOnboardingLoading]);

useEffect(() => {
if (!Navigation.isActiveRoute(ROUTES.SIGN_IN_MODAL)) {
return;
}
// This means sign in in RHP was successful, so we can subscribe to user events
initializePusher();
// eslint-disable-next-line react-compiler/react-compiler, react-hooks/exhaustive-deps
}, [session]);

useAutoUpdateTimezone();

useEffect(() => {
NavBarManager.setButtonStyle(theme.navigationBarButtonsStyle);

Expand Down Expand Up @@ -248,7 +290,7 @@
}

NetworkConnection.listenForReconnect();
NetworkConnection.onReconnect(() => handleNetworkReconnect(lastUpdateIDAppliedToClient, !!isLoadingApp));
NetworkConnection.onReconnect(() => handleNetworkReconnect(!!isLoadingApp));
PusherConnectionManager.init();
initializePusher();
// Sometimes when we transition from old dot to new dot, the client is not the leader
Expand Down
97 changes: 0 additions & 97 deletions tests/unit/useAutoUpdateTimezoneTest.tsx

This file was deleted.

Loading