// SPDX-License-Identifier: MIT // Copyright (c) 2020 The Pybricks Authors import { connect } from 'react-redux'; import { Action, Dispatch } from '../actions'; import { repl } from '../actions/hub'; import { RootState } from '../reducers'; import { HubRuntimeState } from '../reducers/hub'; import ActionButton, { ActionButtonProps } from './ActionButton'; import { TooltipId } from './button'; import replIcon from './images/repl.svg'; type StateProps = Pick; type DispatchProps = Pick; type OwnProps = Pick; const mapStateToProps = (state: RootState): StateProps => ({ enabled: state.hub.runtime === HubRuntimeState.Idle || state.hub.runtime === HubRuntimeState.Error, }); const mapDispatchToProps = (dispatch: Dispatch): DispatchProps => ({ onAction: (): Action => dispatch(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);