Anton Tranelis 924195ce9f
fix(source): fix gallery (#213)
* 3.0.82

* version number

* fix gallery bug
2025-05-06 09:31:36 +00:00

34 lines
994 B
TypeScript

import { useState } from 'react'
import { RowsPhotoAlbum } from 'react-photo-album'
import ReactLightbox from 'yet-another-react-lightbox'
import { useAppState } from '#components/AppShell/hooks/useAppState'
import type { Item } from '#types/Item'
export const GalleryView = ({ item }: { item: Item }) => {
const [index, setIndex] = useState(-1)
const appState = useAppState()
const images =
item.gallery?.map((i, j) => ({
src: appState.assetsApi.url + `${i.directus_files_id.id}.jpg`,
width: i.directus_files_id.width,
height: i.directus_files_id.height,
index: j,
})) ?? []
if (images.length > 0)
return (
<div className='tw:mx-6 tw:mb-6'>
<RowsPhotoAlbum
photos={images}
targetRowHeight={150}
onClick={({ index: current }) => setIndex(current)}
/>
<ReactLightbox index={index} slides={images} open={index >= 0} close={() => setIndex(-1)} />
</div>
)
else return <></>
}