d25d482dc2
Publish CLI Package / publish-npm (push) Waiting to run
Publish Python SDK / publish-pypi (push) Waiting to run
Publish TypeScript SDK / publish-npm (push) Waiting to run
CI / Migrate Dev DB (push) Has been skipped
CI / Detect Version (push) Has been cancelled
CI / Migrate DB (push) Has been cancelled
CI / Build Dev ECR (./docker/app.Dockerfile, ECR_APP) (push) Has been cancelled
CI / Build Dev ECR (./docker/db.Dockerfile, ECR_MIGRATIONS) (push) Has been cancelled
CI / Build Dev ECR (./docker/pii.Dockerfile, ECR_PII) (push) Has been cancelled
CI / Build Dev ECR (./docker/realtime.Dockerfile, ECR_REALTIME) (push) Has been cancelled
CI / Deploy Trigger.dev (Dev) (push) Has been cancelled
CI / Build AMD64 (./docker/app.Dockerfile, ECR_APP, ghcr.io/simstudioai/simstudio) (push) Has been cancelled
CI / Build AMD64 (./docker/db.Dockerfile, ECR_MIGRATIONS, ghcr.io/simstudioai/migrations) (push) Has been cancelled
CI / Build AMD64 (./docker/pii.Dockerfile, ECR_PII, ghcr.io/simstudioai/pii) (push) Has been cancelled
CI / Build AMD64 (./docker/realtime.Dockerfile, ECR_REALTIME, ghcr.io/simstudioai/realtime) (push) Has been cancelled
CI / Build ARM64 (GHCR Only) (./docker/app.Dockerfile, ghcr.io/simstudioai/simstudio) (push) Has been cancelled
CI / Build ARM64 (GHCR Only) (./docker/db.Dockerfile, ghcr.io/simstudioai/migrations) (push) Has been cancelled
CI / Build ARM64 (GHCR Only) (./docker/pii.Dockerfile, ghcr.io/simstudioai/pii) (push) Has been cancelled
CI / Build ARM64 (GHCR Only) (./docker/realtime.Dockerfile, ghcr.io/simstudioai/realtime) (push) Has been cancelled
CI / Create GHCR Manifests (ghcr.io/simstudioai/migrations) (push) Has been cancelled
CI / Create GHCR Manifests (ghcr.io/simstudioai/pii) (push) Has been cancelled
CI / Create GHCR Manifests (ghcr.io/simstudioai/realtime) (push) Has been cancelled
CI / Create GHCR Manifests (ghcr.io/simstudioai/simstudio) (push) Has been cancelled
CI / Check Docs Changes (push) Has been cancelled
CI / Process Docs (push) Has been cancelled
CI / Create GitHub Release (push) Has been cancelled
CI / Test and Build (push) Has been cancelled
97 lines
2.7 KiB
TypeScript
97 lines
2.7 KiB
TypeScript
'use client'
|
|
|
|
import { useEffect, useEffectEvent, useLayoutEffect, useRef } from 'react'
|
|
import { getAssetUrl } from '@/lib/utils'
|
|
|
|
interface LightboxProps {
|
|
isOpen: boolean
|
|
onClose: () => void
|
|
src: string
|
|
alt: string
|
|
type: 'image' | 'video'
|
|
startTime?: number
|
|
}
|
|
|
|
export function Lightbox({ isOpen, onClose, src, alt, type, startTime }: LightboxProps) {
|
|
const overlayRef = useRef<HTMLDivElement>(null)
|
|
const mediaButtonRef = useRef<HTMLButtonElement>(null)
|
|
const videoRef = useRef<HTMLVideoElement>(null)
|
|
const closeLightbox = useEffectEvent(onClose)
|
|
|
|
useEffect(() => {
|
|
if (!isOpen) return
|
|
|
|
const handleKeyDown = (event: KeyboardEvent) => {
|
|
if (event.key === 'Escape') {
|
|
closeLightbox()
|
|
}
|
|
}
|
|
|
|
const handleClickOutside = (event: MouseEvent) => {
|
|
if (overlayRef.current && event.target === overlayRef.current) {
|
|
closeLightbox()
|
|
}
|
|
}
|
|
|
|
const previousOverflow = document.body.style.overflow
|
|
|
|
document.addEventListener('keydown', handleKeyDown)
|
|
document.addEventListener('click', handleClickOutside)
|
|
document.body.style.overflow = 'hidden'
|
|
mediaButtonRef.current?.focus()
|
|
|
|
return () => {
|
|
document.removeEventListener('keydown', handleKeyDown)
|
|
document.removeEventListener('click', handleClickOutside)
|
|
document.body.style.overflow = previousOverflow
|
|
}
|
|
}, [isOpen])
|
|
|
|
useLayoutEffect(() => {
|
|
if (isOpen && type === 'video' && videoRef.current && startTime != null && startTime > 0) {
|
|
videoRef.current.currentTime = startTime
|
|
}
|
|
}, [isOpen, startTime, type])
|
|
|
|
if (!isOpen) return null
|
|
|
|
return (
|
|
<div
|
|
ref={overlayRef}
|
|
className='fixed inset-0 z-50 flex items-center justify-center bg-black/80 p-12 backdrop-blur-sm'
|
|
role='dialog'
|
|
aria-modal='true'
|
|
aria-label='Media viewer'
|
|
>
|
|
<div className='relative max-h-full max-w-full overflow-hidden rounded-xl'>
|
|
<button
|
|
ref={mediaButtonRef}
|
|
type='button'
|
|
onClick={onClose}
|
|
aria-label='Close media viewer'
|
|
className='block cursor-pointer rounded-xl p-0 outline-none focus-visible:ring-2 focus-visible:ring-white/70'
|
|
>
|
|
{type === 'image' ? (
|
|
<img
|
|
src={src}
|
|
alt={alt}
|
|
className='max-h-[75vh] max-w-[75vw] rounded-xl object-contain'
|
|
loading='lazy'
|
|
/>
|
|
) : (
|
|
<video
|
|
ref={videoRef}
|
|
src={getAssetUrl(src)}
|
|
autoPlay
|
|
loop
|
|
muted
|
|
playsInline
|
|
className='max-h-[75vh] max-w-[75vw] rounded-xl outline-none focus:outline-none'
|
|
/>
|
|
)}
|
|
</button>
|
|
</div>
|
|
</div>
|
|
)
|
|
}
|