#254 test all of the edge cases for autosaving, such as login and logout, changing the autosave preference
This commit is contained in:
parent
93130934f2
commit
c8253dd923
3 changed files with 10 additions and 31 deletions
|
@ -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,
|
||||
|
|
|
@ -16,7 +16,7 @@ const initialState = {
|
|||
infiniteLoop: false,
|
||||
previewIsRefreshing: false,
|
||||
infiniteLoopMessage: '',
|
||||
projectJustOpened: false,
|
||||
justOpenedProject: false,
|
||||
projectSavedTime: '',
|
||||
previousPath: '/',
|
||||
forceAuthenticationVisible: false,
|
||||
|
|
|
@ -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();
|
||||
})
|
||||
|
|
Loading…
Reference in a new issue