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' ;
@@ -25,6 +26,7 @@ import LoginDropdown from './login-dropdown.jsx';
25
26
import SB3Downloader from '../../containers/sb3-downloader.jsx' ;
26
27
import DeletionRestorer from '../../containers/deletion-restorer.jsx' ;
27
28
import TurboMode from '../../containers/turbo-mode.jsx' ;
29
+ import ConfirmReplaceHOC from './confirm-replace-hoc.jsx' ;
28
30
29
31
import { openTipsLibrary } from '../../reducers/modals' ;
30
32
import { setPlayer } from '../../reducers/mode' ;
@@ -160,17 +162,14 @@ class MenuBar extends React.Component {
160
162
document . removeEventListener ( 'keydown' , this . handleKeyPress ) ;
161
163
}
162
164
handleClickNew ( ) {
163
- let readyToReplaceProject = true ;
164
165
// if the project is dirty, and user owns the project, we will autosave.
165
166
// but if they are not logged in and can't save, user should consider
166
167
// downloading or logging in first.
167
168
// Note that if user is logged in and editing someone else's project,
168
169
// they'll lose their work.
169
- if ( this . props . projectChanged && ! this . props . canCreateNew ) {
170
- readyToReplaceProject = confirm ( // eslint-disable-line no-alert
171
- this . props . intl . formatMessage ( sharedMessages . replaceProjectWarning )
172
- ) ;
173
- }
170
+ const readyToReplaceProject = this . props . confirmReadyToReplaceProject (
171
+ this . props . intl . formatMessage ( sharedMessages . replaceProjectWarning )
172
+ ) ;
174
173
this . props . onRequestCloseFile ( ) ;
175
174
if ( readyToReplaceProject ) {
176
175
this . props . onClickNew ( this . props . canSave && this . props . canCreateNew ) ;
@@ -752,7 +751,6 @@ MenuBar.propTypes = {
752
751
onShare : PropTypes . func ,
753
752
onToggleLoginOpen : PropTypes . func ,
754
753
onUpdateProjectTitle : PropTypes . func ,
755
- projectChanged : PropTypes . bool ,
756
754
projectTitle : PropTypes . string ,
757
755
renderLogin : PropTypes . func ,
758
756
sessionExists : PropTypes . bool ,
@@ -776,7 +774,6 @@ const mapStateToProps = state => {
776
774
isShowingProject : getIsShowingProject ( loadingState ) ,
777
775
languageMenuOpen : languageMenuOpen ( state ) ,
778
776
loginMenuOpen : loginMenuOpen ( state ) ,
779
- projectChanged : state . scratchGui . projectChanged ,
780
777
projectTitle : state . scratchGui . projectTitle ,
781
778
sessionExists : state . session && typeof state . session . session !== 'undefined' ,
782
779
username : user ? user . username : null
@@ -803,7 +800,11 @@ const mapDispatchToProps = dispatch => ({
803
800
onSeeCommunity : ( ) => dispatch ( setPlayer ( true ) )
804
801
} ) ;
805
802
806
- export default injectIntl ( connect (
807
- mapStateToProps ,
808
- mapDispatchToProps
809
- ) ( MenuBar ) ) ;
803
+ export default compose (
804
+ injectIntl ,
805
+ ConfirmReplaceHOC ,
806
+ connect (
807
+ mapStateToProps ,
808
+ mapDispatchToProps
809
+ )
810
+ ) ( MenuBar ) ;
0 commit comments