From 384cb78a743913619c9ec342b3c6905f8d57774f Mon Sep 17 00:00:00 2001 From: David Lechner Date: Sat, 18 Dec 2021 11:04:42 -0600 Subject: [PATCH] editor: convert OpenButton to function --- src/editor/OpenButton.tsx | 56 +++++++++++++++++++-------------------- 1 file changed, 28 insertions(+), 28 deletions(-) diff --git a/src/editor/OpenButton.tsx b/src/editor/OpenButton.tsx index e6a02140..0728701b 100644 --- a/src/editor/OpenButton.tsx +++ b/src/editor/OpenButton.tsx @@ -1,39 +1,39 @@ // SPDX-License-Identifier: MIT -// Copyright (c) 2020 The Pybricks Authors +// Copyright (c) 2020-2021 The Pybricks Authors -import { connect } from 'react-redux'; -import * as notification from '../notifications/actions'; +import React from 'react'; +import { useDispatch, useSelector } from 'react-redux'; +import * as notificationActions from '../notifications/actions'; import { RootState } from '../reducers'; import OpenFileButton, { OpenFileButtonProps } from '../toolbar/OpenFileButton'; import { TooltipId } from '../toolbar/i18n'; -import * as editor from './actions'; +import * as editorActions from './actions'; import openIcon from './open.svg'; -type StateProps = Pick; -type DispatchProps = Pick; -type OwnProps = Pick; +type OpenButtonProps = Pick; -const mapStateToProps = (state: RootState): StateProps => ({ - enabled: state.editor.current !== null, -}); +const OpenButton: React.FunctionComponent = (props) => { + const editor = useSelector((state: RootState) => state.editor.current); + const dispatch = useDispatch(); -const mapDispatchToProps: DispatchProps = { - onFile: editor.open, - onReject: (file) => - notification.add('error', `'${file.name}' is not a valid python file.`), + return ( + dispatch(editorActions.open(data))} + onReject={(file) => + dispatch( + notificationActions.add( + 'error', + `'${file.name}' is not a valid python file.`, + ), + ) + } + {...props} + /> + ); }; -const mergeProps = ( - stateProps: StateProps, - dispatchProps: DispatchProps, - ownProps: OwnProps, -): OpenFileButtonProps => ({ - fileExtension: '.py', - tooltip: TooltipId.Open, - icon: openIcon, - ...ownProps, - ...stateProps, - ...dispatchProps, -}); - -export default connect(mapStateToProps, mapDispatchToProps, mergeProps)(OpenFileButton); +export default OpenButton;