1- import React , { useState , useRef } from 'react' ;
1+ import React , { useState , useRef , useEffect } from 'react' ;
22import { apiService } from '../../services/api' ;
33import { KeywordTagsInput } from './KeywordTagsInput' ;
44
@@ -317,9 +317,13 @@ export const CreateModelModal: React.FC<CreateModelModalProps> = ({
317317 ecore : { progress : 0 , isUploading : false } ,
318318 genmodel : { progress : 0 , isUploading : false }
319319 } ) ;
320+ const [ submitProgress , setSubmitProgress ] = useState ( { progress : 0 , isSubmitting : false } ) ;
320321
321322 const ecoreFileInputRef = useRef < HTMLInputElement > ( null ) ;
322323 const genmodelFileInputRef = useRef < HTMLInputElement > ( null ) ;
324+ const ecoreProgressIntervalRef = useRef < number | null > ( null ) ;
325+ const genmodelProgressIntervalRef = useRef < number | null > ( null ) ;
326+ const submitProgressIntervalRef = useRef < number | null > ( null ) ;
323327
324328 const canSave = uploadedFileIds . ecoreFileId > 0 && uploadedFileIds . genModelFileId > 0 && formData . name . trim ( ) ;
325329
@@ -339,7 +343,10 @@ export const CreateModelModal: React.FC<CreateModelModalProps> = ({
339343 console . log ( 'Uploading .ecore file:' , file . name , 'Size:' , file . size ) ;
340344
341345 // Simulate progress updates
342- const progressInterval = setInterval ( ( ) => {
346+ if ( ecoreProgressIntervalRef . current ) {
347+ clearInterval ( ecoreProgressIntervalRef . current ) ;
348+ }
349+ ecoreProgressIntervalRef . current = window . setInterval ( ( ) => {
343350 setUploadProgress ( prev => ( {
344351 ...prev ,
345352 ecore : {
@@ -352,7 +359,10 @@ export const CreateModelModal: React.FC<CreateModelModalProps> = ({
352359 const response = await apiService . uploadFile ( file , 'ECORE' ) ;
353360 console . log ( 'Upload response:' , response ) ;
354361
355- clearInterval ( progressInterval ) ;
362+ if ( ecoreProgressIntervalRef . current ) {
363+ clearInterval ( ecoreProgressIntervalRef . current ) ;
364+ ecoreProgressIntervalRef . current = null ;
365+ }
356366
357367 // Complete the progress
358368 setUploadProgress ( prev => ( { ...prev , ecore : { progress : 100 , isUploading : false } } ) ) ;
@@ -379,6 +389,10 @@ export const CreateModelModal: React.FC<CreateModelModalProps> = ({
379389 console . error ( 'Upload error:' , err ) ;
380390 setError ( `${ err instanceof Error ? err . message : 'Unknown error' } ` ) ;
381391 setUploadProgress ( prev => ( { ...prev , ecore : { progress : 0 , isUploading : false } } ) ) ;
392+ if ( ecoreProgressIntervalRef . current ) {
393+ clearInterval ( ecoreProgressIntervalRef . current ) ;
394+ ecoreProgressIntervalRef . current = null ;
395+ }
382396 }
383397
384398 event . target . value = '' ;
@@ -400,7 +414,10 @@ export const CreateModelModal: React.FC<CreateModelModalProps> = ({
400414 console . log ( 'Uploading .genmodel file:' , file . name , 'Size:' , file . size ) ;
401415
402416 // Simulate progress updates
403- const progressInterval = setInterval ( ( ) => {
417+ if ( genmodelProgressIntervalRef . current ) {
418+ clearInterval ( genmodelProgressIntervalRef . current ) ;
419+ }
420+ genmodelProgressIntervalRef . current = window . setInterval ( ( ) => {
404421 setUploadProgress ( prev => ( {
405422 ...prev ,
406423 genmodel : {
@@ -413,7 +430,10 @@ export const CreateModelModal: React.FC<CreateModelModalProps> = ({
413430 const response = await apiService . uploadFile ( file , 'GEN_MODEL' ) ;
414431 console . log ( 'Upload response:' , response ) ;
415432
416- clearInterval ( progressInterval ) ;
433+ if ( genmodelProgressIntervalRef . current ) {
434+ clearInterval ( genmodelProgressIntervalRef . current ) ;
435+ genmodelProgressIntervalRef . current = null ;
436+ }
417437
418438 // Complete the progress
419439 setUploadProgress ( prev => ( { ...prev , genmodel : { progress : 100 , isUploading : false } } ) ) ;
@@ -440,6 +460,10 @@ export const CreateModelModal: React.FC<CreateModelModalProps> = ({
440460 console . error ( 'Upload error:' , err ) ;
441461 setError ( `Error uploading ${ file . name } : ${ err instanceof Error ? err . message : 'Unknown error' } ` ) ;
442462 setUploadProgress ( prev => ( { ...prev , genmodel : { progress : 0 , isUploading : false } } ) ) ;
463+ if ( genmodelProgressIntervalRef . current ) {
464+ clearInterval ( genmodelProgressIntervalRef . current ) ;
465+ genmodelProgressIntervalRef . current = null ;
466+ }
443467 }
444468
445469 event . target . value = '' ;
@@ -459,6 +483,18 @@ export const CreateModelModal: React.FC<CreateModelModalProps> = ({
459483
460484 setIsLoading ( true ) ;
461485 setError ( '' ) ;
486+ // Start submit progress animation
487+ if ( submitProgressIntervalRef . current ) {
488+ clearInterval ( submitProgressIntervalRef . current ) ;
489+ submitProgressIntervalRef . current = null ;
490+ }
491+ setSubmitProgress ( { progress : 0 , isSubmitting : true } ) ;
492+ submitProgressIntervalRef . current = window . setInterval ( ( ) => {
493+ setSubmitProgress ( prev => ( {
494+ progress : Math . min ( prev . progress + Math . random ( ) * 20 , 90 ) ,
495+ isSubmitting : true ,
496+ } ) ) ;
497+ } , 200 ) ;
462498
463499 try {
464500 const requestData : CreateModelRequest = {
@@ -475,20 +511,49 @@ export const CreateModelModal: React.FC<CreateModelModalProps> = ({
475511 const response = await apiService . createMetaModel ( requestData ) ;
476512 console . log ( 'Meta Model creation response:' , response ) ;
477513
514+ // Finish submit progress
515+ if ( submitProgressIntervalRef . current ) {
516+ clearInterval ( submitProgressIntervalRef . current ) ;
517+ submitProgressIntervalRef . current = null ;
518+ }
519+ setSubmitProgress ( { progress : 100 , isSubmitting : false } ) ;
520+
478521 setSuccess ( 'Meta Model created successfully!' ) ;
479522 setTimeout ( ( ) => {
480523 onSuccess ?.( response . data ) ;
481524 handleClose ( ) ;
482525 } , 1500 ) ;
526+ // Reset progress after brief success display if modal remains open
527+ setTimeout ( ( ) => {
528+ setSubmitProgress ( { progress : 0 , isSubmitting : false } ) ;
529+ } , 2000 ) ;
483530 } catch ( err ) {
484531 console . error ( 'Meta Model creation error:' , err ) ;
485532 setError ( `Error creating meta model: ${ err instanceof Error ? err . message : 'Unknown error' } ` ) ;
533+ if ( submitProgressIntervalRef . current ) {
534+ clearInterval ( submitProgressIntervalRef . current ) ;
535+ submitProgressIntervalRef . current = null ;
536+ }
537+ setSubmitProgress ( { progress : 0 , isSubmitting : false } ) ;
486538 } finally {
487539 setIsLoading ( false ) ;
488540 }
489541 } ;
490542
491543 const handleClose = ( ) => {
544+ if ( submitProgressIntervalRef . current ) {
545+ clearInterval ( submitProgressIntervalRef . current ) ;
546+ submitProgressIntervalRef . current = null ;
547+ }
548+ if ( ecoreProgressIntervalRef . current ) {
549+ clearInterval ( ecoreProgressIntervalRef . current ) ;
550+ ecoreProgressIntervalRef . current = null ;
551+ }
552+ if ( genmodelProgressIntervalRef . current ) {
553+ clearInterval ( genmodelProgressIntervalRef . current ) ;
554+ genmodelProgressIntervalRef . current = null ;
555+ }
556+ setSubmitProgress ( { progress : 0 , isSubmitting : false } ) ;
492557 setFormData ( {
493558 name : '' ,
494559 description : '' ,
@@ -510,13 +575,49 @@ export const CreateModelModal: React.FC<CreateModelModalProps> = ({
510575 onClose ( ) ;
511576 } ;
512577
578+ useEffect ( ( ) => {
579+ if ( ! isOpen ) {
580+ if ( submitProgressIntervalRef . current ) {
581+ clearInterval ( submitProgressIntervalRef . current ) ;
582+ submitProgressIntervalRef . current = null ;
583+ }
584+ if ( ecoreProgressIntervalRef . current ) {
585+ clearInterval ( ecoreProgressIntervalRef . current ) ;
586+ ecoreProgressIntervalRef . current = null ;
587+ }
588+ if ( genmodelProgressIntervalRef . current ) {
589+ clearInterval ( genmodelProgressIntervalRef . current ) ;
590+ genmodelProgressIntervalRef . current = null ;
591+ }
592+ setSubmitProgress ( { progress : 0 , isSubmitting : false } ) ;
593+ setUploadProgress ( {
594+ ecore : { progress : 0 , isUploading : false } ,
595+ genmodel : { progress : 0 , isUploading : false }
596+ } ) ;
597+ }
598+ return ( ) => {
599+ if ( submitProgressIntervalRef . current ) {
600+ clearInterval ( submitProgressIntervalRef . current ) ;
601+ submitProgressIntervalRef . current = null ;
602+ }
603+ if ( ecoreProgressIntervalRef . current ) {
604+ clearInterval ( ecoreProgressIntervalRef . current ) ;
605+ ecoreProgressIntervalRef . current = null ;
606+ }
607+ if ( genmodelProgressIntervalRef . current ) {
608+ clearInterval ( genmodelProgressIntervalRef . current ) ;
609+ genmodelProgressIntervalRef . current = null ;
610+ }
611+ } ;
612+ } , [ isOpen ] ) ;
613+
513614 if ( ! isOpen ) return null ;
514615
515616 return (
516617 < div style = { modalOverlayStyle } onClick = { handleClose } >
517618 < div style = { modalStyle } onClick = { ( e ) => e . stopPropagation ( ) } >
518619 < div style = { modalHeaderStyle } >
519- < h2 style = { modalTitleStyle } > Upload New Meta Model</ h2 >
620+ < h2 style = { modalTitleStyle } > Build New Meta Model</ h2 >
520621 < button
521622 style = { closeButtonStyle }
522623 onClick = { handleClose }
@@ -527,6 +628,18 @@ export const CreateModelModal: React.FC<CreateModelModalProps> = ({
527628 </ button >
528629 </ div >
529630
631+ { ( isLoading || submitProgress . isSubmitting ) && (
632+ < >
633+ < div style = { { fontSize : '13px' , color : '#5a6c7d' , textAlign : 'center' } } > Submitting...</ div >
634+ < div style = { progressBarContainerStyle } >
635+ < div style = { { ...progressBarStyle , width : `${ submitProgress . progress } %` } } />
636+ </ div >
637+ < div style = { progressTextStyle } >
638+ { Math . round ( submitProgress . progress ) } %
639+ </ div >
640+ </ >
641+ ) }
642+
530643 { error && < div style = { errorMessageStyle } > { error } </ div > }
531644 { success && < div style = { successMessageStyle } > { success } </ div > }
532645
0 commit comments