renamed confirm-replace-hoc to menu-bar-hoc; moved project changed checking there
This commit is contained in:
1 parent
416bc85455
commit
16024769c8
2 files changed
+17
-11
No files matched your search
@@ -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
|
||||
|
||||
@@ -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 (<WrappedComponent
|
||||
confirmReadyToReplaceProject={this.confirmReadyToReplaceProject}
|
||||
shouldSaveBeforeTransition={this.shouldSaveBeforeTransition}
|
||||
{...props}
|
||||
/>);
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
Reference in new issue
Block a user