Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F3381618
D5711.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
8 KB
Referenced Files
None
Subscribers
None
D5711.diff
View Options
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/data/sqlite-context-provider.js b/native/data/sqlite-data-handler.js
rename from native/data/sqlite-context-provider.js
rename to native/data/sqlite-data-handler.js
--- a/native/data/sqlite-context-provider.js
+++ b/native/data/sqlite-data-handler.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 SQLiteDataHandler(): 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 };
+export { SQLiteDataHandler };
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
@@ -22,7 +22,7 @@
import ChatContextProvider from './chat/chat-context-provider.react';
import PersistedStateGate from './components/persisted-state-gate';
import ConnectedStatusBar from './connected-status-bar.react';
-import { SQLiteContextProvider } from './data/sqlite-context-provider';
+import { SQLiteDataHandler } from './data/sqlite-data-handler';
import ErrorBoundary from './error-boundary.react';
import InputStateContainer from './input/input-state-container.react';
import LifecycleHandler from './lifecycle/lifecycle-handler.react';
@@ -247,21 +247,20 @@
<SafeAreaProvider initialMetrics={initialWindowMetrics}>
<ActionSheetProvider>
<ChatContextProvider>
- <SQLiteContextProvider>
- <ConnectedStatusBar />
- <ReduxPersistGate persistor={getPersistor()}>
- {gated}
- </ReduxPersistGate>
- <PersistedStateGate>
- <Socket
- detectUnsupervisedBackgroundRef={
- detectUnsupervisedBackgroundRef
- }
- />
- </PersistedStateGate>
- {navigation}
- <NavigationHandler />
- </SQLiteContextProvider>
+ <SQLiteDataHandler />
+ <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
Details
Attached
Mime Type
text/plain
Expires
Fri, Nov 29, 5:33 AM (21 h, 54 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2596060
Default Alt Text
D5711.diff (8 KB)
Attached To
Mode
D5711: Use new redux action and storeLoaded field
Attached
Detach File
Event Timeline
Log In to Comment