initial autosave update fixes
This commit is contained in:
parent
697458a7ef
commit
93130934f2
1 changed files with 31 additions and 19 deletions
|
@ -49,10 +49,10 @@ class IDEView extends React.Component {
|
||||||
}
|
}
|
||||||
|
|
||||||
// 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
|
||||||
&& this.isUserOwner()) {
|
// && this.isUserOwner()) {
|
||||||
this.autosaveInterval = setInterval(this.props.autosaveProject, 30000);
|
// this.autosaveInterval = setInterval(this.props.autosaveProject, 30000);
|
||||||
}
|
// }
|
||||||
}
|
}
|
||||||
|
|
||||||
this.consoleSize = this.props.ide.consoleIsExpanded ? 150 : 29;
|
this.consoleSize = this.props.ide.consoleIsExpanded ? 150 : 29;
|
||||||
|
@ -96,33 +96,45 @@ class IDEView extends React.Component {
|
||||||
}
|
}
|
||||||
|
|
||||||
componentDidUpdate(prevProps) {
|
componentDidUpdate(prevProps) {
|
||||||
// if user is the owner of the project
|
if (this.isUserOwner() && this.props.project.id) {
|
||||||
if (this.isUserOwner()) {
|
if (this.props.preferences.autosave && this.props.ide.unsavedChanges && !prevProps.ide.unsavedChanges) {
|
||||||
// if the user turns on autosave
|
this.autosaveInterval = setTimeout(this.props.autosaveProject, 30000);
|
||||||
// or the user saves the project for the first time
|
|
||||||
if (!this.autosaveInterval &&
|
|
||||||
((this.props.preferences.autosave && !prevProps.preferences.autosave) ||
|
|
||||||
(this.props.project.id && !prevProps.project.id))) {
|
|
||||||
this.autosaveInterval = setInterval(this.props.autosaveProject, 30000);
|
|
||||||
// if user turns off autosave preference
|
|
||||||
} else if (this.autosaveInterval && !this.props.preferences.autosave && prevProps.preferences.autosave) {
|
} else if (this.autosaveInterval && !this.props.preferences.autosave && prevProps.preferences.autosave) {
|
||||||
clearInterval(this.autosaveInterval);
|
clearTimeout(this.autosaveInterval);
|
||||||
this.autosaveInterval = null;
|
this.autosaveInterval = null;
|
||||||
}
|
}
|
||||||
}
|
} else if (this.autosaveInterval) {
|
||||||
|
clearTimeout(this.autosaveInterval);
|
||||||
if (this.autosaveInterval && (!this.props.project.id || !this.isUserOwner())) {
|
|
||||||
clearInterval(this.autosaveInterval);
|
|
||||||
this.autosaveInterval = null;
|
this.autosaveInterval = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// // if user is the owner of the project
|
||||||
|
// if (this.isUserOwner()) {
|
||||||
|
// // if the user turns on autosave
|
||||||
|
// // or the user saves the project for the first time
|
||||||
|
// if (!this.autosaveInterval &&
|
||||||
|
// ((this.props.preferences.autosave && !prevProps.preferences.autosave) ||
|
||||||
|
// (this.props.project.id && !prevProps.project.id))) {
|
||||||
|
// this.autosaveInterval = setInterval(this.props.autosaveProject, 30000);
|
||||||
|
// // if user turns off autosave preference
|
||||||
|
// } else if (this.autosaveInterval && !this.props.preferences.autosave && prevProps.preferences.autosave) {
|
||||||
|
// clearInterval(this.autosaveInterval);
|
||||||
|
// this.autosaveInterval = null;
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
|
// if (this.autosaveInterval && (!this.props.project.id || !this.isUserOwner())) {
|
||||||
|
// clearInterval(this.autosaveInterval);
|
||||||
|
// this.autosaveInterval = null;
|
||||||
|
// }
|
||||||
|
|
||||||
if (this.props.route.path !== prevProps.route.path) {
|
if (this.props.route.path !== prevProps.route.path) {
|
||||||
this.props.router.setRouteLeaveHook(this.props.route, (route) => this.warnIfUnsavedChanges(route));
|
this.props.router.setRouteLeaveHook(this.props.route, (route) => this.warnIfUnsavedChanges(route));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
componentWillUnmount() {
|
componentWillUnmount() {
|
||||||
clearInterval(this.autosaveInterval);
|
clearTimeout(this.autosaveInterval);
|
||||||
this.autosaveInterval = null;
|
this.autosaveInterval = null;
|
||||||
this.consoleSize = undefined;
|
this.consoleSize = undefined;
|
||||||
this.sidebarSize = undefined;
|
this.sidebarSize = undefined;
|
||||||
|
|
Loading…
Reference in a new issue