1
1
import classNames from 'classnames' ;
2
2
import { connect } from 'react-redux' ;
3
+ import { compose } from 'redux' ;
3
4
import { defineMessages , FormattedMessage , injectIntl , intlShape } from 'react-intl' ;
4
5
import PropTypes from 'prop-types' ;
5
6
import bindAll from 'lodash.bindall' ;
@@ -27,6 +28,7 @@ import LoginDropdown from './login-dropdown.jsx';
27
28
import SB3Downloader from '../../containers/sb3-downloader.jsx' ;
28
29
import DeletionRestorer from '../../containers/deletion-restorer.jsx' ;
29
30
import TurboMode from '../../containers/turbo-mode.jsx' ;
31
+ import ConfirmReplaceHOC from './confirm-replace-hoc.jsx' ;
30
32
31
33
import { openTipsLibrary } from '../../reducers/modals' ;
32
34
import { setPlayer } from '../../reducers/mode' ;
@@ -164,17 +166,14 @@ class MenuBar extends React.Component {
164
166
document . removeEventListener ( 'keydown' , this . handleKeyPress ) ;
165
167
}
166
168
handleClickNew ( ) {
167
- let readyToReplaceProject = true ;
168
169
// if the project is dirty, and user owns the project, we will autosave.
169
170
// but if they are not logged in and can't save, user should consider
170
171
// downloading or logging in first.
171
172
// Note that if user is logged in and editing someone else's project,
172
173
// they'll lose their work.
173
- if ( this . props . projectChanged && ! this . props . canCreateNew ) {
174
- readyToReplaceProject = confirm ( // eslint-disable-line no-alert
175
- this . props . intl . formatMessage ( sharedMessages . replaceProjectWarning )
176
- ) ;
177
- }
174
+ const readyToReplaceProject = this . props . confirmReadyToReplaceProject (
175
+ this . props . intl . formatMessage ( sharedMessages . replaceProjectWarning )
176
+ ) ;
178
177
this . props . onRequestCloseFile ( ) ;
179
178
if ( readyToReplaceProject ) {
180
179
this . props . onClickNew ( this . props . canSave && this . props . canCreateNew ) ;
@@ -759,7 +758,6 @@ MenuBar.propTypes = {
759
758
onShare : PropTypes . func ,
760
759
onToggleLoginOpen : PropTypes . func ,
761
760
onUpdateProjectTitle : PropTypes . func ,
762
- projectChanged : PropTypes . bool ,
763
761
projectTitle : PropTypes . string ,
764
762
renderLogin : PropTypes . func ,
765
763
sessionExists : PropTypes . bool ,
@@ -785,7 +783,6 @@ const mapStateToProps = (state, ownProps) => {
785
783
languageMenuOpen : languageMenuOpen ( state ) ,
786
784
locale : state . locales . locale ,
787
785
loginMenuOpen : loginMenuOpen ( state ) ,
788
- projectChanged : state . scratchGui . projectChanged ,
789
786
projectTitle : state . scratchGui . projectTitle ,
790
787
sessionExists : state . session && typeof state . session . session !== 'undefined' ,
791
788
username : user ? user . username : null ,
@@ -815,7 +812,11 @@ const mapDispatchToProps = dispatch => ({
815
812
onSeeCommunity : ( ) => dispatch ( setPlayer ( true ) )
816
813
} ) ;
817
814
818
- export default injectIntl ( connect (
819
- mapStateToProps ,
820
- mapDispatchToProps
821
- ) ( MenuBar ) ) ;
815
+ export default compose (
816
+ injectIntl ,
817
+ ConfirmReplaceHOC ,
818
+ connect (
819
+ mapStateToProps ,
820
+ mapDispatchToProps
821
+ )
822
+ ) ( MenuBar ) ;
0 commit comments