1
- import { useEffect } from "react" ;
1
+ import { useEffect , useRef } from "react" ;
2
2
import find from "lodash/find" ;
3
3
4
4
// import ModalVideo from "react-modal-video";
@@ -14,6 +14,8 @@ import { type SingleListData } from "../../../types/apiTypes";
14
14
15
15
const VideoModal = ( { listData } : { listData : SingleListData [ ] } ) => {
16
16
const showVideoModal = useModalStore ( ( state ) => state . showVideoModal ) ;
17
+ const ref = useRef < HTMLVideoElement > ( null ) ;
18
+
17
19
const toggleShowVideoModal = useModalStore (
18
20
( state ) => state . toggleShowVideoModal ,
19
21
) ;
@@ -27,6 +29,8 @@ const VideoModal = ({ listData }: { listData: SingleListData[] }) => {
27
29
useEffect ( ( ) => {
28
30
if ( ! showVideoModal ) {
29
31
setSelectedVideoId ( null ) ;
32
+ // if this is not there then video keeps playing even on modal close
33
+ ref ?. current ?. pause ( ) ;
30
34
}
31
35
} , [ setSelectedVideoId , showVideoModal ] ) ;
32
36
@@ -39,14 +43,17 @@ const VideoModal = ({ listData }: { listData: SingleListData[] }) => {
39
43
< Modal
40
44
open = { showVideoModal }
41
45
setOpen = { ( ) => toggleShowVideoModal ( ) }
42
- wrapperClassName = "h-auto w-auto max-h-full max-w-[80%] rounded-2xl outline-none"
46
+ // wrapperClassName="h-auto w-auto max-w-[80%] rounded-2xl outline-none"
47
+ wrapperClassName = "h-[80%] w-[80%] rounded-2xl outline-none"
48
+ // wrapperClassName="relative h-[100vh] w-[100vw] rounded-2xl outline-none"
43
49
>
44
50
{ /* eslint-disable-next-line jsx-a11y/media-has-caption */ }
45
51
< video
46
52
autoPlay
47
- className = "rounded-2xl bg-black"
53
+ className = "h-full w-full rounded-2xl bg-black object-contain "
48
54
controls
49
55
preload = "auto"
56
+ ref = { ref }
50
57
src = { selectedVideoData ?. url }
51
58
/>
52
59
</ Modal >
0 commit comments