1
1
import { useCallback , useState } from 'react' ;
2
2
import PropTypes from 'prop-types' ;
3
3
import { useSelector } from 'react-redux' ;
4
- import { useNavigate } from 'react-router-dom ' ;
4
+ import { getConfig } from '@edx/frontend-platform ' ;
5
5
import { useIntl , FormattedMessage } from '@edx/frontend-platform/i18n' ;
6
6
import {
7
7
ActionRow , Button , StandardModal , useToggle ,
8
8
} from '@openedx/paragon' ;
9
9
10
10
import { getCourseSectionVertical } from '../data/selectors' ;
11
+ import { getWaffleFlags } from '../../data/selectors' ;
11
12
import { COMPONENT_TYPES } from '../../generic/block-type-utils/constants' ;
12
13
import ComponentModalView from './add-component-modals/ComponentModalView' ;
13
14
import AddComponentButton from './add-component-btn' ;
@@ -16,6 +17,8 @@ import { ComponentPicker } from '../../library-authoring/component-picker';
16
17
import { messageTypes } from '../constants' ;
17
18
import { useIframe } from '../../generic/hooks/context/hooks' ;
18
19
import { useEventListener } from '../../generic/hooks' ;
20
+ import VideoSelectorPage from '../../editors/VideoSelectorPage' ;
21
+ import EditorPage from '../../editors/EditorPage' ;
19
22
20
23
const AddComponent = ( {
21
24
parentLocator,
@@ -24,18 +27,24 @@ const AddComponent = ({
24
27
addComponentTemplateData,
25
28
handleCreateNewCourseXBlock,
26
29
} ) => {
27
- const navigate = useNavigate ( ) ;
28
30
const intl = useIntl ( ) ;
29
31
const [ isOpenAdvanced , openAdvanced , closeAdvanced ] = useToggle ( false ) ;
30
32
const [ isOpenHtml , openHtml , closeHtml ] = useToggle ( false ) ;
31
33
const [ isOpenOpenAssessment , openOpenAssessment , closeOpenAssessment ] = useToggle ( false ) ;
32
34
const { componentTemplates = { } } = useSelector ( getCourseSectionVertical ) ;
33
35
const blockId = addComponentTemplateData . parentLocator || parentLocator ;
34
36
const [ isAddLibraryContentModalOpen , showAddLibraryContentModal , closeAddLibraryContentModal ] = useToggle ( ) ;
37
+ const [ isVideoSelectorModalOpen , showVideoSelectorModal , closeVideoSelectorModal ] = useToggle ( ) ;
38
+ const [ isXBlockEditorModalOpen , showXBlockEditorModal , closeXBlockEditorModal ] = useToggle ( ) ;
39
+
40
+ const [ blockType , setBlockType ] = useState ( null ) ;
41
+ const [ courseId , setCourseId ] = useState ( null ) ;
42
+ const [ newBlockId , setNewBlockId ] = useState ( null ) ;
35
43
const [ isSelectLibraryContentModalOpen , showSelectLibraryContentModal , closeSelectLibraryContentModal ] = useToggle ( ) ;
36
44
const [ selectedComponents , setSelectedComponents ] = useState ( [ ] ) ;
37
45
const [ usageId , setUsageId ] = useState ( null ) ;
38
46
const { sendMessageToIframe } = useIframe ( ) ;
47
+ const { useVideoGalleryFlow } = useSelector ( getWaffleFlags ) ;
39
48
40
49
const receiveMessage = useCallback ( ( { data : { type, payload } } ) => {
41
50
if ( type === messageTypes . showMultipleComponentPicker ) {
@@ -54,6 +63,12 @@ const AddComponent = ({
54
63
closeSelectLibraryContentModal ( ) ;
55
64
} , [ selectedComponents ] ) ;
56
65
66
+ const onXBlockSave = useCallback ( /* istanbul ignore next */ ( ) => {
67
+ closeXBlockEditorModal ( ) ;
68
+ closeVideoSelectorModal ( ) ;
69
+ sendMessageToIframe ( messageTypes . refreshXBlock , null ) ;
70
+ } , [ closeXBlockEditorModal , closeVideoSelectorModal , sendMessageToIframe ] ) ;
71
+
57
72
const handleLibraryV2Selection = useCallback ( ( selection ) => {
58
73
handleCreateNewCourseXBlock ( {
59
74
type : COMPONENT_TYPES . libraryV2 ,
@@ -71,12 +86,28 @@ const AddComponent = ({
71
86
handleCreateNewCourseXBlock ( { type, parentLocator : blockId } ) ;
72
87
break ;
73
88
case COMPONENT_TYPES . problem :
74
- case COMPONENT_TYPES . video :
75
89
handleCreateNewCourseXBlock ( { type, parentLocator : blockId } , ( { courseKey, locator } ) => {
76
- localStorage . setItem ( 'createXBlockLastYPosition' , window . scrollY ) ;
77
- navigate ( `/course/${ courseKey } /editor/${ type } /${ locator } ` ) ;
90
+ setCourseId ( courseKey ) ;
91
+ setBlockType ( type ) ;
92
+ setNewBlockId ( locator ) ;
93
+ showXBlockEditorModal ( ) ;
78
94
} ) ;
79
95
break ;
96
+ case COMPONENT_TYPES . video :
97
+ handleCreateNewCourseXBlock (
98
+ { type, parentLocator : blockId } ,
99
+ /* istanbul ignore next */ ( { courseKey, locator } ) => {
100
+ setCourseId ( courseKey ) ;
101
+ setBlockType ( type ) ;
102
+ setNewBlockId ( locator ) ;
103
+ if ( useVideoGalleryFlow ) {
104
+ showVideoSelectorModal ( ) ;
105
+ } else {
106
+ showXBlockEditorModal ( ) ;
107
+ }
108
+ } ,
109
+ ) ;
110
+ break ;
80
111
// TODO: The library functional will be a bit different of current legacy (CMS)
81
112
// behaviour and this ticket is on hold (blocked by other development team).
82
113
case COMPONENT_TYPES . library :
@@ -99,9 +130,11 @@ const AddComponent = ({
99
130
type,
100
131
boilerplate : moduleName ,
101
132
parentLocator : blockId ,
102
- } , ( { courseKey, locator } ) => {
103
- localStorage . setItem ( 'createXBlockLastYPosition' , window . scrollY ) ;
104
- navigate ( `/course/${ courseKey } /editor/html/${ locator } ` ) ;
133
+ } , /* istanbul ignore next */ ( { courseKey, locator } ) => {
134
+ setCourseId ( courseKey ) ;
135
+ setBlockType ( type ) ;
136
+ setNewBlockId ( locator ) ;
137
+ showXBlockEditorModal ( ) ;
105
138
} ) ;
106
139
break ;
107
140
default :
@@ -201,6 +234,43 @@ const AddComponent = ({
201
234
onChangeComponentSelection = { setSelectedComponents }
202
235
/>
203
236
</ StandardModal >
237
+ < StandardModal
238
+ title = { intl . formatMessage ( messages . videoPickerModalTitle ) }
239
+ isOpen = { isVideoSelectorModalOpen }
240
+ onClose = { closeVideoSelectorModal }
241
+ isOverflowVisible = { false }
242
+ size = "xl"
243
+ >
244
+ < div className = "selector-page" >
245
+ < VideoSelectorPage
246
+ blockId = { newBlockId }
247
+ courseId = { courseId }
248
+ studioEndpointUrl = { getConfig ( ) . STUDIO_BASE_URL }
249
+ lmsEndpointUrl = { getConfig ( ) . LMS_BASE_URL }
250
+ onCancel = { closeVideoSelectorModal }
251
+ returnFunction = { /* istanbul ignore next */ ( ) => onXBlockSave }
252
+ />
253
+ </ div >
254
+ </ StandardModal >
255
+ < StandardModal
256
+ title = { intl . formatMessage ( messages . blockEditorModalTitle ) }
257
+ isOpen = { isXBlockEditorModalOpen }
258
+ onClose = { closeXBlockEditorModal }
259
+ isOverflowVisible = { false }
260
+ size = "xl"
261
+ >
262
+ < div className = "editor-page" >
263
+ < EditorPage
264
+ courseId = { courseId }
265
+ blockType = { blockType }
266
+ blockId = { newBlockId }
267
+ studioEndpointUrl = { getConfig ( ) . STUDIO_BASE_URL }
268
+ lmsEndpointUrl = { getConfig ( ) . LMS_BASE_URL }
269
+ onClose = { closeXBlockEditorModal }
270
+ returnFunction = { /* istanbul ignore next */ ( ) => onXBlockSave }
271
+ />
272
+ </ div >
273
+ </ StandardModal >
204
274
</ div >
205
275
) ;
206
276
}
0 commit comments