1
- import PropTypes from 'prop-types' ;
2
1
import React , { useEffect , useRef , useState } from 'react' ;
3
- import { useLocation , Prompt } from 'react-router-dom' ;
2
+ import { useLocation , Prompt , useParams } from 'react-router-dom' ;
4
3
import { useDispatch , useSelector } from 'react-redux' ;
5
4
import { useTranslation } from 'react-i18next' ;
6
5
import { Helmet } from 'react-helmet' ;
@@ -69,14 +68,16 @@ function WarnIfUnsavedChanges() {
69
68
70
69
export const CmControllerContext = React . createContext ( { } ) ;
71
70
72
- const IDEView = ( props ) => {
71
+ const IDEView = ( ) => {
73
72
const ide = useSelector ( ( state ) => state . ide ) ;
74
73
const preferences = useSelector ( ( state ) => state . preferences ) ;
75
74
const project = useSelector ( ( state ) => state . project ) ;
76
75
const isUserOwner = useSelector ( getIsUserOwner ) ;
77
76
const dispatch = useDispatch ( ) ;
78
77
const { t } = useTranslation ( ) ;
79
78
79
+ const params = useParams ( ) ;
80
+
80
81
const [ consoleSize , setConsoleSize ] = useState ( 150 ) ;
81
82
const [ sidebarSize , setSidebarSize ] = useState ( 160 ) ;
82
83
const [ isOverlayVisible , setIsOverlayVisible ] = useState ( true ) ;
@@ -94,13 +95,14 @@ const IDEView = (props) => {
94
95
dispatch ( clearPersistedState ( ) ) ;
95
96
96
97
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 ) ) ;
102
104
}
103
- } , [ ] ) ;
105
+ } , [ dispatch , params , project . id ] ) ;
104
106
105
107
const autosaveAllowed = isUserOwner && project . id && preferences . autosave ;
106
108
const shouldAutosave = autosaveAllowed && ide . unsavedChanges ;
@@ -241,12 +243,4 @@ const IDEView = (props) => {
241
243
) ;
242
244
} ;
243
245
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
-
252
246
export default IDEView ;
0 commit comments