Skip to content

Commit

Permalink
chore: optimized device connect refresh info
Browse files Browse the repository at this point in the history
  • Loading branch information
ByteZhang1024 committed Mar 21, 2024
1 parent 513b0bf commit abd7092
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ const Item = ({ item, onPress, connected }: ItemProps) => {
};

type IDeviceListProps = {
onSelected: (device: Device) => void;
onSelected: (device: Device | undefined) => void;
disableSaveDevice?: boolean;
};
export interface IDeviceListInstance {
Expand Down Expand Up @@ -108,15 +108,16 @@ function DeviceListFC(
}, []);

const selectDevice = useCallback(
(device: Device) => {
setSelectedId(device.connectId);
storeSelectedId(device.connectId);
(device: Device | undefined) => {
setSelectedId(device?.connectId ?? '');
storeSelectedId(device?.connectId ?? '');
onSelected(device);
},
[onSelected]
);

const searchDevices = useCallback(async () => {
selectDevice(undefined);
if (!sdk) return alert(intl.formatMessage({ id: 'tip__sdk_not_ready' }));

const response = await sdk.searchDevices();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ function FirmwareLocalFile({ title, type, onUpdate }: FirmwareLocalFileProps) {
}

interface FirmwareUpdateProps {
selectDevice: Device | null;
selectDevice: Device | undefined;
onReconnectDevice: () => void;
onDisconnectDevice: () => void;
}
Expand Down Expand Up @@ -150,7 +150,12 @@ function FirmwareUpdate({

useEffect(() => {
if (!sdk) return;
if (selectDevice?.connectId == null && selectDevice?.features == null) return;
if (selectDevice?.connectId == null || selectDevice?.features == null) {
setFeatures(undefined);
setOnekeyFeatures(undefined);
return;
}

setConnecting(true);
setFeatures(undefined);
sdk
Expand Down Expand Up @@ -393,7 +398,7 @@ function FirmwareUpdate({
}

export default function FirmwareScreen() {
const [selectedDevice, setSelectedDevice] = useState<Device | null>(null);
const [selectedDevice, setSelectedDevice] = useState<Device | undefined>(undefined);
const deviceListInstanceRef = useRef<IDeviceListInstance>(null);

return (
Expand All @@ -402,9 +407,8 @@ export default function FirmwareScreen() {
<DeviceList ref={deviceListInstanceRef} onSelected={setSelectedDevice} disableSaveDevice />
<FirmwareUpdate
selectDevice={selectedDevice}
onDisconnectDevice={() => setSelectedDevice(null)}
onDisconnectDevice={() => setSelectedDevice(undefined)}
onReconnectDevice={() => {
setSelectedDevice(null);
deviceListInstanceRef.current?.searchDevices();
}}
/>
Expand Down

0 comments on commit abd7092

Please sign in to comment.