From 517045623c930fe9aebb715739506aa119bd4c6b Mon Sep 17 00:00:00 2001 From: Cassie Tarakajian Date: Sat, 13 May 2017 20:47:41 -0400 Subject: [PATCH] fix autosave, which apparently had never worked --- client/modules/IDE/pages/IDEView.jsx | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/client/modules/IDE/pages/IDEView.jsx b/client/modules/IDE/pages/IDEView.jsx index c1a7425b..fb957d27 100644 --- a/client/modules/IDE/pages/IDEView.jsx +++ b/client/modules/IDE/pages/IDEView.jsx @@ -96,9 +96,14 @@ class IDEView extends React.Component { componentDidUpdate(prevProps) { if (this.isUserOwner() && this.props.project.id) { - if (this.props.preferences.autosave && this.props.ide.unsavedChanges && this.autosaveInterval === null && !this.props.ide.justOpenedProject) { - console.log('saving project in 30 seconds'); - this.autosaveInterval = setTimeout(this.props.autosaveProject, 30000); + if (this.props.preferences.autosave && this.props.ide.unsavedChanges && !this.props.ide.justOpenedProject) { + if (this.props.selectedFile.name === prevProps.selectedFile.name && this.props.selectedFile.content !== prevProps.selectedFile.content) { + if (this.autosaveInterval) { + clearTimeout(this.autosaveInterval); + } + console.log('will save project in 20 seconds'); + this.autosaveInterval = setTimeout(this.props.autosaveProject, 20000); + } } else if (this.autosaveInterval && !this.props.preferences.autosave) { clearTimeout(this.autosaveInterval); this.autosaveInterval = null; @@ -557,7 +562,8 @@ IDEView.propTypes = { updateFileContent: PropTypes.func.isRequired, selectedFile: PropTypes.shape({ id: PropTypes.string.isRequired, - content: PropTypes.string.isRequired + content: PropTypes.string.isRequired, + name: PropTypes.string.isRequired }).isRequired, setSelectedFile: PropTypes.func.isRequired, htmlFile: PropTypes.shape({