@@ -110,7 +110,7 @@ const CourseHomeworkEditor: FC<{
110110 const [ title , setTitle ] = useState < string > ( homework . title ! )
111111 const [ tags , setTags ] = useState < string [ ] > ( homework . tags ! )
112112 const [ description , setDescription ] = useState < string > ( homework . description ! )
113- const [ filesControlState , setFilesControlState ] = useState < IEditFilesState > ( {
113+ const [ filesState , setFilesState ] = useState < IEditFilesState > ( {
114114 initialFilesInfo : filesInfo ,
115115 selectedFilesInfo : filesInfo ,
116116 isLoadingInfo : false
@@ -168,8 +168,8 @@ const CourseHomeworkEditor: FC<{
168168 isModified : true ,
169169 }
170170
171- props . onUpdate ( { fileInfos : [ ] , homework : update } )
172- } , [ title , description , tags , metadata , hasErrors ] )
171+ props . onUpdate ( { fileInfos : filesState . selectedFilesInfo , homework : update } )
172+ } , [ title , description , tags , metadata , hasErrors , filesState . selectedFilesInfo ] )
173173
174174 useEffect ( ( ) => {
175175 setHasErrors ( ! title || metadata . hasErrors )
@@ -228,18 +228,18 @@ const CourseHomeworkEditor: FC<{
228228 const updatedHomeworkId = updatedHomework . value ! . id !
229229
230230 // Если какие-то файлы из ранее добавленных больше не выбраны, удаляем их из хранилища
231- const deleteOperations = filesControlState . initialFilesInfo
231+ const deleteOperations = filesState . initialFilesInfo
232232 . filter ( initialFile =>
233233 initialFile . key &&
234- ! filesControlState . selectedFilesInfo . some ( s => s . key === initialFile . key )
234+ ! filesState . selectedFilesInfo . some ( s => s . key === initialFile . key )
235235 )
236236 . map ( initialFile => UpdateFilesUtils . deleteFileWithErrorsHadling ( courseId , initialFile ) ) ;
237237
238238 // Если какие-то файлы из выбранных сейчас не были добавлены раньше, загружаем их в хранилище
239- const uploadOperations = filesControlState . selectedFilesInfo
239+ const uploadOperations = filesState . selectedFilesInfo
240240 . filter ( selectedFile =>
241241 selectedFile . file &&
242- ! filesControlState . initialFilesInfo . some ( i => i . key === selectedFile . key )
242+ ! filesState . initialFilesInfo . some ( i => i . key === selectedFile . key )
243243 )
244244 . map ( selectedFile => UpdateFilesUtils . uploadFileWithErrorsHadling (
245245 selectedFile . file ! ,
@@ -253,12 +253,12 @@ const CourseHomeworkEditor: FC<{
253253 if ( deleteOperations . length === 0 && uploadOperations . length === 0 ) {
254254 if ( isNewHomework ) props . onUpdate ( {
255255 homework : update ,
256- fileInfos : filesControlState . selectedFilesInfo ,
256+ fileInfos : [ ] ,
257257 isDeleted : true
258258 } ) // remove fake homework
259259 props . onUpdate ( {
260260 homework : updatedHomework . value ! ,
261- fileInfos : filesControlState . selectedFilesInfo ,
261+ fileInfos : filesState . selectedFilesInfo ,
262262 isSaved : true
263263 } )
264264 } else {
@@ -280,7 +280,7 @@ const CourseHomeworkEditor: FC<{
280280 } ) // remove fake homework
281281 props . onUpdate ( {
282282 homework : updatedHomework . value ! ,
283- fileInfos : filesControlState . selectedFilesInfo ,
283+ fileInfos : filesState . selectedFilesInfo ,
284284 isSaved : true
285285 } )
286286 }
@@ -335,15 +335,15 @@ const CourseHomeworkEditor: FC<{
335335 < Grid item xs = { 12 } style = { { marginBottom : "15px" } } >
336336 < Grid container direction = "column" >
337337 < FilesUploader
338- initialFilesInfo = { filesControlState . selectedFilesInfo }
339- isLoading = { filesControlState . isLoadingInfo }
338+ initialFilesInfo = { filesState . selectedFilesInfo }
339+ isLoading = { filesState . isLoadingInfo }
340340 onChange = { ( filesInfo ) => {
341- setFilesControlState ( ( prevState ) => ( {
341+ setFilesState ( ( prevState ) => ( {
342342 ...prevState ,
343343 selectedFilesInfo : filesInfo
344- } ) )
344+ } ) ) ;
345345 } }
346- />
346+ homeworkId = { homeworkId } />
347347 < PublicationAndDeadlineDates
348348 hasDeadline = { metadata . hasDeadline }
349349 isDeadlineStrict = { metadata . isDeadlineStrict }
0 commit comments