🚧 update saveProject action redirection

This commit is contained in:
ghalestrilo 2020-08-17 14:53:22 -03:00
parent 074334e14a
commit 6941e06eb3
2 changed files with 15 additions and 12 deletions

View file

@ -126,7 +126,7 @@ function getSynchedProject(currentState, responseProject) {
};
}
export function saveProject(selectedFile = null, autosave = false) {
export function saveProject(selectedFile = null, autosave = false, mobile = false) {
return (dispatch, getState) => {
const state = getState();
if (state.project.isSaving) {
@ -185,16 +185,15 @@ export function saveProject(selectedFile = null, autosave = false) {
.then((response) => {
dispatch(endSavingProject());
const { hasChanges, synchedProject } = getSynchedProject(getState(), response.data);
dispatch(setNewProject(synchedProject));
dispatch(setUnsavedChanges(false));
browserHistory.push(`${mobile ? '/mobile' : ''}/${response.data.user.username}/sketches/${response.data.id}`);
if (hasChanges) {
dispatch(setNewProject(synchedProject));
dispatch(setUnsavedChanges(false));
browserHistory.push(`/${response.data.user.username}/sketches/${response.data.id}`);
dispatch(setUnsavedChanges(true));
} else {
dispatch(setNewProject(synchedProject));
dispatch(setUnsavedChanges(false));
browserHistory.push(`/${response.data.user.username}/sketches/${response.data.id}`);
}
dispatch(projectSaveSuccess());
if (!autosave) {
if (state.preferences.autosave) {
@ -222,9 +221,9 @@ export function saveProject(selectedFile = null, autosave = false) {
};
}
export function autosaveProject() {
export function autosaveProject(mobile = false) {
return (dispatch, getState) => {
saveProject(null, true)(dispatch, getState);
saveProject(null, true, mobile)(dispatch, getState);
};
}

View file

@ -116,7 +116,7 @@ const handleGlobalKeydown = (props, cmController) => (e) => {
// 83 === s
e.preventDefault();
e.stopPropagation();
if (canSaveProject(props)) saveProject(cmController.getContent());
if (canSaveProject(project, user)) saveProject(cmController.getContent(), false, true);
else if (user.authenticated) cloneProject();
else showErrorModal('forceAuthentication');
@ -145,6 +145,10 @@ const autosave = (autosaveInterval, setAutosaveInterval) => (props, prevProps) =
const { selectedFile: oldFile } = prevProps;
const doAutosave = () => autosaveProject(true);
console.log(isUserOwner(props), project);
if (isUserOwner(props) && project.id) {
if (preferences.autosave && ide.unsavedChanges && !ide.justOpenedProject) {
if (file.name === oldFile.name && file.content !== oldFile.content) {
@ -152,7 +156,7 @@ const autosave = (autosaveInterval, setAutosaveInterval) => (props, prevProps) =
clearTimeout(autosaveInterval);
}
console.log('will save project in 20 seconds');
setAutosaveInterval(setTimeout(autosaveProject, 20000));
setAutosaveInterval(setTimeout(doAutosave, 20000));
}
} else if (autosaveInterval && !preferences.autosave) {
clearTimeout(autosaveInterval);