mirror of
https://github.com/pybricks/pybricks-code.git
synced 2026-09-12 01:23:52 +00:00
40 lines
1.2 KiB
TypeScript
40 lines
1.2 KiB
TypeScript
// 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-i18n';
|
|
import replIcon from './images/repl.svg';
|
|
|
|
type StateProps = Pick<ActionButtonProps, 'enabled'>;
|
|
type DispatchProps = Pick<ActionButtonProps, 'onAction'>;
|
|
type OwnProps = Pick<ActionButtonProps, 'id'>;
|
|
|
|
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);
|