diff --git a/src/hub/RunButton.tsx b/src/hub/RunButton.tsx index a19d12d1..409e4719 100644 --- a/src/hub/RunButton.tsx +++ b/src/hub/RunButton.tsx @@ -1,7 +1,8 @@ // SPDX-License-Identifier: MIT // Copyright (c) 2020-2021 The Pybricks Authors -import { connect } from 'react-redux'; +import React from 'react'; +import { useDispatch, useSelector } from 'react-redux'; import { RootState } from '../reducers'; import ActionButton, { ActionButtonProps } from '../toolbar/ActionButton'; import { TooltipId } from '../toolbar/i18n'; @@ -9,34 +10,30 @@ import { downloadAndRun } from './actions'; import { HubRuntimeState } from './reducers'; import runIcon from './run.svg'; -type StateProps = Pick; -type DispatchProps = Pick; -type OwnProps = Pick & +type RunButtonProps = Pick & Pick; -const mapStateToProps = (state: RootState): StateProps => ({ - enabled: - state.editor.current !== null && state.hub.runtime === HubRuntimeState.Idle, - showProgress: state.hub.runtime === HubRuntimeState.Loading, - progress: - state.hub.downloadProgress === null ? undefined : state.hub.downloadProgress, -}); +const RunButton: React.FunctionComponent = (props) => { + const editor = useSelector((state: RootState) => state.editor.current); + const downloadProgress = useSelector( + (state: RootState) => state.hub.downloadProgress, + ); + const runtime = useSelector((state: RootState) => state.hub.runtime); -const mapDispatchToProps: DispatchProps = { - onAction: downloadAndRun, + const dispatch = useDispatch(); + + return ( + dispatch(downloadAndRun())} + {...props} + /> + ); }; -const mergeProps = ( - stateProps: StateProps, - dispatchProps: DispatchProps, - ownProps: OwnProps, -): ActionButtonProps => ({ - tooltip: TooltipId.Run, - progressTooltip: TooltipId.RunProgress, - icon: runIcon, - ...ownProps, - ...stateProps, - ...dispatchProps, -}); - -export default connect(mapStateToProps, mapDispatchToProps, mergeProps)(ActionButton); +export default RunButton;