diff --git a/lib/selectors/app-state-selectors.js b/lib/selectors/app-state-selectors.js new file mode 100644 --- /dev/null +++ b/lib/selectors/app-state-selectors.js @@ -0,0 +1,12 @@ +// @flow + +import { useSelector } from '../utils/redux-utils.js'; + +function usePersistedStateLoaded(): boolean { + const rehydrateConcluded = useSelector(state => !!state._persist?.rehydrated); + const initialStateLoaded = useSelector(state => state.initialStateLoaded); + + return rehydrateConcluded && initialStateLoaded; +} + +export { usePersistedStateLoaded }; diff --git a/lib/types/redux-types.js b/lib/types/redux-types.js --- a/lib/types/redux-types.js +++ b/lib/types/redux-types.js @@ -209,6 +209,7 @@ +_persist: ?PersistState, +queuedDMOperations: QueuedDMOperations, +holderStore: HolderStore, + +initialStateLoaded: boolean, ... }; diff --git a/native/components/persisted-state-gate.js b/native/components/persisted-state-gate.js --- a/native/components/persisted-state-gate.js +++ b/native/components/persisted-state-gate.js @@ -2,7 +2,7 @@ import * as React from 'react'; -import { usePersistedStateLoaded } from '../selectors/app-state-selectors.js'; +import { usePersistedStateLoaded } from 'lib/selectors/app-state-selectors.js'; function PersistedStateGate(props: { +children: React.Node }): React.Node { const persistedStateLoaded = usePersistedStateLoaded(); diff --git a/native/data/sqlite-data-handler.js b/native/data/sqlite-data-handler.js --- a/native/data/sqlite-data-handler.js +++ b/native/data/sqlite-data-handler.js @@ -64,7 +64,7 @@ const returnsFalseSinceDoesntNeedToSupportCancellation = () => false; function SQLiteDataHandler(): React.Node { - const storeLoaded = useSelector(state => state.storeLoaded); + const initialStateLoaded = useSelector(state => state.initialStateLoaded); const dispatch = useDispatch(); const dispatchActionPromise = useDispatchActionPromise(); @@ -218,7 +218,7 @@ } const sensitiveDataHandled = handleSensitiveData(); - if (storeLoaded) { + if (initialStateLoaded) { return; } if (!loggedIn) { @@ -317,7 +317,7 @@ dispatch, rehydrateConcluded, staffCanSee, - storeLoaded, + initialStateLoaded, recoverData, callClearSensitiveData, mediaCacheContext, diff --git a/native/navigation/app-navigator.react.js b/native/navigation/app-navigator.react.js --- a/native/navigation/app-navigator.react.js +++ b/native/navigation/app-navigator.react.js @@ -81,7 +81,9 @@ const fontsLoaded = useLoadCommFonts(); const rootContext = React.useContext(RootContext); - const storeLoadedFromLocalDatabase = useSelector(state => state.storeLoaded); + const storeLoadedFromLocalDatabase = useSelector( + state => state.initialStateLoaded, + ); const setNavStateInitialized = rootContext && rootContext.setNavStateInitialized; React.useEffect(() => { diff --git a/native/navigation/navigation-handler.react.js b/native/navigation/navigation-handler.react.js --- a/native/navigation/navigation-handler.react.js +++ b/native/navigation/navigation-handler.react.js @@ -3,6 +3,7 @@ import * as React from 'react'; import { useIsLoggedInToIdentityAndAuthoritativeKeyserver } from 'lib/hooks/account-hooks.js'; +import { usePersistedStateLoaded } from 'lib/selectors/app-state-selectors.js'; import { logInActionType, logOutActionType } from './action-types.js'; import ModalPruner from './modal-pruner.react.js'; @@ -13,7 +14,6 @@ import ThreadScreenTracker from './thread-screen-tracker.react.js'; import { MissingRegistrationDataHandler } from '../account/registration/missing-registration-data/missing-registration-data-handler.react.js'; import DevTools from '../redux/dev-tools.react.js'; -import { usePersistedStateLoaded } from '../selectors/app-state-selectors.js'; const NavigationHandler: React.ComponentType<{}> = React.memo<{}>( function NavigationHandler() { diff --git a/native/redux/default-state.js b/native/redux/default-state.js --- a/native/redux/default-state.js +++ b/native/redux/default-state.js @@ -38,7 +38,7 @@ local: {}, currentAsOf: { [authoritativeKeyserverID]: 0 }, }, - storeLoaded: false, + initialStateLoaded: false, loadingStatuses: {}, calendarFilters: defaultCalendarFilters, dataLoaded: false, diff --git a/native/redux/handle-redux-migration-failure.js b/native/redux/handle-redux-migration-failure.js --- a/native/redux/handle-redux-migration-failure.js +++ b/native/redux/handle-redux-migration-failure.js @@ -15,7 +15,7 @@ 'deviceOrientation', 'frozen', 'threadStore', - 'storeLoaded', + 'initialStateLoaded', 'dbOpsStore', 'syncedMetadataStore', 'userStore', diff --git a/native/redux/redux-setup.js b/native/redux/redux-setup.js --- a/native/redux/redux-setup.js +++ b/native/redux/redux-setup.js @@ -241,13 +241,13 @@ if (action.type === setStoreLoadedActionType) { return { ...state, - storeLoaded: true, + initialStateLoaded: true, }; } if (action.type === setClientDBStoreActionType) { state = { ...state, - storeLoaded: true, + initialStateLoaded: true, }; const currentLoggedInUserID = state.currentUserInfo?.anonymous ? undefined diff --git a/native/redux/state-types.js b/native/redux/state-types.js --- a/native/redux/state-types.js +++ b/native/redux/state-types.js @@ -35,7 +35,7 @@ import type { LocalSettings } from '../types/local-settings-types.js'; const nonUserSpecificFieldsNative = [ - 'storeLoaded', + 'initialStateLoaded', 'loadingStatuses', 'customServer', 'lifecycleState', @@ -57,7 +57,7 @@ +threadStore: ThreadStore, +userStore: UserStore, +messageStore: MessageStore, - +storeLoaded: boolean, + +initialStateLoaded: boolean, +loadingStatuses: { [key: string]: { [idx: number]: LoadingStatus } }, +calendarFilters: $ReadOnlyArray, +dataLoaded: boolean, diff --git a/native/selectors/app-state-selectors.js b/native/selectors/app-state-selectors.js deleted file mode 100644 --- a/native/selectors/app-state-selectors.js +++ /dev/null @@ -1,12 +0,0 @@ -// @flow - -import { useSelector } from '../redux/redux-utils.js'; - -function usePersistedStateLoaded(): boolean { - const rehydrateConcluded = useSelector(state => !!state._persist?.rehydrated); - const storeLoaded = useSelector(state => state.storeLoaded); - - return rehydrateConcluded && storeLoaded; -} - -export { usePersistedStateLoaded };