From c8253dd9230e859d8f72592ffc5ac1f7f46b1338 Mon Sep 17 00:00:00 2001 From: Cassie Tarakajian Date: Tue, 24 Jan 2017 13:04:51 -0500 Subject: [PATCH] #254 test all of the edge cases for autosaving, such as login and logout, changing the autosave preference --- client/modules/IDE/pages/IDEView.jsx | 35 +++++----------------------- client/modules/IDE/reducers/ide.js | 2 +- client/modules/User/actions.js | 4 +++- 3 files changed, 10 insertions(+), 31 deletions(-) diff --git a/client/modules/IDE/pages/IDEView.jsx b/client/modules/IDE/pages/IDEView.jsx index 38e18df8..ad209a40 100644 --- a/client/modules/IDE/pages/IDEView.jsx +++ b/client/modules/IDE/pages/IDEView.jsx @@ -47,12 +47,6 @@ class IDEView extends React.Component { if (id !== this.props.project.id) { this.props.getProject(id); } - - // 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); - // } } this.consoleSize = this.props.ide.consoleIsExpanded ? 150 : 29; @@ -67,6 +61,7 @@ class IDEView extends React.Component { window.onbeforeunload = () => this.warnIfUnsavedChanges(); document.body.className = this.props.preferences.theme; + this.autosaveInterval = null; } componentWillReceiveProps(nextProps) { @@ -97,9 +92,10 @@ class IDEView extends React.Component { componentDidUpdate(prevProps) { if (this.isUserOwner() && this.props.project.id) { - if (this.props.preferences.autosave && this.props.ide.unsavedChanges && !prevProps.ide.unsavedChanges) { + 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); - } else if (this.autosaveInterval && !this.props.preferences.autosave && prevProps.preferences.autosave) { + } else if (this.autosaveInterval && !this.props.preferences.autosave) { clearTimeout(this.autosaveInterval); this.autosaveInterval = null; } @@ -108,26 +104,6 @@ class IDEView extends React.Component { 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)); } @@ -513,7 +489,8 @@ IDEView.propTypes = { projectSavedTime: PropTypes.string.isRequired, previousPath: PropTypes.string.isRequired, forceAuthenticationVisible: PropTypes.bool.isRequired, - authenticationError: PropTypes.bool.isRequired + authenticationError: PropTypes.bool.isRequired, + justOpenedProject: PropTypes.bool.isRequired }).isRequired, startSketch: PropTypes.func.isRequired, stopSketch: PropTypes.func.isRequired, diff --git a/client/modules/IDE/reducers/ide.js b/client/modules/IDE/reducers/ide.js index f77ef048..5c01c142 100644 --- a/client/modules/IDE/reducers/ide.js +++ b/client/modules/IDE/reducers/ide.js @@ -16,7 +16,7 @@ const initialState = { infiniteLoop: false, previewIsRefreshing: false, infiniteLoopMessage: '', - projectJustOpened: false, + justOpenedProject: false, projectSavedTime: '', previousPath: '/', forceAuthenticationVisible: false, diff --git a/client/modules/User/actions.js b/client/modules/User/actions.js index f66f8d36..3eaeb0fd 100644 --- a/client/modules/User/actions.js +++ b/client/modules/User/actions.js @@ -1,7 +1,7 @@ import * as ActionTypes from '../../constants'; import { browserHistory } from 'react-router'; import axios from 'axios'; -import { showAuthenticationError } from '../IDE/actions/ide'; +import { showAuthenticationError, justOpenedProject } from '../IDE/actions/ide'; const ROOT_URL = location.href.indexOf('localhost') > 0 ? 'http://localhost:8000/api' : '/api'; @@ -20,6 +20,7 @@ export function signUpUser(previousPath, formValues) { dispatch({ type: ActionTypes.AUTH_USER, user: response.data }); + dispatch(justOpenedProject()); browserHistory.push(previousPath); }) .catch(response => dispatch(authError(response.data.error))); @@ -55,6 +56,7 @@ export function validateAndLoginUser(previousPath, formProps, dispatch) { type: ActionTypes.SET_PREFERENCES, preferences: response.data.preferences }); + dispatch(justOpenedProject()); browserHistory.push(previousPath); resolve(); })