#254 test all of the edge cases for autosaving, such as login and logout, changing the autosave preference

This commit is contained in:
Cassie Tarakajian 2017-01-24 13:04:51 -05:00
parent 93130934f2
commit c8253dd923
3 changed files with 10 additions and 31 deletions

View file

@ -47,12 +47,6 @@ class IDEView extends React.Component {
if (id !== this.props.project.id) { if (id !== this.props.project.id) {
this.props.getProject(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; this.consoleSize = this.props.ide.consoleIsExpanded ? 150 : 29;
@ -67,6 +61,7 @@ class IDEView extends React.Component {
window.onbeforeunload = () => this.warnIfUnsavedChanges(); window.onbeforeunload = () => this.warnIfUnsavedChanges();
document.body.className = this.props.preferences.theme; document.body.className = this.props.preferences.theme;
this.autosaveInterval = null;
} }
componentWillReceiveProps(nextProps) { componentWillReceiveProps(nextProps) {
@ -97,9 +92,10 @@ class IDEView extends React.Component {
componentDidUpdate(prevProps) { componentDidUpdate(prevProps) {
if (this.isUserOwner() && this.props.project.id) { 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); 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); clearTimeout(this.autosaveInterval);
this.autosaveInterval = null; this.autosaveInterval = null;
} }
@ -108,26 +104,6 @@ class IDEView extends React.Component {
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));
} }
@ -513,7 +489,8 @@ IDEView.propTypes = {
projectSavedTime: PropTypes.string.isRequired, projectSavedTime: PropTypes.string.isRequired,
previousPath: PropTypes.string.isRequired, previousPath: PropTypes.string.isRequired,
forceAuthenticationVisible: PropTypes.bool.isRequired, forceAuthenticationVisible: PropTypes.bool.isRequired,
authenticationError: PropTypes.bool.isRequired authenticationError: PropTypes.bool.isRequired,
justOpenedProject: PropTypes.bool.isRequired
}).isRequired, }).isRequired,
startSketch: PropTypes.func.isRequired, startSketch: PropTypes.func.isRequired,
stopSketch: PropTypes.func.isRequired, stopSketch: PropTypes.func.isRequired,

View file

@ -16,7 +16,7 @@ const initialState = {
infiniteLoop: false, infiniteLoop: false,
previewIsRefreshing: false, previewIsRefreshing: false,
infiniteLoopMessage: '', infiniteLoopMessage: '',
projectJustOpened: false, justOpenedProject: false,
projectSavedTime: '', projectSavedTime: '',
previousPath: '/', previousPath: '/',
forceAuthenticationVisible: false, forceAuthenticationVisible: false,

View file

@ -1,7 +1,7 @@
import * as ActionTypes from '../../constants'; import * as ActionTypes from '../../constants';
import { browserHistory } from 'react-router'; import { browserHistory } from 'react-router';
import axios from 'axios'; 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'; 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, dispatch({ type: ActionTypes.AUTH_USER,
user: response.data user: response.data
}); });
dispatch(justOpenedProject());
browserHistory.push(previousPath); browserHistory.push(previousPath);
}) })
.catch(response => dispatch(authError(response.data.error))); .catch(response => dispatch(authError(response.data.error)));
@ -55,6 +56,7 @@ export function validateAndLoginUser(previousPath, formProps, dispatch) {
type: ActionTypes.SET_PREFERENCES, type: ActionTypes.SET_PREFERENCES,
preferences: response.data.preferences preferences: response.data.preferences
}); });
dispatch(justOpenedProject());
browserHistory.push(previousPath); browserHistory.push(previousPath);
resolve(); resolve();
}) })