Files
pybricks-code/src/hub/ReplButton.tsx
T
David Lechner 7f9e6bd4db Fix download and run race condition
It was possible for a program to start and finish running before the
final checksum message was received, which resulted in a bad state
(run button disabled).

This fixes it by using proper didStart/didFinish/didFailToFinish
actions for the download saga and updates the reducer to handle all
cases.
2021-04-07 12:28:36 -05:00

38 lines
1.1 KiB
TypeScript

// SPDX-License-Identifier: MIT
// Copyright (c) 2020 The Pybricks Authors
import { connect } from 'react-redux';
import { RootState } from '../reducers';
import ActionButton, { ActionButtonProps } from '../toolbar/ActionButton';
import { TooltipId } from '../toolbar/i18n';
import { repl } from './actions';
import { HubRuntimeState } from './reducers';
import replIcon from './repl.svg';
type StateProps = Pick<ActionButtonProps, 'enabled'>;
type DispatchProps = Pick<ActionButtonProps, 'onAction'>;
type OwnProps = Pick<ActionButtonProps, 'id'> &
Pick<ActionButtonProps, 'keyboardShortcut'>;
const mapStateToProps = (state: RootState): StateProps => ({
enabled: state.hub.runtime === HubRuntimeState.Idle,
});
const mapDispatchToProps: DispatchProps = {
onAction: repl,
};
const mergeProps = (
stateProps: StateProps,
dispatchProps: DispatchProps,
ownProps: OwnProps,
): ActionButtonProps => ({
tooltip: TooltipId.Repl,
icon: replIcon,
...ownProps,
...stateProps,
...dispatchProps,
});
export default connect(mapStateToProps, mapDispatchToProps, mergeProps)(ActionButton);