mirror of
https://github.com/pybricks/pybricks-code.git
synced 2026-09-12 09:36:27 +00:00
It can take a while (especially on Windows) before the connection is ready and the other buttons become enabled. So use a spinner to let the user know that we are working on it. Issue: https://github.com/pybricks/support/issues/315
45 lines
1.5 KiB
TypeScript
45 lines
1.5 KiB
TypeScript
// SPDX-License-Identifier: MIT
|
|
// Copyright (c) 2020-2021 The Pybricks Authors
|
|
|
|
import { connect } from 'react-redux';
|
|
import { toggleBluetooth } from '../ble/actions';
|
|
import { BleConnectionState } from '../ble/reducers';
|
|
import { BootloaderConnectionState } from '../lwp3-bootloader/reducers';
|
|
import { RootState } from '../reducers';
|
|
import ActionButton, { ActionButtonProps } from '../toolbar/ActionButton';
|
|
import { TooltipId } from '../toolbar/i18n';
|
|
import btConnectedIcon from './bt-connected.svg';
|
|
import btDisconnectedIcon from './bt-disconnected.svg';
|
|
|
|
type StateProps = Pick<
|
|
ActionButtonProps,
|
|
'tooltip' | 'icon' | 'enabled' | 'showProgress'
|
|
>;
|
|
type DispatchProps = Pick<ActionButtonProps, 'onAction'>;
|
|
|
|
const mapStateToProps = (state: RootState): StateProps => {
|
|
if (
|
|
state.ble.connection === BleConnectionState.Disconnected &&
|
|
state.bootloader.connection === BootloaderConnectionState.Disconnected
|
|
) {
|
|
return {
|
|
tooltip: TooltipId.BluetoothConnect,
|
|
icon: btDisconnectedIcon,
|
|
enabled: true,
|
|
};
|
|
} else {
|
|
return {
|
|
tooltip: TooltipId.BluetoothDisconnect,
|
|
icon: btConnectedIcon,
|
|
enabled: state.ble.connection === BleConnectionState.Connected,
|
|
showProgress: state.ble.connection === BleConnectionState.Connecting,
|
|
};
|
|
}
|
|
};
|
|
|
|
const mapDispatchToProps: DispatchProps = {
|
|
onAction: toggleBluetooth,
|
|
};
|
|
|
|
export default connect(mapStateToProps, mapDispatchToProps)(ActionButton);
|