1- import PropTypes from 'prop-types' ;
21import React , { useEffect , useRef , useState } from 'react' ;
3- import { useLocation , Prompt } from 'react-router-dom' ;
2+ import { useLocation , Prompt , useParams } from 'react-router-dom' ;
43import { useDispatch , useSelector } from 'react-redux' ;
54import { useTranslation } from 'react-i18next' ;
65import { Helmet } from 'react-helmet' ;
@@ -69,14 +68,16 @@ function WarnIfUnsavedChanges() {
6968
7069export 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-
252246export default IDEView ;
0 commit comments