From f2e8d4086158bc6550ff7b1e45da1c5be431851b Mon Sep 17 00:00:00 2001 From: ghalestrilo Date: Wed, 5 Aug 2020 15:27:22 -0300 Subject: [PATCH] :construction: write hooks for mounting MobileIDEView component --- client/modules/IDE/pages/MobileIDEView.jsx | 28 +++++++++++++++------- 1 file changed, 19 insertions(+), 9 deletions(-) diff --git a/client/modules/IDE/pages/MobileIDEView.jsx b/client/modules/IDE/pages/MobileIDEView.jsx index 3504ff9f..c198ac0c 100644 --- a/client/modules/IDE/pages/MobileIDEView.jsx +++ b/client/modules/IDE/pages/MobileIDEView.jsx @@ -64,10 +64,10 @@ const getNatOptions = (username = undefined) => const MobileIDEView = (props) => { const { preferences, ide, editorAccessibility, project, updateLintMessage, clearLintMessage, - selectedFile, updateFileContent, files, user, + selectedFile, updateFileContent, files, user, params, closeEditorOptions, showEditorOptions, startRefreshSketch, stopSketch, expandSidebar, collapseSidebar, clearConsole, console, - showRuntimeErrorWarning, hideRuntimeErrorWarning, startSketch + showRuntimeErrorWarning, hideRuntimeErrorWarning, startSketch, getProject, clearPersistedState } = props; const [tmController, setTmController] = useState(null); // eslint-disable-line @@ -79,16 +79,22 @@ const MobileIDEView = (props) => { align="right" />); + // Force state reset + useEffect(clearPersistedState, []); + useEffect(stopSketch, []); + useEffect(() => getProject(params.project_id), []); + // Load Project + const [currentProjectID, setCurrentProjectID] = useState(null); useEffect(() => { - // const { project_id } = params; - // const oldproject_id = ''; + if (params.project_id && !currentProjectID) { + if (params.project_id !== project.id) { + getProject(params.project_id); + } + } + setCurrentProjectID(params.project_id); + }, [params, project]); - // if (nextProps.params.project_id && !oldproject_id) - // if (nextProps.params.project_id !== nextProps.project.id) - - // getProject(nextProps.params.project_id); - }, []); return ( @@ -260,6 +266,10 @@ MobileIDEView.propTypes = { id: PropTypes.string, username: PropTypes.string, }).isRequired, + + getProject: PropTypes.func.isRequired, + clearPersistedState: PropTypes.func.isRequired, + params: PropTypes.shape({ project_id: PropTypes.string }).isRequired, }; function mapStateToProps(state) {