🚧 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) => { return (dispatch, getState) => {
const state = getState(); const state = getState();
if (state.project.isSaving) { if (state.project.isSaving) {
@ -185,16 +185,15 @@ export function saveProject(selectedFile = null, autosave = false) {
.then((response) => { .then((response) => {
dispatch(endSavingProject()); dispatch(endSavingProject());
const { hasChanges, synchedProject } = getSynchedProject(getState(), response.data); 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) { if (hasChanges) {
dispatch(setNewProject(synchedProject));
dispatch(setUnsavedChanges(false));
browserHistory.push(`/${response.data.user.username}/sketches/${response.data.id}`);
dispatch(setUnsavedChanges(true)); dispatch(setUnsavedChanges(true));
} else {
dispatch(setNewProject(synchedProject));
dispatch(setUnsavedChanges(false));
browserHistory.push(`/${response.data.user.username}/sketches/${response.data.id}`);
} }
dispatch(projectSaveSuccess()); dispatch(projectSaveSuccess());
if (!autosave) { if (!autosave) {
if (state.preferences.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) => { 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 // 83 === s
e.preventDefault(); e.preventDefault();
e.stopPropagation(); e.stopPropagation();
if (canSaveProject(props)) saveProject(cmController.getContent()); if (canSaveProject(project, user)) saveProject(cmController.getContent(), false, true);
else if (user.authenticated) cloneProject(); else if (user.authenticated) cloneProject();
else showErrorModal('forceAuthentication'); else showErrorModal('forceAuthentication');
@ -145,6 +145,10 @@ const autosave = (autosaveInterval, setAutosaveInterval) => (props, prevProps) =
const { selectedFile: oldFile } = prevProps; const { selectedFile: oldFile } = prevProps;
const doAutosave = () => autosaveProject(true);
console.log(isUserOwner(props), project);
if (isUserOwner(props) && project.id) { if (isUserOwner(props) && project.id) {
if (preferences.autosave && ide.unsavedChanges && !ide.justOpenedProject) { if (preferences.autosave && ide.unsavedChanges && !ide.justOpenedProject) {
if (file.name === oldFile.name && file.content !== oldFile.content) { if (file.name === oldFile.name && file.content !== oldFile.content) {
@ -152,7 +156,7 @@ const autosave = (autosaveInterval, setAutosaveInterval) => (props, prevProps) =
clearTimeout(autosaveInterval); clearTimeout(autosaveInterval);
} }
console.log('will save project in 20 seconds'); console.log('will save project in 20 seconds');
setAutosaveInterval(setTimeout(autosaveProject, 20000)); setAutosaveInterval(setTimeout(doAutosave, 20000));
} }
} else if (autosaveInterval && !preferences.autosave) { } else if (autosaveInterval && !preferences.autosave) {
clearTimeout(autosaveInterval); clearTimeout(autosaveInterval);