Files
pybricks-code/src/components/StopButton.tsx
T
2020-04-17 17:16:23 -05:00

38 lines
1.1 KiB
TypeScript

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);