11'use client'
22
33import { useRef , useState } from 'react'
4+ import { Lightbox } from '@sim/emcn'
45import { cn , getAssetUrl } from '@/lib/utils'
5- import { Lightbox } from './lightbox'
66
77interface ActionImageProps {
88 src : string
@@ -17,10 +17,6 @@ interface ActionVideoProps {
1717}
1818
1919export function ActionImage ( { src, alt, enableLightbox = true } : ActionImageProps ) {
20- const [ isLightboxOpen , setIsLightboxOpen ] = useState ( false )
21-
22- const openLightbox = ( ) => setIsLightboxOpen ( true )
23-
2420 const image = (
2521 < img
2622 src = { src }
@@ -32,42 +28,28 @@ export function ActionImage({ src, alt, enableLightbox = true }: ActionImageProp
3228 />
3329 )
3430
31+ if ( ! enableLightbox ) return image
32+
3533 return (
36- < >
37- { enableLightbox ? (
38- < button
39- type = 'button'
40- onClick = { openLightbox }
41- aria-label = { `Open ${ alt } in media viewer` }
42- className = 'group inline-block cursor-pointer rounded p-0 text-left'
43- >
44- { image }
45- </ button >
46- ) : (
47- image
48- ) }
49- { enableLightbox && (
50- < Lightbox
51- isOpen = { isLightboxOpen }
52- onClose = { ( ) => setIsLightboxOpen ( false ) }
53- src = { src }
54- alt = { alt }
55- type = 'image'
56- />
57- ) }
58- </ >
34+ < Lightbox src = { src } alt = { alt } >
35+ < button
36+ type = 'button'
37+ aria-label = { `Open ${ alt } in media viewer` }
38+ className = 'group inline-block cursor-pointer rounded p-0 text-left'
39+ >
40+ { image }
41+ </ button >
42+ </ Lightbox >
5943 )
6044}
6145
6246export function ActionVideo ( { src, alt, enableLightbox = true } : ActionVideoProps ) {
6347 const videoRef = useRef < HTMLVideoElement > ( null )
64- const startTimeRef = useRef ( 0 )
65- const [ isLightboxOpen , setIsLightboxOpen ] = useState ( false )
48+ const [ startTime , setStartTime ] = useState ( 0 )
6649 const resolvedSrc = getAssetUrl ( src )
6750
6851 const openLightbox = ( ) => {
69- startTimeRef . current = videoRef . current ?. currentTime ?? 0
70- setIsLightboxOpen ( true )
52+ setStartTime ( videoRef . current ?. currentTime ?? 0 )
7153 }
7254
7355 const video = (
@@ -85,30 +67,18 @@ export function ActionVideo({ src, alt, enableLightbox = true }: ActionVideoProp
8567 />
8668 )
8769
70+ if ( ! enableLightbox ) return video
71+
8872 return (
89- < >
90- { enableLightbox ? (
91- < button
92- type = 'button'
93- onClick = { openLightbox }
94- aria-label = { `Open ${ alt } in media viewer` }
95- className = 'group inline-block cursor-pointer rounded p-0 text-left'
96- >
97- { video }
98- </ button >
99- ) : (
100- video
101- ) }
102- { enableLightbox && (
103- < Lightbox
104- isOpen = { isLightboxOpen }
105- onClose = { ( ) => setIsLightboxOpen ( false ) }
106- src = { src }
107- alt = { alt }
108- type = 'video'
109- startTime = { startTimeRef . current }
110- />
111- ) }
112- </ >
73+ < Lightbox src = { resolvedSrc } alt = { alt } type = 'video' startTime = { startTime } >
74+ < button
75+ type = 'button'
76+ onClick = { openLightbox }
77+ aria-label = { `Open ${ alt } in media viewer` }
78+ className = 'group inline-block cursor-pointer rounded p-0 text-left'
79+ >
80+ { video }
81+ </ button >
82+ </ Lightbox >
11383 )
11484}
0 commit comments