From 93130934f2fa00252a9c05e8a310bc67eec6a528 Mon Sep 17 00:00:00 2001 From: Cassie Tarakajian Date: Wed, 18 Jan 2017 16:43:41 -0500 Subject: [PATCH] initial autosave update fixes --- client/modules/IDE/pages/IDEView.jsx | 50 +++++++++++++++++----------- 1 file changed, 31 insertions(+), 19 deletions(-) diff --git a/client/modules/IDE/pages/IDEView.jsx b/client/modules/IDE/pages/IDEView.jsx index a5ff6000..38e18df8 100644 --- a/client/modules/IDE/pages/IDEView.jsx +++ b/client/modules/IDE/pages/IDEView.jsx @@ -49,10 +49,10 @@ class IDEView extends React.Component { } // if autosave is on and the user is the owner of the project - if (this.props.preferences.autosave - && this.isUserOwner()) { - this.autosaveInterval = setInterval(this.props.autosaveProject, 30000); - } + // if (this.props.preferences.autosave + // && this.isUserOwner()) { + // this.autosaveInterval = setInterval(this.props.autosaveProject, 30000); + // } } this.consoleSize = this.props.ide.consoleIsExpanded ? 150 : 29; @@ -96,33 +96,45 @@ class IDEView extends React.Component { } componentDidUpdate(prevProps) { - // 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 + if (this.isUserOwner() && this.props.project.id) { + if (this.props.preferences.autosave && this.props.ide.unsavedChanges && !prevProps.ide.unsavedChanges) { + this.autosaveInterval = setTimeout(this.props.autosaveProject, 30000); } else if (this.autosaveInterval && !this.props.preferences.autosave && prevProps.preferences.autosave) { - clearInterval(this.autosaveInterval); + clearTimeout(this.autosaveInterval); this.autosaveInterval = null; } - } - - if (this.autosaveInterval && (!this.props.project.id || !this.isUserOwner())) { - clearInterval(this.autosaveInterval); + } else if (this.autosaveInterval) { + clearTimeout(this.autosaveInterval); 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) { this.props.router.setRouteLeaveHook(this.props.route, (route) => this.warnIfUnsavedChanges(route)); } } componentWillUnmount() { - clearInterval(this.autosaveInterval); + clearTimeout(this.autosaveInterval); this.autosaveInterval = null; this.consoleSize = undefined; this.sidebarSize = undefined;