@@ -17,7 +17,7 @@ import {
1717 addVideoThumbnail , cancelAllUploads ,
1818 deleteVideoFile ,
1919 fetchVideoDownload , fetchVideos ,
20- getUsagePaths , markVideoUploadsInProgressAsFailed , resetErrors ,
20+ getUsagePaths , markVideoUploadsInProgressAsFailed , newUploadData , resetErrors ,
2121 updateVideoOrder ,
2222} from 'CourseAuthoring/files-and-videos/videos-page/data/thunks' ;
2323import { getFormattedDuration , resampleFile } from 'CourseAuthoring/files-and-videos/videos-page/data/utils' ;
@@ -26,7 +26,7 @@ import messages from 'CourseAuthoring/files-and-videos/videos-page/messages';
2626import TranscriptSettings from 'CourseAuthoring/files-and-videos/videos-page/transcript-settings' ;
2727import UploadModal from 'CourseAuthoring/files-and-videos/videos-page/upload-modal' ;
2828import VideoThumbnail from 'CourseAuthoring/files-and-videos/videos-page/VideoThumbnail' ;
29- import { useModels } from 'CourseAuthoring/generic/model-store' ;
29+ import { useModel , useModels } from 'CourseAuthoring/generic/model-store' ;
3030import PropTypes from 'prop-types' ;
3131import React , { useEffect , useRef } from 'react' ;
3232import { useDispatch , useSelector } from 'react-redux' ;
@@ -39,6 +39,15 @@ const CourseVideosSlot = ({ courseId }) => {
3939 openTranscriptSettings ,
4040 closeTranscriptSettings ,
4141 ] = useToggle ( false ) ;
42+ const [
43+ isUploadTrackerOpen ,
44+ openUploadTracker ,
45+ closeUploadTracker ,
46+ ] = useToggle ( false ) ;
47+
48+ useEffect ( ( ) => {
49+ dispatch ( fetchVideos ( courseId ) ) ;
50+ } , [ courseId ] ) ;
4251 const {
4352 videoIds,
4453 loadingStatus,
@@ -51,6 +60,30 @@ const CourseVideosSlot = ({ courseId }) => {
5160
5261 const uploadingIdsRef = useRef ( { uploadData : { } , uploadCount : 0 } ) ;
5362
63+ useEffect ( ( ) => {
64+ window . onbeforeunload = ( ) => {
65+ dispatch ( markVideoUploadsInProgressAsFailed ( { uploadingIdsRef, courseId } ) ) ;
66+ if ( addVideoStatus === RequestStatus . IN_PROGRESS ) {
67+ return '' ;
68+ }
69+ return undefined ;
70+ } ;
71+ switch ( addVideoStatus ) {
72+ case RequestStatus . IN_PROGRESS :
73+ openUploadTracker ( ) ;
74+ break ;
75+ case RequestStatus . SUCCESSFUL :
76+ setTimeout ( ( ) => closeUploadTracker ( ) , 500 ) ;
77+ break ;
78+ case RequestStatus . FAILED :
79+ setTimeout ( ( ) => closeUploadTracker ( ) , 500 ) ;
80+ break ;
81+ default :
82+ closeUploadTracker ( ) ;
83+ break ;
84+ }
85+ } , [ addVideoStatus ] ) ;
86+
5487 const {
5588 isVideoTranscriptEnabled,
5689 encodingsDownloadUrl,
@@ -66,6 +99,18 @@ const CourseVideosSlot = ({ courseId }) => {
6699 const handleAddFile = ( files ) => {
67100 handleErrorReset ( { errorType : 'add' } ) ;
68101 uploadingIdsRef . current . uploadCount = files . length ;
102+
103+ files . forEach ( ( file , idx ) => {
104+ const name = file ?. name || `Video ${ idx + 1 } ` ;
105+ const progress = 0 ;
106+
107+ newUploadData ( {
108+ status : RequestStatus . PENDING ,
109+ currentData : uploadingIdsRef . current . uploadData ,
110+ originalValue : { name, progress } ,
111+ key : `video_${ idx } ` ,
112+ } ) ;
113+ } ) ;
69114 dispatch ( addVideoFile ( courseId , files , videoIds , uploadingIdsRef ) ) ;
70115 } ;
71116 const handleDeleteFile = ( id ) => dispatch ( deleteVideoFile ( courseId , id ) ) ;
@@ -81,40 +126,8 @@ const CourseVideosSlot = ({ courseId }) => {
81126 videoId,
82127 addVideoThumbnail,
83128 } ) ;
84- const videos = useModels ( 'videos' , videoIds ) ;
85- const [
86- isUploadTrackerOpen ,
87- openUploadTracker ,
88- closeUploadTracker ,
89- ] = useToggle ( false ) ;
90-
91- useEffect ( ( ) => {
92- dispatch ( fetchVideos ( courseId ) ) ;
93- } , [ courseId ] ) ;
94129
95- useEffect ( ( ) => {
96- window . onbeforeunload = ( ) => {
97- dispatch ( markVideoUploadsInProgressAsFailed ( { uploadingIdsRef, courseId } ) ) ;
98- if ( addVideoStatus === RequestStatus . IN_PROGRESS ) {
99- return '' ;
100- }
101- return undefined ;
102- } ;
103- switch ( addVideoStatus ) {
104- case RequestStatus . IN_PROGRESS :
105- openUploadTracker ( ) ;
106- break ;
107- case RequestStatus . SUCCESSFUL :
108- setTimeout ( ( ) => closeUploadTracker ( ) , 500 ) ;
109- break ;
110- case RequestStatus . FAILED :
111- setTimeout ( ( ) => closeUploadTracker ( ) , 500 ) ;
112- break ;
113- default :
114- closeUploadTracker ( ) ;
115- break ;
116- }
117- } , [ addVideoStatus ] ) ;
130+ const videos = useModels ( 'videos' , videoIds ) ;
118131
119132 const data = {
120133 supportedFileFormats,
@@ -202,14 +215,18 @@ const CourseVideosSlot = ({ courseId }) => {
202215 { ...activeColumn } ,
203216 { ...processingStatusColumn } ,
204217 ] ;
218+
205219 return (
206220 < PluginSlot
207- id = "videos_upload_page_table_slot "
221+ id = "org.openedx.frontend.authoring.videos_upload_page_table.v1 "
208222 pluginProps = { {
209223 courseId,
210224 } }
211225 >
212226 < ActionRow >
227+ < div className = "h2" >
228+ { intl . formatMessage ( messages . heading ) }
229+ </ div >
213230 < ActionRow . Spacer />
214231 { isVideoTranscriptEnabled ? (
215232 < Button
0 commit comments