Skip to content
This repository has been archived by the owner on Jun 16, 2022. It is now read-only.

Commit

Permalink
Fixes LL-724
Browse files Browse the repository at this point in the history
  • Loading branch information
gre committed May 7, 2019
1 parent caa53ed commit 936357a
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 29 deletions.
13 changes: 3 additions & 10 deletions src/components/SelectDevice/BluetoothEmpty.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,15 @@

import React, { PureComponent } from "react";
import { View, StyleSheet } from "react-native";
import { withNavigation } from "react-navigation";

import { Trans } from "react-i18next";
import ConnectNanoXIllustration from "../../icons/ConnectNanoXIllustration";
import Button from "../Button";

type Props = {
navigation: *,
onPairNewDevice: () => void,
};

class BluetoothEmpty extends PureComponent<Props> {
onPairNewDevice = () => {
const { navigation } = this.props;
navigation.navigate("PairDevices");
};

render() {
return (
<View>
Expand All @@ -26,7 +19,7 @@ class BluetoothEmpty extends PureComponent<Props> {
event="PairDevice"
type="primary"
title={<Trans i18nKey="SelectDevice.deviceNotFoundPairNewDevice" />}
onPress={this.onPairNewDevice}
onPress={this.props.onPairNewDevice}
/>
</View>
);
Expand All @@ -40,4 +33,4 @@ const styles = StyleSheet.create({
},
});

export default withNavigation(BluetoothEmpty);
export default BluetoothEmpty;
43 changes: 30 additions & 13 deletions src/components/SelectDevice/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ type Props = {
filter?: TransportModule => boolean,
deviceModelId: DeviceNames,
navigation: NavigationScreenProp<*>,
autoSelectOnAdd?: boolean,
};

type OwnProps = Props & {
Expand Down Expand Up @@ -81,12 +82,23 @@ const ORBar = () => (
/>
);

const getAll = ({ knownDevices }, { devices }) =>
devices.concat(
knownDevices.map(d => ({
deviceId: d.id,
deviceName: d.name || "",
wired: false,
modelId: "nanoX",
})),
);

class SelectDevice extends Component<OwnProps, State> {
static defaultProps = {
steps: [],
filter: () => true,
showDiscoveredDevices: true,
showKnownDevices: true,
autoSelectOnAdd: false,
};

state = {
Expand Down Expand Up @@ -160,8 +172,21 @@ class SelectDevice extends Component<OwnProps, State> {
};

onPairNewDevice = () => {
const { navigation } = this.props;
navigation.navigate("PairDevices");
const { navigation, autoSelectOnAdd } = this.props;
let opts;
if (autoSelectOnAdd) {
opts = {
onDone: deviceId => {
const device = getAll(this.props, this.state).find(
d => d.deviceId === deviceId,
);
if (device) {
this.onSelect(device);
}
},
};
}
navigation.navigate("PairDevices", opts);
};

renderItem = (item: *) => (
Expand All @@ -179,23 +204,15 @@ class SelectDevice extends Component<OwnProps, State> {

render() {
const {
knownDevices,
steps,
onStepEntered,
usbOnly,
withArrows,
deviceModelId,
} = this.props;
const { devices, connecting } = this.state;
const { connecting } = this.state;

const all: DeviceMeta[] = devices.concat(
knownDevices.map(d => ({
deviceId: d.id,
deviceName: d.name || "",
wired: false,
modelId: "nanoX",
})),
);
const all: DeviceMeta[] = getAll(this.props, this.state);

const [ble, other] = all.reduce(
([ble, other], device) =>
Expand All @@ -210,7 +227,7 @@ class SelectDevice extends Component<OwnProps, State> {
{usbOnly && withArrows ? (
<UsbPlaceholder />
) : ble.length === 0 ? (
<BluetoothEmpty />
<BluetoothEmpty onPairNewDevice={this.onPairNewDevice} />
) : (
<View>
<BluetoothHeader />
Expand Down
1 change: 1 addition & 0 deletions src/screens/Onboarding/steps/pair-new.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ class OnboardingStepPairNew extends Component<OnboardingStepProps> {
usbOnly={usbOnly}
deviceModelId={deviceModelId}
onSelect={this.props.next}
autoSelectOnAdd
/>
</OnboardingLayout>
);
Expand Down
10 changes: 7 additions & 3 deletions src/screens/PairDevices/Paired.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import NanoX from "../../icons/NanoX";
class Paired extends PureComponent<{
deviceId: string,
deviceName: string,
onContinue: () => *,
onContinue: (deviceId: string) => *,
navigation: *,
genuine: boolean,
}> {
Expand All @@ -30,8 +30,12 @@ class Paired extends PureComponent<{
});
};

onContinue = () => {
this.props.onContinue(this.props.deviceId);
};

render() {
const { deviceId, onContinue, genuine } = this.props;
const { deviceId, genuine } = this.props;
return (
<View style={styles.root}>
<TrackScreen category="PairDevices" name="Paired" />
Expand Down Expand Up @@ -68,7 +72,7 @@ class Paired extends PureComponent<{
event="PairDevicesContinue"
type="primary"
title={<Trans i18nKey="PairDevices.Paired.action" />}
onPress={onContinue}
onPress={this.onContinue}
/>
</View>
</View>
Expand Down
15 changes: 12 additions & 3 deletions src/screens/PairDevices/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,11 @@ import ScanningTimeout from "./ScanningTimeout";
import RenderError from "./RenderError";

type Props = {
navigation: NavigationScreenProp<*>,
navigation: NavigationScreenProp<{
params: {
onDone?: (deviceId: string) => void,
},
}>,
knownDevices: DeviceLike[],
addKnownDevice: DeviceLike => *,
};
Expand Down Expand Up @@ -147,8 +151,13 @@ class PairDevices extends Component<Props, State> {
}
};

onDone = () => {
this.props.navigation.goBack();
onDone = (deviceId: string) => {
const { navigation } = this.props;
const onDone = navigation.getParam("onDone");
navigation.goBack();
if (onDone) {
onDone(deviceId);
}
};

render() {
Expand Down

0 comments on commit 936357a

Please sign in to comment.