// SPDX-License-Identifier: MIT // Copyright (c) 2020 The Pybricks Authors import { connect } from 'react-redux'; import { Dispatch } from '../actions'; import * as editor from '../actions/editor'; import { RootState } from '../reducers'; import ActionButton, { ActionButtonProps } from './ActionButton'; import { TooltipId } from './button-i18n'; import downloadIcon from './images/download.svg'; type StateProps = Pick; type DispatchProps = Pick; type OwnProps = Pick & Pick; const mapStateToProps = (state: RootState): StateProps => ({ enabled: state.editor.current !== null, }); const mapDispatchToProps = (dispatch: Dispatch): DispatchProps => ({ onAction: (): void => { dispatch(editor.saveAs()); }, }); const mergeProps = ( stateProps: StateProps, dispatchProps: DispatchProps, ownProps: OwnProps, ): ActionButtonProps => ({ tooltip: TooltipId.SaveAs, icon: downloadIcon, ...ownProps, ...stateProps, ...dispatchProps, }); export default connect(mapStateToProps, mapDispatchToProps, mergeProps)(ActionButton);