Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F3447980
D14116.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
D14116.diff
View Options
diff --git a/native/account/qr-auth/secondary-device-qr-code-scanner.react.js b/native/account/qr-auth/secondary-device-qr-code-scanner.react.js
--- a/native/account/qr-auth/secondary-device-qr-code-scanner.react.js
+++ b/native/account/qr-auth/secondary-device-qr-code-scanner.react.js
@@ -1,16 +1,21 @@
// @flow
+import { useFocusEffect } from '@react-navigation/core';
import { useNavigation } from '@react-navigation/native';
import { BarCodeScanner, type BarCodeEvent } from 'expo-barcode-scanner';
-import invariant from 'invariant';
import * as React from 'react';
import { View, Text } from 'react-native';
-import { QRAuthContext } from './qr-auth-context.js';
+import { useCheckIfPrimaryDevice } from 'lib/hooks/primary-device-hooks.js';
+
import type { QRAuthNavigationProp } from './qr-auth-navigator.react.js';
import TextInput from '../../components/text-input.react.js';
import HeaderRightTextButton from '../../navigation/header-right-text-button.react.js';
-import type { NavigationRoute } from '../../navigation/route-names.js';
+import {
+ type NavigationRoute,
+ ConnectSecondaryDeviceRouteName,
+ QRAuthNotPrimaryDeviceRouteName,
+} from '../../navigation/route-names.js';
import { useStyles, useColors } from '../../themes/colors.js';
import Alert from '../../utils/alert.js';
import { deviceIsEmulator } from '../../utils/url-utils.js';
@@ -29,12 +34,9 @@
const [urlInput, setURLInput] = React.useState('');
const styles = useStyles(unboundStyles);
- const { goBack, setOptions } = useNavigation();
+ const { goBack, setOptions, navigate } = useNavigation();
const { panelForegroundTertiaryLabel } = useColors();
-
- const qrAuthContext = React.useContext(QRAuthContext);
- invariant(qrAuthContext, 'qrAuthContext should be set');
- const { onConnect } = qrAuthContext;
+ const checkIfPrimaryDevice = useCheckIfPrimaryDevice();
React.useEffect(() => {
void (async () => {
@@ -58,8 +60,8 @@
return;
}
- await onConnect(urlInput);
- }, [onConnect, urlInput]);
+ navigate(ConnectSecondaryDeviceRouteName, { data: urlInput });
+ }, [navigate, urlInput]);
const buttonDisabled = !urlInput;
React.useEffect(() => {
@@ -77,6 +79,12 @@
});
}, [buttonDisabled, onPressSave, setOptions]);
+ const onFocusCallback = React.useCallback(() => {
+ setScanned(false);
+ }, [setScanned]);
+
+ useFocusEffect(onFocusCallback);
+
const onChangeText = React.useCallback(
(text: string) => setURLInput(text),
[],
@@ -86,24 +94,17 @@
(barCodeEvent: BarCodeEvent) => {
setScanned(true);
const { data } = barCodeEvent;
- Alert.alert(
- 'Connect with this device?',
- 'Are you sure you want to allow this device to log in to your account?',
- [
- {
- text: 'Cancel',
- style: 'cancel',
- onPress: goBack,
- },
- {
- text: 'Connect',
- onPress: () => onConnect(data),
- },
- ],
- { cancelable: false },
- );
+ void (async () => {
+ const isPrimaryDevice = await checkIfPrimaryDevice();
+
+ if (isPrimaryDevice) {
+ navigate(ConnectSecondaryDeviceRouteName, { data });
+ } else {
+ navigate(QRAuthNotPrimaryDeviceRouteName);
+ }
+ })();
},
- [goBack, onConnect],
+ [checkIfPrimaryDevice, navigate],
);
if (hasPermission === null) {
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Thu, Dec 12, 7:51 PM (21 h, 21 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2649279
Default Alt Text
D14116.diff (3 KB)
Attached To
Mode
D14116: [native] navigate to proper screen after scanning QR code
Attached
Detach File
Event Timeline
Log In to Comment