@@ -52,7 +52,8 @@ function OrgPost(): JSX.Element {
52
52
const [ currentPage , setCurrentPage ] = useState ( 1 ) ;
53
53
const postsPerPage = 6 ;
54
54
const [ displayPosts , setDisplayPosts ] = useState < InterfacePost [ ] > ( [ ] ) ;
55
-
55
+ const [ videoFile , setVideoFile ] = useState < File | null > ( null ) ;
56
+ const [ videoPreview , setVideoPreview ] = useState ( '' ) ;
56
57
const [ file , setFile ] = useState < File | null > ( null ) ;
57
58
const { orgId : currentUrl } = useParams ( ) ;
58
59
const [ showTitle , setShowTitle ] = useState ( true ) ;
@@ -385,6 +386,28 @@ function OrgPost(): JSX.Element {
385
386
}
386
387
}
387
388
} ;
389
+ const handleVideoAddMediaChange = async (
390
+ e : React . ChangeEvent < HTMLInputElement > ,
391
+ ) : Promise < void > => {
392
+ const selectedFile = e . target . files ?. [ 0 ] ;
393
+ if ( selectedFile ) {
394
+ if ( ! selectedFile . type . startsWith ( 'video/' ) ) {
395
+ toast . error ( 'Please select a video file' ) ;
396
+ return ;
397
+ }
398
+ setVideoFile ( selectedFile ) ;
399
+ try {
400
+ const base64 = await convertToBase64 ( selectedFile ) ;
401
+ setVideoPreview ( base64 ) ;
402
+ } catch {
403
+ toast . error ( 'Could not generate video preview' ) ;
404
+ }
405
+ } else {
406
+ setVideoFile ( null ) ;
407
+ setVideoPreview ( '' ) ;
408
+ }
409
+ } ;
410
+
388
411
return (
389
412
< >
390
413
< Row className = { styles . head } >
@@ -515,6 +538,17 @@ function OrgPost(): JSX.Element {
515
538
className = { `mb-3 ${ styles . inputField } ` }
516
539
/>
517
540
541
+ < Form . Control
542
+ id = "videoAddMedia"
543
+ name = "videoAddMedia"
544
+ type = "file"
545
+ accept = "video/*"
546
+ placeholder = { t ( 'addVideo' ) }
547
+ onChange = { handleVideoAddMediaChange }
548
+ data-testid = "addVideoField"
549
+ className = { `mb-3 ${ styles . inputField } ` }
550
+ />
551
+
518
552
{ postformState . addMedia && file && (
519
553
< div className = { styles . previewOrgPost } data-testid = "mediaPreview" >
520
554
{ file . type . startsWith ( 'image' ) ? (
@@ -549,6 +583,34 @@ function OrgPost(): JSX.Element {
549
583
</ button >
550
584
</ div >
551
585
) }
586
+
587
+ { videoPreview && videoFile && (
588
+ < div
589
+ className = { styles . previewOrgPost }
590
+ data-testid = "videoPreviewContainer"
591
+ >
592
+ < video controls data-testid = "videoPreview" >
593
+ < source src = { videoPreview } type = { videoFile . type } /> ({ t ( 'tag' ) }
594
+ )
595
+ </ video >
596
+ < button
597
+ className = { styles . closeButtonOrgPost }
598
+ onClick = { ( ) : void => {
599
+ setVideoPreview ( '' ) ;
600
+ setVideoFile ( null ) ;
601
+ const fileInput = document . getElementById (
602
+ 'videoAddMedia' ,
603
+ ) as HTMLInputElement ;
604
+ if ( fileInput ) {
605
+ fileInput . value = '' ;
606
+ }
607
+ } }
608
+ data-testid = "videoMediaCloseButton"
609
+ >
610
+ < i className = "fa fa-times" > </ i >
611
+ </ button >
612
+ </ div >
613
+ ) }
552
614
< Form . Label htmlFor = "pinpost" className = "mt-3" >
553
615
{ t ( 'pinPost' ) }
554
616
</ Form . Label >
0 commit comments