initial autosave update fixes

This commit is contained in:
Cassie Tarakajian 2017-01-18 16:43:41 -05:00
parent 697458a7ef
commit 93130934f2

View file

@ -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,25 +96,37 @@ 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);
this.autosaveInterval = null;
} }
if (this.autosaveInterval && (!this.props.project.id || !this.isUserOwner())) { // // if user is the owner of the project
clearInterval(this.autosaveInterval); // if (this.isUserOwner()) {
this.autosaveInterval = null; // // 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));
@ -122,7 +134,7 @@ class IDEView extends React.Component {
} }
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;