Skip to content

Commit e5f7060

Browse files
committed
Merge branch 'master' of github.com:jurgelenas/expresslrs-configurator
2 parents 8e2e6bf + 3889df1 commit e5f7060

File tree

1 file changed

+26
-5
lines changed

1 file changed

+26
-5
lines changed

src/ui/views/ConfiguratorView/index.tsx

+26-5
Original file line numberDiff line numberDiff line change
@@ -677,27 +677,48 @@ const ConfiguratorView: FunctionComponent<ConfiguratorViewProps> = (props) => {
677677
if (dnsDevice) {
678678
const targetName = dnsDevice.target.toUpperCase();
679679

680-
const device = deviceTargets?.find((item) => {
680+
// if targetName is an empty string, then return
681+
if (targetName.trim().length === 0) {
682+
return;
683+
}
684+
685+
const deviceMatches = deviceTargets?.filter((item) => {
681686
return item.targets.find((target) => {
682687
return target.name.toUpperCase().startsWith(targetName);
683688
});
684689
});
685690

691+
if (!deviceMatches || deviceMatches.length === 0) {
692+
return;
693+
}
694+
695+
// if multiple device matches are found, then don't select any of them
696+
// we do not know which one is correct and do not want to pick the wrong device.
697+
if (deviceMatches.length > 1) {
698+
console.error(
699+
`multiple device matches found for target ${targetName}!`
700+
);
701+
return;
702+
}
703+
704+
const device = deviceMatches[0];
705+
686706
const dTarget =
687707
device?.targets.find((target) => {
688708
return target.flashingMethod === FlashingMethod.WIFI;
689709
})?.name ||
690710
device?.targets[0].name ||
691711
null;
692712

693-
setDeviceTarget(dTarget);
713+
if (dTarget !== deviceTarget) {
714+
setDeviceTarget(dTarget);
715+
deviceOptionsRef?.current?.scrollIntoView({ behavior: 'smooth' });
716+
}
694717

695718
setWifiDevice(dnsDevice.ip);
696-
697-
deviceOptionsRef?.current?.scrollIntoView({ behavior: 'smooth' });
698719
}
699720
},
700-
[deviceTargets, networkDevices]
721+
[deviceTarget, deviceTargets, networkDevices]
701722
);
702723

703724
useEffect(() => {

0 commit comments

Comments
 (0)