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();
|
win.focus();
|
||||||
}
|
}
|
||||||
|
|
||||||
export function newProject() {
|
export function resetProject() {
|
||||||
browserHistory.push('/');
|
|
||||||
return {
|
return {
|
||||||
type: ActionTypes.RESET_PROJECT
|
type: ActionTypes.RESET_PROJECT
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function newProject() {
|
||||||
|
browserHistory.push('/');
|
||||||
|
return resetProject();
|
||||||
|
}
|
||||||
|
|
||||||
export function cloneProject() {
|
export function cloneProject() {
|
||||||
return (dispatch, getState) => {
|
return (dispatch, getState) => {
|
||||||
const state = getState();
|
const state = getState();
|
||||||
|
|
|
@ -45,7 +45,9 @@ class IDEView extends React.Component {
|
||||||
this.props.stopSketch();
|
this.props.stopSketch();
|
||||||
if (this.props.params.project_id) {
|
if (this.props.params.project_id) {
|
||||||
const id = this.props.params.project_id;
|
const id = this.props.params.project_id;
|
||||||
this.props.getProject(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 autosave is on and the user is the owner of the project
|
||||||
if (this.props.preferences.autosave
|
if (this.props.preferences.autosave
|
||||||
|
@ -62,7 +64,7 @@ class IDEView extends React.Component {
|
||||||
this.isMac = navigator.userAgent.toLowerCase().indexOf('mac') !== -1;
|
this.isMac = navigator.userAgent.toLowerCase().indexOf('mac') !== -1;
|
||||||
document.addEventListener('keydown', this.handleGlobalKeydown, false);
|
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();
|
window.onbeforeunload = () => this.warnIfUnsavedChanges();
|
||||||
|
|
||||||
|
@ -85,7 +87,13 @@ class IDEView extends React.Component {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (nextProps.params.project_id && !this.props.params.project_id) {
|
if (nextProps.params.project_id && !this.props.params.project_id) {
|
||||||
this.props.getProject(nextProps.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) {
|
if (nextProps.preferences.theme !== this.props.preferences.theme) {
|
||||||
|
@ -115,7 +123,7 @@ class IDEView extends React.Component {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.props.route.path !== prevProps.route.path) {
|
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
|
warnIfUnsavedChanges(route) { // eslint-disable-line
|
||||||
if (this.props.ide.unsavedChanges) {
|
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.')) {
|
if (!window.confirm('Are you sure you want to leave this page? You have unsaved changes.')) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -591,7 +603,8 @@ IDEView.propTypes = {
|
||||||
endSketchRefresh: PropTypes.func.isRequired,
|
endSketchRefresh: PropTypes.func.isRequired,
|
||||||
startRefreshSketch: PropTypes.func.isRequired,
|
startRefreshSketch: PropTypes.func.isRequired,
|
||||||
setBlobUrl: PropTypes.func.isRequired,
|
setBlobUrl: PropTypes.func.isRequired,
|
||||||
setPreviousPath: PropTypes.func.isRequired
|
setPreviousPath: PropTypes.func.isRequired,
|
||||||
|
resetProject: PropTypes.func.isRequired
|
||||||
};
|
};
|
||||||
|
|
||||||
function mapStateToProps(state) {
|
function mapStateToProps(state) {
|
||||||
|
|
Loading…
Reference in a new issue