Skip to content

Commit 640a293

Browse files
authored
Merge pull request #4 from lindapaiste/dewanshmobile/ide
cleanup IDEView
2 parents a3ad31a + 62daa3c commit 640a293

File tree

1 file changed

+11
-17
lines changed

1 file changed

+11
-17
lines changed

client/modules/IDE/pages/IDEView.jsx

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
import PropTypes from 'prop-types';
21
import React, { useEffect, useRef, useState } from 'react';
3-
import { useLocation, Prompt } from 'react-router-dom';
2+
import { useLocation, Prompt, useParams } from 'react-router-dom';
43
import { useDispatch, useSelector } from 'react-redux';
54
import { useTranslation } from 'react-i18next';
65
import { Helmet } from 'react-helmet';
@@ -69,14 +68,16 @@ function WarnIfUnsavedChanges() {
6968

7069
export const CmControllerContext = React.createContext({});
7170

72-
const IDEView = (props) => {
71+
const IDEView = () => {
7372
const ide = useSelector((state) => state.ide);
7473
const preferences = useSelector((state) => state.preferences);
7574
const project = useSelector((state) => state.project);
7675
const isUserOwner = useSelector(getIsUserOwner);
7776
const dispatch = useDispatch();
7877
const { t } = useTranslation();
7978

79+
const params = useParams();
80+
8081
const [consoleSize, setConsoleSize] = useState(150);
8182
const [sidebarSize, setSidebarSize] = useState(160);
8283
const [isOverlayVisible, setIsOverlayVisible] = useState(true);
@@ -94,13 +95,14 @@ const IDEView = (props) => {
9495
dispatch(clearPersistedState());
9596

9697
dispatch(stopSketch());
97-
if (props.params.project_id) {
98-
const { project_id: id, username } = props.params;
99-
if (id !== project.id) {
100-
dispatch(getProject(id, username));
101-
}
98+
}, [dispatch]);
99+
100+
useEffect(() => {
101+
const { project_id: id, username } = params;
102+
if (id && project.id !== id) {
103+
dispatch(getProject(id, username));
102104
}
103-
}, []);
105+
}, [dispatch, params, project.id]);
104106

105107
const autosaveAllowed = isUserOwner && project.id && preferences.autosave;
106108
const shouldAutosave = autosaveAllowed && ide.unsavedChanges;
@@ -241,12 +243,4 @@ const IDEView = (props) => {
241243
);
242244
};
243245

244-
IDEView.propTypes = {
245-
params: PropTypes.shape({
246-
project_id: PropTypes.string,
247-
username: PropTypes.string,
248-
reset_password_token: PropTypes.string
249-
}).isRequired
250-
};
251-
252246
export default IDEView;

0 commit comments

Comments
 (0)