mirror of
https://github.com/mediacms-io/mediacms.git
synced 2024-11-24 17:24:43 +01:00
handle image click
This commit is contained in:
parent
fc268380da
commit
80e732f2e8
@ -46,7 +46,7 @@ export default function ImageViewer() {
|
||||
}, [image]);
|
||||
|
||||
useEffect(() => {
|
||||
MediaPageStore.on('loaded_image_data', onImageLoad);
|
||||
MediaPageStore.on('page_init', onImageLoad);
|
||||
return () => MediaPageStore.removeListener('loaded_image_data', onImageLoad);
|
||||
}, []);
|
||||
|
||||
@ -55,47 +55,36 @@ export default function ImageViewer() {
|
||||
};
|
||||
|
||||
const handlePrevious = () => {
|
||||
setCurrentIndex((prevIndex) =>
|
||||
(prevIndex - 1 + slideshowItems.length) % slideshowItems.length
|
||||
);
|
||||
setCurrentIndex((prevIndex) => (prevIndex - 1 + slideshowItems.length) % slideshowItems.length);
|
||||
};
|
||||
|
||||
const handleDotClick = (index) => {
|
||||
setCurrentIndex(index);
|
||||
};
|
||||
|
||||
console.log(slideshowItems[currentIndex]?.original_media_url)
|
||||
|
||||
const handleImageClick = (index) => {
|
||||
const mediaPageUrl = site.url + slideshowItems[index]?.url;
|
||||
window.location = mediaPageUrl;
|
||||
};
|
||||
|
||||
return !image ? null : (
|
||||
<div className="viewer-image-container">
|
||||
<img src={image} alt={MediaPageStore.get('media-data').title || null} onClick={() => setIsModalOpen(true)} />
|
||||
{/* {slideshowItems && <div>{slideshowItems.map((i)=><li>{i.poster_url}</li>)}</div>} */}
|
||||
{isModalOpen && (
|
||||
{isModalOpen && slideshowItems && (
|
||||
<div className="modal-overlay" onClick={() => setIsModalOpen(false)}>
|
||||
<div
|
||||
className="slideshow-container"
|
||||
onClick={(e) => e.stopPropagation()}
|
||||
>
|
||||
<button
|
||||
className="arrow left"
|
||||
onClick={handlePrevious}
|
||||
aria-label="Previous slide"
|
||||
>
|
||||
‹
|
||||
<div className="slideshow-container" onClick={(e) => e.stopPropagation()}>
|
||||
<button className="arrow left" onClick={handlePrevious} aria-label="Previous slide">
|
||||
‹
|
||||
</button>
|
||||
<div className="slideshow-image">
|
||||
<img
|
||||
src={site.url + '/' + slideshowItems[currentIndex]?.original_media_url}
|
||||
alt={`Slide ${currentIndex + 1}`}
|
||||
onClick={() => handleImageClick(currentIndex)}
|
||||
/>
|
||||
</div>
|
||||
<button
|
||||
className="arrow right"
|
||||
onClick={handleNext}
|
||||
aria-label="Next slide"
|
||||
>
|
||||
›
|
||||
<button className="arrow right" onClick={handleNext} aria-label="Next slide">
|
||||
›
|
||||
</button>
|
||||
<div className="dots">
|
||||
{slideshowItems.map((_, index) => (
|
||||
|
Loading…
Reference in New Issue
Block a user