fix #185
This commit is contained in:
parent
66b83df0f2
commit
167828b872
2 changed files with 26 additions and 9 deletions
|
@ -136,13 +136,17 @@ export function exportProjectAsZip(projectId) {
|
|||
win.focus();
|
||||
}
|
||||
|
||||
export function newProject() {
|
||||
browserHistory.push('/');
|
||||
export function resetProject() {
|
||||
return {
|
||||
type: ActionTypes.RESET_PROJECT
|
||||
};
|
||||
}
|
||||
|
||||
export function newProject() {
|
||||
browserHistory.push('/');
|
||||
return resetProject();
|
||||
}
|
||||
|
||||
export function cloneProject() {
|
||||
return (dispatch, getState) => {
|
||||
const state = getState();
|
||||
|
|
|
@ -45,7 +45,9 @@ class IDEView extends React.Component {
|
|||
this.props.stopSketch();
|
||||
if (this.props.params.project_id) {
|
||||
const id = this.props.params.project_id;
|
||||
if (id !== this.props.project.id) {
|
||||
this.props.getProject(id);
|
||||
}
|
||||
|
||||
// if autosave is on and the user is the owner of the project
|
||||
if (this.props.preferences.autosave
|
||||
|
@ -62,7 +64,7 @@ class IDEView extends React.Component {
|
|||
this.isMac = navigator.userAgent.toLowerCase().indexOf('mac') !== -1;
|
||||
document.addEventListener('keydown', this.handleGlobalKeydown, false);
|
||||
|
||||
this.props.router.setRouteLeaveHook(this.props.route, () => this.warnIfUnsavedChanges());
|
||||
this.props.router.setRouteLeaveHook(this.props.route, (route) => this.warnIfUnsavedChanges(route));
|
||||
|
||||
window.onbeforeunload = () => this.warnIfUnsavedChanges();
|
||||
|
||||
|
@ -85,8 +87,14 @@ class IDEView extends React.Component {
|
|||
}
|
||||
|
||||
if (nextProps.params.project_id && !this.props.params.project_id) {
|
||||
if (nextProps.params.project_id !== nextProps.project.id) {
|
||||
this.props.getProject(nextProps.params.project_id);
|
||||
}
|
||||
}
|
||||
|
||||
if (!nextProps.params.project_id && this.props.params.project_id) {
|
||||
this.props.resetProject();
|
||||
}
|
||||
|
||||
if (nextProps.preferences.theme !== this.props.preferences.theme) {
|
||||
document.body.className = nextProps.preferences.theme;
|
||||
|
@ -115,7 +123,7 @@ class IDEView extends React.Component {
|
|||
}
|
||||
|
||||
if (this.props.route.path !== prevProps.route.path) {
|
||||
this.props.router.setRouteLeaveHook(this.props.route, () => this.warnIfUnsavedChanges());
|
||||
this.props.router.setRouteLeaveHook(this.props.route, (route) => this.warnIfUnsavedChanges(route));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -168,8 +176,12 @@ class IDEView extends React.Component {
|
|||
}
|
||||
}
|
||||
|
||||
warnIfUnsavedChanges() { // eslint-disable-line
|
||||
if (this.props.ide.unsavedChanges) {
|
||||
warnIfUnsavedChanges(route) { // eslint-disable-line
|
||||
if (route && (route.action === 'PUSH' && (route.pathname === '/login' || route.pathname === '/signup'))) {
|
||||
// don't warn
|
||||
} else if (route && this.props.location.pathname === '/login' || this.props.location.pathname === '/signup') {
|
||||
// don't warn
|
||||
} else if (this.props.ide.unsavedChanges) {
|
||||
if (!window.confirm('Are you sure you want to leave this page? You have unsaved changes.')) {
|
||||
return false;
|
||||
}
|
||||
|
@ -591,7 +603,8 @@ IDEView.propTypes = {
|
|||
endSketchRefresh: PropTypes.func.isRequired,
|
||||
startRefreshSketch: PropTypes.func.isRequired,
|
||||
setBlobUrl: PropTypes.func.isRequired,
|
||||
setPreviousPath: PropTypes.func.isRequired
|
||||
setPreviousPath: PropTypes.func.isRequired,
|
||||
resetProject: PropTypes.func.isRequired
|
||||
};
|
||||
|
||||
function mapStateToProps(state) {
|
||||
|
|
Loading…
Reference in a new issue