File tree Expand file tree Collapse file tree 1 file changed +7
-23
lines changed Expand file tree Collapse file tree 1 file changed +7
-23
lines changed Original file line number Diff line number Diff line change @@ -109,27 +109,20 @@ const IDEView = (props) => {
109
109
}
110
110
} , [ ] ) ;
111
111
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
113
116
useEffect ( ( ) => {
114
117
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 ( ) ) ;
126
119
} ;
127
120
128
121
if ( autosaveIntervalRef . current ) {
129
122
clearTimeout ( autosaveIntervalRef . current ) ;
130
123
}
131
124
132
- if ( preferences . autosave ) {
125
+ if ( shouldAutosave ) {
133
126
autosaveIntervalRef . current = setTimeout ( handleAutosave , 10000 ) ;
134
127
}
135
128
prevFileNameRef . current = selectedFile . name ;
@@ -139,16 +132,7 @@ const IDEView = (props) => {
139
132
clearTimeout ( autosaveIntervalRef . current ) ;
140
133
}
141
134
} ;
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 ] ) ;
152
136
153
137
return (
154
138
< RootPage >
You can’t perform that action at this time.
0 commit comments