From 461021a3e91df91044ca39343304a559bafaf69e Mon Sep 17 00:00:00 2001 From: Jakub Butkiewicz Date: Tue, 26 Sep 2023 16:13:30 +0200 Subject: [PATCH 1/3] ref: move SignInRedirect to TS --- .../{SignInRedirect.js => SignInRedirect.ts} | 29 ++++++++----------- 1 file changed, 12 insertions(+), 17 deletions(-) rename src/libs/actions/{SignInRedirect.js => SignInRedirect.ts} (79%) diff --git a/src/libs/actions/SignInRedirect.js b/src/libs/actions/SignInRedirect.ts similarity index 79% rename from src/libs/actions/SignInRedirect.js rename to src/libs/actions/SignInRedirect.ts index a010621c4eea..e3f4bd51d1ad 100644 --- a/src/libs/actions/SignInRedirect.js +++ b/src/libs/actions/SignInRedirect.ts @@ -1,7 +1,5 @@ import Onyx from 'react-native-onyx'; -import lodashGet from 'lodash/get'; -import _ from 'underscore'; -import ONYXKEYS from '../../ONYXKEYS'; +import ONYXKEYS, {OnyxKey} from '../../ONYXKEYS'; import * as MainQueue from '../Network/MainQueue'; import * as PersistedRequests from './PersistedRequests'; import NetworkConnection from '../NetworkConnection'; @@ -12,8 +10,8 @@ import Navigation from '../Navigation/Navigation'; import * as ErrorUtils from '../ErrorUtils'; import * as SessionUtils from '../SessionUtils'; -let currentIsOffline; -let currentShouldForceOffline; +let currentIsOffline: boolean | undefined; +let currentShouldForceOffline: boolean | undefined; Onyx.connect({ key: ONYXKEYS.NETWORK, callback: (network) => { @@ -25,14 +23,11 @@ Onyx.connect({ }, }); -/** - * @param {String} errorMessage - */ -function clearStorageAndRedirect(errorMessage) { +function clearStorageAndRedirect(errorMessage?: string) { // Under certain conditions, there are key-values we'd like to keep in storage even when a user is logged out. // We pass these into the clear() method in order to avoid having to reset them on a delayed tick and getting // flashes of unwanted default state. - const keysToPreserve = []; + const keysToPreserve: OnyxKey[] = []; keysToPreserve.push(ONYXKEYS.NVP_PREFERRED_LOCALE); keysToPreserve.push(ONYXKEYS.ACTIVE_CLIENTS); keysToPreserve.push(ONYXKEYS.DEVICE_ID); @@ -58,15 +53,15 @@ function clearStorageAndRedirect(errorMessage) { */ function resetHomeRouteParams() { Navigation.isNavigationReady().then(() => { - const routes = navigationRef.current && lodashGet(navigationRef.current.getState(), 'routes'); - const homeRoute = _.find(routes, (route) => route.name === SCREENS.HOME); + const routes = navigationRef.current?.getState().routes; + const homeRoute = routes?.find((route) => route.name === SCREENS.HOME); - const emptyParams = {}; - _.keys(lodashGet(homeRoute, 'params')).forEach((paramKey) => { + const emptyParams: Record = {}; + Object.keys(homeRoute?.params ?? {}).forEach((paramKey) => { emptyParams[paramKey] = undefined; }); - Navigation.setParams(emptyParams, lodashGet(homeRoute, 'key', '')); + Navigation.setParams(emptyParams, homeRoute?.key ?? ''); Onyx.set(ONYXKEYS.IS_CHECKING_PUBLIC_ROOM, false); }); } @@ -79,9 +74,9 @@ function resetHomeRouteParams() { * * Normally this method would live in Session.js, but that would cause a circular dependency with Network.js. * - * @param {String} [errorMessage] error message to be displayed on the sign in page + * @param [errorMessage] error message to be displayed on the sign in page */ -function redirectToSignIn(errorMessage) { +function redirectToSignIn(errorMessage?: string) { MainQueue.clear(); HttpUtils.cancelPendingRequests(); PersistedRequests.clear(); From 89eb48823099a19687c898ad8eca9779b409b3e3 Mon Sep 17 00:00:00 2001 From: Jakub Butkiewicz Date: Thu, 28 Sep 2023 14:28:47 +0200 Subject: [PATCH 2/3] fix: added missing type in Session type --- src/types/onyx/Session.ts | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/types/onyx/Session.ts b/src/types/onyx/Session.ts index 75cb4f4818ad..746f9fb96c84 100644 --- a/src/types/onyx/Session.ts +++ b/src/types/onyx/Session.ts @@ -1,3 +1,5 @@ +import * as OnyxCommon from './OnyxCommon'; + type Session = { /** The user's email for the current session */ email?: string; @@ -12,6 +14,8 @@ type Session = { accountID?: number; autoAuthState?: string; + /** Server side errors keyed by microtime */ + errors?: OnyxCommon.Errors; }; export default Session; From 24e363ccfca64e176ced1b8ce7c10d893778e68e Mon Sep 17 00:00:00 2001 From: Jakub Butkiewicz Date: Mon, 16 Oct 2023 12:22:15 +0200 Subject: [PATCH 3/3] fix: resolved comment --- src/libs/actions/SignInRedirect.ts | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/src/libs/actions/SignInRedirect.ts b/src/libs/actions/SignInRedirect.ts index e3f4bd51d1ad..67f5f2d8586f 100644 --- a/src/libs/actions/SignInRedirect.ts +++ b/src/libs/actions/SignInRedirect.ts @@ -15,11 +15,8 @@ let currentShouldForceOffline: boolean | undefined; Onyx.connect({ key: ONYXKEYS.NETWORK, callback: (network) => { - if (!network) { - return; - } - currentIsOffline = network.isOffline; - currentShouldForceOffline = Boolean(network.shouldForceOffline); + currentIsOffline = network?.isOffline; + currentShouldForceOffline = network?.shouldForceOffline; }, });