Skip to content

Commit 2a2fa99

Browse files
auto save logic
Co-authored-by: Linda Paiste <lindapaiste@gmail.com>
1 parent 8d36f7e commit 2a2fa99

File tree

1 file changed

+7
-23
lines changed

1 file changed

+7
-23
lines changed

client/modules/IDE/pages/IDEView.jsx

Lines changed: 7 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -109,27 +109,20 @@ const IDEView = (props) => {
109109
}
110110
}, []);
111111

112-
// For autosave
112+
const autosaveAllowed = isUserOwner && project.id && preferences.autosave;
113+
const shouldAutosave = autosaveAllowed && ide.unsavedChanges;
114+
115+
// For autosave - send to API after 5 seconds without changes
113116
useEffect(() => {
114117
const handleAutosave = () => {
115-
if (
116-
isUserOwner &&
117-
project.id &&
118-
preferences.autosave &&
119-
ide.unsavedChanges &&
120-
!ide.justOpenedProject &&
121-
selectedFile.name === prevFileNameRef.current
122-
) {
123-
dispatch(autosaveProject());
124-
console.log('saveee');
125-
}
118+
dispatch(autosaveProject());
126119
};
127120

128121
if (autosaveIntervalRef.current) {
129122
clearTimeout(autosaveIntervalRef.current);
130123
}
131124

132-
if (preferences.autosave) {
125+
if (shouldAutosave) {
133126
autosaveIntervalRef.current = setTimeout(handleAutosave, 10000);
134127
}
135128
prevFileNameRef.current = selectedFile.name;
@@ -139,16 +132,7 @@ const IDEView = (props) => {
139132
clearTimeout(autosaveIntervalRef.current);
140133
}
141134
};
142-
}, [
143-
isUserOwner,
144-
project.id,
145-
preferences.autosave,
146-
ide.unsavedChanges,
147-
ide.justOpenedProject,
148-
selectedFile.name,
149-
dispatch,
150-
autosaveProject
151-
]);
135+
}, [shouldAutosave, dispatch]);
152136

153137
return (
154138
<RootPage>

0 commit comments

Comments
 (0)