wire up stop button

This commit is contained in:
David Lechner
2020-04-17 17:16:23 -05:00
parent 454475980a
commit 18417cb37c
3 changed files with 46 additions and 6 deletions
+37
View File
@@ -0,0 +1,37 @@
import { connect } from 'react-redux';
import { ThunkDispatch } from 'redux-thunk';
import { AnyAction } from 'redux';
import { RootState } from '../reducers';
import { HubRuntimeState } from '../reducers/hub';
import { stop } from '../actions/hub';
import ActionButton, { ActionButtonProps } from './ActionButton';
type Dispatch = ThunkDispatch<{}, {}, AnyAction>;
type StateProps = Pick<ActionButtonProps, 'enabled' | 'context'>;
type DispatchProps = Pick<ActionButtonProps, 'onAction'>;
type OwnProps = Pick<ActionButtonProps, 'id'>;
const mapStateToProps = (state: RootState): StateProps => ({
enabled: state.hub.runtime === HubRuntimeState.Running,
});
const mapDispatchToProps = (dispatch: Dispatch): DispatchProps => ({
onAction: (): void => {
dispatch(stop());
},
});
const mergeProps = (
stateProps: StateProps,
dispatchProps: DispatchProps,
ownProps: OwnProps,
): ActionButtonProps => ({
tooltip: 'Stop everything',
icon: 'stop.svg',
...ownProps,
...stateProps,
...dispatchProps,
});
export default connect(mapStateToProps, mapDispatchToProps, mergeProps)(ActionButton);
+2 -6
View File
@@ -7,6 +7,7 @@ import { BLEConnectionState } from '../reducers/ble';
import ActionButton from './ActionButton';
import BluetoothButton from './BluetoothButton';
import RunButton from './RunButton';
import StopButton from './StopButton';
interface ToolbarState {
bleState: BLEConnectionState;
@@ -35,12 +36,7 @@ class Toolbar extends React.Component<{}, ToolbarState> {
<ButtonGroup className="mr-2" size="lg">
<BluetoothButton id="bluetooth" />
<RunButton id="run" />
<ActionButton
id="stop"
tooltip="Stop everything"
icon="stop.svg"
onAction={this.onAction}
/>
<StopButton id="stop" />
</ButtonGroup>
<ButtonGroup className="mr-2" size="lg">
<ActionButton