Page MenuHomePhabricator

D5711.id18836.diff
No OneTemporary

D5711.id18836.diff

diff --git a/native/data/sqlite-context-provider.js b/native/data/sqlite-context-provider.js
--- a/native/data/sqlite-context-provider.js
+++ b/native/data/sqlite-context-provider.js
@@ -5,9 +5,7 @@
import ExitApp from 'react-native-exit-app';
import { useDispatch } from 'react-redux';
-import { setDraftStoreDrafts } from 'lib/actions/draft-actions';
-import { setMessageStoreMessages } from 'lib/actions/message-actions.js';
-import { setThreadStoreActionType } from 'lib/actions/thread-actions';
+import { setClientDBStoreActionType } from 'lib/actions/client-db-store-actions';
import { isLoggedIn } from 'lib/selectors/user-selectors';
import { logInActionSources } from 'lib/types/account-types';
import { fetchNewCookieFromNativeCredentials } from 'lib/utils/action-utils';
@@ -15,18 +13,14 @@
import { convertClientDBThreadInfosToRawThreadInfos } from 'lib/utils/thread-ops-utils';
import { commCoreModule } from '../native-modules';
+import { setStoreLoadedActionType } from '../redux/action-types';
import { useSelector } from '../redux/redux-utils';
import { StaffContext } from '../staff/staff-context';
import { isTaskCancelledError } from '../utils/error-handling';
import { useStaffCanSee } from '../utils/staff-utils';
-import { SQLiteContext } from './sqlite-context';
-type Props = {
- +children: React.Node,
-};
-
-function SQLiteContextProvider(props: Props): React.Node {
- const [storeLoaded, setStoreLoaded] = React.useState<boolean>(false);
+function SQLiteContextProvider(): React.Node {
+ const storeLoaded = useSelector(state => state.storeLoaded);
const dispatch = useDispatch();
const rehydrateConcluded = useSelector(
@@ -88,7 +82,7 @@
return;
}
if (!loggedIn) {
- setStoreLoaded(true);
+ dispatch({ type: setStoreLoadedActionType });
return;
}
(async () => {
@@ -103,21 +97,17 @@
threads,
);
dispatch({
- type: setThreadStoreActionType,
- payload: { threadInfos: threadInfosFromDB },
- });
- dispatch({
- type: setMessageStoreMessages,
- payload: messages,
- });
- dispatch({
- type: setDraftStoreDrafts,
- payload: drafts,
+ type: setClientDBStoreActionType,
+ payload: {
+ drafts,
+ messages,
+ threadStore: { threadInfos: threadInfosFromDB },
+ currentUserID: currentLoggedInUserID,
+ },
});
- setStoreLoaded(true);
} catch (setStoreException) {
if (isTaskCancelledError(setStoreException)) {
- setStoreLoaded(true);
+ dispatch({ type: setStoreLoadedActionType });
return;
}
if (staffCanSee) {
@@ -135,7 +125,7 @@
urlPrefix,
logInActionSources.sqliteLoadFailure,
);
- setStoreLoaded(true);
+ dispatch({ type: setStoreLoadedActionType });
} catch (fetchCookieException) {
if (staffCanSee) {
Alert.alert(
@@ -151,6 +141,7 @@
}
})();
}, [
+ currentLoggedInUserID,
handleSensitiveData,
loggedIn,
cookie,
@@ -161,18 +152,7 @@
urlPrefix,
]);
- const contextValue = React.useMemo(
- () => ({
- storeLoaded,
- }),
- [storeLoaded],
- );
-
- return (
- <SQLiteContext.Provider value={contextValue}>
- {props.children}
- </SQLiteContext.Provider>
- );
+ return null;
}
export { SQLiteContextProvider };
diff --git a/native/data/sqlite-context.js b/native/data/sqlite-context.js
deleted file mode 100644
--- a/native/data/sqlite-context.js
+++ /dev/null
@@ -1,13 +0,0 @@
-// @flow
-
-import * as React from 'react';
-
-export type SQLiteContextType = {
- +storeLoaded: boolean,
-};
-
-const SQLiteContext: React.Context<?SQLiteContextType> = React.createContext(
- null,
-);
-
-export { SQLiteContext };
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
@@ -2,13 +2,13 @@
import * as SplashScreen from 'expo-splash-screen';
import * as React from 'react';
+import { useSelector } from 'react-redux';
import { PersistGate } from 'redux-persist/integration/react';
import MultimediaMessageTooltipModal from '../chat/multimedia-message-tooltip-modal.react';
import RobotextMessageTooltipModal from '../chat/robotext-message-tooltip-modal.react';
import ThreadSettingsMemberTooltipModal from '../chat/settings/thread-settings-member-tooltip-modal.react';
import TextMessageTooltipModal from '../chat/text-message-tooltip-modal.react';
-import { type SQLiteContextType, SQLiteContext } from '../data/sqlite-context';
import KeyboardStateContainer from '../keyboard/keyboard-state-container.react';
import CameraModal from '../media/camera-modal.react';
import ImageModal from '../media/image-modal.react';
@@ -60,10 +60,7 @@
const { navigation } = props;
const rootContext = React.useContext(RootContext);
- const localDatabaseContext: ?SQLiteContextType = React.useContext(
- SQLiteContext,
- );
- const storeLoadedFromLocalDatabase = localDatabaseContext?.storeLoaded;
+ const storeLoadedFromLocalDatabase = useSelector(state => state.storeLoaded);
const setNavStateInitialized =
rootContext && rootContext.setNavStateInitialized;
React.useEffect(() => {
diff --git a/native/root.react.js b/native/root.react.js
--- a/native/root.react.js
+++ b/native/root.react.js
@@ -247,21 +247,20 @@
<SafeAreaProvider initialMetrics={initialWindowMetrics}>
<ActionSheetProvider>
<ChatContextProvider>
- <SQLiteContextProvider>
- <ConnectedStatusBar />
- <ReduxPersistGate persistor={getPersistor()}>
- {gated}
- </ReduxPersistGate>
- <PersistedStateGate>
- <Socket
- detectUnsupervisedBackgroundRef={
- detectUnsupervisedBackgroundRef
- }
- />
- </PersistedStateGate>
- {navigation}
- <NavigationHandler />
- </SQLiteContextProvider>
+ <SQLiteContextProvider />
+ <ConnectedStatusBar />
+ <ReduxPersistGate persistor={getPersistor()}>
+ {gated}
+ </ReduxPersistGate>
+ <PersistedStateGate>
+ <Socket
+ detectUnsupervisedBackgroundRef={
+ detectUnsupervisedBackgroundRef
+ }
+ />
+ </PersistedStateGate>
+ {navigation}
+ <NavigationHandler />
</ChatContextProvider>
</ActionSheetProvider>
</SafeAreaProvider>
diff --git a/native/selectors/app-state-selectors.js b/native/selectors/app-state-selectors.js
--- a/native/selectors/app-state-selectors.js
+++ b/native/selectors/app-state-selectors.js
@@ -1,15 +1,12 @@
// @flow
-import * as React from 'react';
import { useSelector } from 'react-redux';
-import { SQLiteContext } from '../data/sqlite-context';
-
function usePersistedStateLoaded(): boolean {
const rehydrateConcluded = useSelector(state => !!state._persist?.rehydrated);
- const localDatabaseContext = React.useContext(SQLiteContext);
+ const storeLoaded = useSelector(state => state.storeLoaded);
- return rehydrateConcluded && !!localDatabaseContext?.storeLoaded;
+ return rehydrateConcluded && storeLoaded;
}
export { usePersistedStateLoaded };

File Metadata

Mime Type
text/plain
Expires
Sun, Dec 1, 11:42 PM (19 h, 7 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2606298
Default Alt Text
D5711.id18836.diff (7 KB)

Event Timeline