diff --git a/src/components/menu-bar/menu-bar.jsx b/src/components/menu-bar/menu-bar.jsx index 5c957525c..1857a6315 100644 --- a/src/components/menu-bar/menu-bar.jsx +++ b/src/components/menu-bar/menu-bar.jsx @@ -28,7 +28,7 @@ import LoginDropdown from './login-dropdown.jsx'; import SB3Downloader from '../../containers/sb3-downloader.jsx'; import DeletionRestorer from '../../containers/deletion-restorer.jsx'; import TurboMode from '../../containers/turbo-mode.jsx'; -import ConfirmReplaceHOC from './confirm-replace-hoc.jsx'; +import MenuBarHOC from '../../containers/menu-bar-hoc.jsx'; import {openTipsLibrary} from '../../reducers/modals'; import {setPlayer} from '../../reducers/mode'; @@ -192,7 +192,7 @@ class MenuBar extends React.Component { this.props.onRequestCloseFile(); } handleClickSeeCommunity (waitForUpdate) { - if (this.props.canSave && this.props.projectChanged) { // save before transitioning to project page + if (this.props.shouldSaveBeforeTransition()) { // save before transitioning to project page this.props.autoUpdateProject(); waitForUpdate(true); // queue the transition to project page } else { @@ -705,6 +705,7 @@ MenuBar.propTypes = { canSave: PropTypes.bool, canShare: PropTypes.bool, className: PropTypes.string, + confirmReadyToReplaceProject: PropTypes.func, editMenuOpen: PropTypes.bool, enableCommunity: PropTypes.bool, fileMenuOpen: PropTypes.bool, @@ -741,6 +742,7 @@ MenuBar.propTypes = { projectTitle: PropTypes.string, renderLogin: PropTypes.func, sessionExists: PropTypes.bool, + shouldSaveBeforeTransition: PropTypes.func, showComingSoon: PropTypes.bool, username: PropTypes.string, vm: PropTypes.instanceOf(VM).isRequired @@ -794,7 +796,7 @@ const mapDispatchToProps = dispatch => ({ export default compose( injectIntl, - ConfirmReplaceHOC, + MenuBarHOC, connect( mapStateToProps, mapDispatchToProps diff --git a/src/components/menu-bar/confirm-replace-hoc.jsx b/src/containers/menu-bar-hoc.jsx similarity index 68% rename from src/components/menu-bar/confirm-replace-hoc.jsx rename to src/containers/menu-bar-hoc.jsx index 5631b800b..a33f36107 100644 --- a/src/components/menu-bar/confirm-replace-hoc.jsx +++ b/src/containers/menu-bar-hoc.jsx @@ -3,16 +3,16 @@ import PropTypes from 'prop-types'; import bindAll from 'lodash.bindall'; import React from 'react'; -const ConfirmReplaceHOC = function (WrappedComponent) { - class ConfirmReplaceProject extends React.PureComponent { +const MenuBarHOC = function (WrappedComponent) { + class MenuBarComponent extends React.PureComponent { constructor (props) { super(props); bindAll(this, [ - 'confirmReadyToReplaceProject' + 'confirmReadyToReplaceProject', + 'shouldSaveBeforeTransition' ]); } - confirmReadyToReplaceProject (message) { let readyToReplaceProject = true; if (this.props.projectChanged && !this.props.canCreateNew) { @@ -20,7 +20,9 @@ const ConfirmReplaceHOC = function (WrappedComponent) { } return readyToReplaceProject; } - + shouldSaveBeforeTransition () { + return (this.props.canSave && this.props.projectChanged); + } render () { const { /* eslint-disable no-unused-vars */ @@ -30,13 +32,15 @@ const ConfirmReplaceHOC = function (WrappedComponent) { } = this.props; return (); } } - ConfirmReplaceProject.propTypes = { + MenuBarComponent.propTypes = { canCreateNew: PropTypes.bool, + canSave: PropTypes.bool, projectChanged: PropTypes.bool }; @@ -44,7 +48,7 @@ const ConfirmReplaceHOC = function (WrappedComponent) { projectChanged: state.scratchGui.projectChanged }); - return connect(_mapStateToProps)(ConfirmReplaceProject); + return connect(_mapStateToProps)(MenuBarComponent); }; -export default ConfirmReplaceHOC; +export default MenuBarHOC;