Skip to content

Commit

Permalink
Merge branch 'master' of github.com:jurgelenas/expresslrs-configurator
Browse files Browse the repository at this point in the history
  • Loading branch information
jurgelenas committed Nov 4, 2021
2 parents 8e2e6bf + 3889df1 commit e5f7060
Showing 1 changed file with 26 additions and 5 deletions.
31 changes: 26 additions & 5 deletions src/ui/views/ConfiguratorView/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -677,27 +677,48 @@ const ConfiguratorView: FunctionComponent<ConfiguratorViewProps> = (props) => {
if (dnsDevice) {
const targetName = dnsDevice.target.toUpperCase();

const device = deviceTargets?.find((item) => {
// if targetName is an empty string, then return
if (targetName.trim().length === 0) {
return;
}

const deviceMatches = deviceTargets?.filter((item) => {
return item.targets.find((target) => {
return target.name.toUpperCase().startsWith(targetName);
});
});

if (!deviceMatches || deviceMatches.length === 0) {
return;
}

// if multiple device matches are found, then don't select any of them
// we do not know which one is correct and do not want to pick the wrong device.
if (deviceMatches.length > 1) {
console.error(
`multiple device matches found for target ${targetName}!`
);
return;
}

const device = deviceMatches[0];

const dTarget =
device?.targets.find((target) => {
return target.flashingMethod === FlashingMethod.WIFI;
})?.name ||
device?.targets[0].name ||
null;

setDeviceTarget(dTarget);
if (dTarget !== deviceTarget) {
setDeviceTarget(dTarget);
deviceOptionsRef?.current?.scrollIntoView({ behavior: 'smooth' });
}

setWifiDevice(dnsDevice.ip);

deviceOptionsRef?.current?.scrollIntoView({ behavior: 'smooth' });
}
},
[deviceTargets, networkDevices]
[deviceTarget, deviceTargets, networkDevices]
);

useEffect(() => {
Expand Down

0 comments on commit e5f7060

Please sign in to comment.