11import { useCallback , useState } from 'react' ;
22import PropTypes from 'prop-types' ;
33import { useSelector } from 'react-redux' ;
4- import { useNavigate } from 'react-router-dom ' ;
4+ import { getConfig } from '@edx/frontend-platform ' ;
55import { useIntl , FormattedMessage } from '@edx/frontend-platform/i18n' ;
66import {
77 ActionRow , Button , StandardModal , useToggle ,
@@ -16,6 +16,7 @@ import { ComponentPicker } from '../../library-authoring/component-picker';
1616import { messageTypes } from '../constants' ;
1717import { useIframe } from '../../generic/hooks/context/hooks' ;
1818import { useEventListener } from '../../generic/hooks' ;
19+ import EditorPage from '../../editors/EditorPage' ;
1920
2021const AddComponent = ( {
2122 parentLocator,
@@ -24,14 +25,18 @@ const AddComponent = ({
2425 addComponentTemplateData,
2526 handleCreateNewCourseXBlock,
2627} ) => {
27- const navigate = useNavigate ( ) ;
2828 const intl = useIntl ( ) ;
2929 const [ isOpenAdvanced , openAdvanced , closeAdvanced ] = useToggle ( false ) ;
3030 const [ isOpenHtml , openHtml , closeHtml ] = useToggle ( false ) ;
3131 const [ isOpenOpenAssessment , openOpenAssessment , closeOpenAssessment ] = useToggle ( false ) ;
3232 const { componentTemplates = { } } = useSelector ( getCourseSectionVertical ) ;
3333 const blockId = addComponentTemplateData . parentLocator || parentLocator ;
3434 const [ isAddLibraryContentModalOpen , showAddLibraryContentModal , closeAddLibraryContentModal ] = useToggle ( ) ;
35+ const [ isXBlockEditorModalOpen , showXBlockEditorModal , closeXBlockEditorModal ] = useToggle ( ) ;
36+
37+ const [ blockType , setBlockType ] = useState ( null ) ;
38+ const [ courseId , setCourseId ] = useState ( null ) ;
39+ const [ newBlockId , setNewBlockId ] = useState ( null ) ;
3540 const [ isSelectLibraryContentModalOpen , showSelectLibraryContentModal , closeSelectLibraryContentModal ] = useToggle ( ) ;
3641 const [ selectedComponents , setSelectedComponents ] = useState ( [ ] ) ;
3742 const [ usageId , setUsageId ] = useState ( null ) ;
@@ -54,6 +59,11 @@ const AddComponent = ({
5459 closeSelectLibraryContentModal ( ) ;
5560 } , [ selectedComponents ] ) ;
5661
62+ const onXBlockSave = useCallback ( /* istanbul ignore next */ ( ) => {
63+ closeXBlockEditorModal ( ) ;
64+ sendMessageToIframe ( messageTypes . refreshXBlock , null ) ;
65+ } , [ closeXBlockEditorModal , sendMessageToIframe ] ) ;
66+
5767 const handleLibraryV2Selection = useCallback ( ( selection ) => {
5868 handleCreateNewCourseXBlock ( {
5969 type : COMPONENT_TYPES . libraryV2 ,
@@ -70,11 +80,13 @@ const AddComponent = ({
7080 case COMPONENT_TYPES . dragAndDrop :
7181 handleCreateNewCourseXBlock ( { type, parentLocator : blockId } ) ;
7282 break ;
73- case COMPONENT_TYPES . problem :
7483 case COMPONENT_TYPES . video :
84+ case COMPONENT_TYPES . problem :
7585 handleCreateNewCourseXBlock ( { type, parentLocator : blockId } , ( { courseKey, locator } ) => {
76- localStorage . setItem ( 'createXBlockLastYPosition' , window . scrollY ) ;
77- navigate ( `/course/${ courseKey } /editor/${ type } /${ locator } ` ) ;
86+ setCourseId ( courseKey ) ;
87+ setBlockType ( type ) ;
88+ setNewBlockId ( locator ) ;
89+ showXBlockEditorModal ( ) ;
7890 } ) ;
7991 break ;
8092 // TODO: The library functional will be a bit different of current legacy (CMS)
@@ -99,9 +111,11 @@ const AddComponent = ({
99111 type,
100112 boilerplate : moduleName ,
101113 parentLocator : blockId ,
102- } , ( { courseKey, locator } ) => {
103- localStorage . setItem ( 'createXBlockLastYPosition' , window . scrollY ) ;
104- navigate ( `/course/${ courseKey } /editor/html/${ locator } ` ) ;
114+ } , /* istanbul ignore next */ ( { courseKey, locator } ) => {
115+ setCourseId ( courseKey ) ;
116+ setBlockType ( type ) ;
117+ setNewBlockId ( locator ) ;
118+ showXBlockEditorModal ( ) ;
105119 } ) ;
106120 break ;
107121 default :
@@ -201,6 +215,25 @@ const AddComponent = ({
201215 onChangeComponentSelection = { setSelectedComponents }
202216 />
203217 </ StandardModal >
218+ < StandardModal
219+ title = { intl . formatMessage ( messages . blockEditorModalTitle ) }
220+ isOpen = { isXBlockEditorModalOpen }
221+ onClose = { closeXBlockEditorModal }
222+ isOverflowVisible = { false }
223+ size = "xl"
224+ >
225+ < div className = "editor-page" >
226+ < EditorPage
227+ courseId = { courseId }
228+ blockType = { blockType }
229+ blockId = { newBlockId }
230+ studioEndpointUrl = { getConfig ( ) . STUDIO_BASE_URL }
231+ lmsEndpointUrl = { getConfig ( ) . LMS_BASE_URL }
232+ onClose = { closeXBlockEditorModal }
233+ returnFunction = { /* istanbul ignore next */ ( ) => onXBlockSave }
234+ />
235+ </ div >
236+ </ StandardModal >
204237 </ div >
205238 ) ;
206239 }
0 commit comments