Skip to content

Commit f274edd

Browse files
committed
removed unused refs
1 parent 0a2c755 commit f274edd

File tree

1 file changed

+35
-47
lines changed

1 file changed

+35
-47
lines changed

client/modules/IDE/pages/IDEView.jsx

Lines changed: 35 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -101,13 +101,10 @@ const IDEView = (props) => {
101101
let overlay = null;
102102

103103
const autosaveIntervalRef = useRef(null);
104-
const prevPropsRef = useRef({
105-
selectedFileName: selectedFile.name,
106-
selectedFileContent: selectedFile.content,
107-
location: props.location,
108-
sidebarIsExpanded: ide.sidebarSize,
109-
project_id: props.params.project_id
110-
});
104+
105+
const prevFileNameRef = useRef(selectedFile.name);
106+
const prevFileContentRef = useRef(selectedFile.content);
107+
const locationRef = useRef(props.location);
111108

112109
const syncFileContent = () => {
113110
const file = cmRef.current.getContent();
@@ -128,61 +125,50 @@ const IDEView = (props) => {
128125

129126
// for setting previous location
130127
useEffect(() => {
131-
if (props.location !== prevPropsRef.current.location) {
132-
dispatch(setPreviousPath(prevPropsRef.current.location.pathname));
133-
}
134-
135-
prevPropsRef.current.location = props.location;
128+
dispatch(setPreviousPath(locationRef.current.pathname));
129+
console.log(locationRef.current.pathname);
136130
}, [props.location]);
137131

138-
// for the sidebar size behaviour
132+
// for the sidebar size behavior
139133
useEffect(() => {
140-
if (!ide.sidebarIsExpanded) {
141-
prevPropsRef.current.sidebarSize = sidebarSize;
142-
setSidebarSize(20);
143-
}
144134
if (ide.sidebarIsExpanded) {
145-
setSidebarSize(
146-
prevPropsRef.current.sidebarSize > 160
147-
? prevPropsRef.current.sidebarSize
148-
: 160
149-
);
135+
setSidebarSize((prev) => (prev < 160 ? 160 : sidebarSize));
150136
}
151137
}, [ide.sidebarIsExpanded]);
152138

153139
// For autosave
154140
useEffect(() => {
155-
if (
156-
isUserOwner &&
157-
project.id &&
158-
preferences.autosave &&
159-
ide.unsavedChanges &&
160-
!ide.justOpenedProject
161-
) {
141+
let autosaveTimeout;
142+
143+
const handleAutosave = () => {
162144
if (
163-
selectedFile.name === prevPropsRef.current.selectedFileName &&
164-
selectedFile.content !== prevPropsRef.current.selectedFileContent
145+
isUserOwner &&
146+
project.id &&
147+
preferences.autosave &&
148+
ide.unsavedChanges &&
149+
!ide.justOpenedProject &&
150+
selectedFile.name === prevFileNameRef.current &&
151+
selectedFile.content !== prevFileContentRef.current
165152
) {
166-
if (autosaveIntervalRef.current) {
167-
clearTimeout(autosaveIntervalRef.current);
168-
}
169-
autosaveIntervalRef.current = setTimeout(
170-
dispatch(autosaveProject()),
171-
20000
172-
);
153+
dispatch(autosaveProject());
173154
}
174-
} else if (autosaveIntervalRef.current && !preferences.autosave) {
155+
};
156+
157+
if (autosaveIntervalRef.current) {
175158
clearTimeout(autosaveIntervalRef.current);
176-
autosaveIntervalRef.current = null;
177159
}
178160

179-
prevPropsRef.current.selectedFileName = selectedFile.name;
180-
prevPropsRef.current.selectedFileContent = selectedFile.content;
161+
if (preferences.autosave) {
162+
autosaveTimeout = setTimeout(handleAutosave, 20000);
163+
}
164+
165+
autosaveIntervalRef.current = autosaveTimeout;
166+
prevFileNameRef.current = selectedFile.name;
167+
prevFileContentRef.current = selectedFile.content;
181168

182169
return () => {
183-
if (autosaveIntervalRef.current) {
184-
clearTimeout(autosaveIntervalRef.current);
185-
autosaveIntervalRef.current = null;
170+
if (autosaveTimeout) {
171+
clearTimeout(autosaveTimeout);
186172
}
187173
};
188174
}, [
@@ -192,7 +178,9 @@ const IDEView = (props) => {
192178
ide.unsavedChanges,
193179
ide.justOpenedProject,
194180
selectedFile.name,
195-
selectedFile.content
181+
selectedFile.content,
182+
dispatch,
183+
autosaveProject
196184
]);
197185

198186
return (
@@ -212,7 +200,7 @@ const IDEView = (props) => {
212200
<main className="editor-preview-container">
213201
<SplitPane
214202
split="vertical"
215-
size={sidebarSize}
203+
size={ide.sidebarIsExpanded ? sidebarSize : 20}
216204
onChange={(size) => {
217205
setSidebarSize(size);
218206
}}

0 commit comments

Comments
 (0)