Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F3558437
D14035.id46153.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
3 KB
Referenced Files
None
Subscribers
None
D14035.id46153.diff
View Options
diff --git a/native/components/version-supported.react.js b/native/components/version-supported.react.js
--- a/native/components/version-supported.react.js
+++ b/native/components/version-supported.react.js
@@ -3,31 +3,19 @@
import * as React from 'react';
import {
- useLogOut,
- logOutActionTypes,
useVersionSupportedByIdentity,
versionSupportedByIdentityActionTypes,
} from 'lib/actions/user-actions.js';
-import { isLoggedIn } from 'lib/selectors/user-selectors.js';
import { useDispatchActionPromise } from 'lib/utils/redux-promise-utils.js';
-import { useSelector } from '../redux/redux-utils.js';
-import { appOutOfDateAlertDetails } from '../utils/alert-messages.js';
-import Alert from '../utils/alert.js';
+import { useShowVersionUnsupportedAlert } from '../utils/hooks.js';
function VersionSupportedChecker(): React.Node {
const hasRun = React.useRef(false);
- const loggedIn = useSelector(isLoggedIn);
const dispatchActionPromise = useDispatchActionPromise();
- const callLogOut = useLogOut();
const callVersionSupportedByIdentity = useVersionSupportedByIdentity();
-
- const onUsernameAlertAcknowledged = React.useCallback(() => {
- if (loggedIn) {
- void dispatchActionPromise(logOutActionTypes, callLogOut());
- }
- }, [callLogOut, dispatchActionPromise, loggedIn]);
+ const showVersionUnsupportedAlert = useShowVersionUnsupportedAlert(true);
const checkVersionSupport = React.useCallback(async () => {
try {
@@ -40,24 +28,14 @@
if (isVersionSupported) {
return;
}
- Alert.alert(
- appOutOfDateAlertDetails.title,
- appOutOfDateAlertDetails.message,
- [
- {
- text: 'OK',
- onPress: onUsernameAlertAcknowledged,
- },
- ],
- { cancelable: false },
- );
+ showVersionUnsupportedAlert();
} catch (error) {
console.log('Error checking version:', error);
}
}, [
callVersionSupportedByIdentity,
dispatchActionPromise,
- onUsernameAlertAcknowledged,
+ showVersionUnsupportedAlert,
]);
React.useEffect(() => {
diff --git a/native/utils/hooks.js b/native/utils/hooks.js
--- a/native/utils/hooks.js
+++ b/native/utils/hooks.js
@@ -3,6 +3,14 @@
import AsyncStorage from '@react-native-async-storage/async-storage';
import * as React from 'react';
+import { useLogOut, logOutActionTypes } from 'lib/actions/user-actions.js';
+import { isLoggedIn } from 'lib/selectors/user-selectors.js';
+import { useDispatchActionPromise } from 'lib/utils/redux-promise-utils.js';
+
+import { useSelector } from '../redux/redux-utils.js';
+import { appOutOfDateAlertDetails } from '../utils/alert-messages.js';
+import Alert from '../utils/alert.js';
+
function useOnFirstLaunchEffect(uniqueKey: string, effect: () => mixed) {
const [started, setStarted] = React.useState(false);
@@ -26,4 +34,30 @@
}, [effect, started, uniqueKey]);
}
-export { useOnFirstLaunchEffect };
+function useShowVersionUnsupportedAlert(shouldCallLogOut: boolean): () => void {
+ const loggedIn = useSelector(isLoggedIn);
+ const dispatchActionPromise = useDispatchActionPromise();
+ const callLogOut = useLogOut();
+
+ const onUsernameAlertAcknowledged = React.useCallback(() => {
+ if (loggedIn && shouldCallLogOut) {
+ void dispatchActionPromise(logOutActionTypes, callLogOut());
+ }
+ }, [callLogOut, dispatchActionPromise, loggedIn, shouldCallLogOut]);
+
+ return React.useCallback(() => {
+ Alert.alert(
+ appOutOfDateAlertDetails.title,
+ appOutOfDateAlertDetails.message,
+ [
+ {
+ text: 'OK',
+ onPress: onUsernameAlertAcknowledged,
+ },
+ ],
+ { cancelable: false },
+ );
+ }, [onUsernameAlertAcknowledged]);
+}
+
+export { useOnFirstLaunchEffect, useShowVersionUnsupportedAlert };
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Sat, Dec 28, 3:09 AM (5 h, 59 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2723593
Default Alt Text
D14035.id46153.diff (3 KB)
Attached To
Mode
D14035: [native] Extract showing version unsupported alert to separate hook
Attached
Detach File
Event Timeline
Log In to Comment