Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: fullscreen images slideshow #1120

Open
wants to merge 9 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
97 changes: 96 additions & 1 deletion frontend/src/static/js/components/media-page/MediaPage.scss
Original file line number Diff line number Diff line change
Expand Up @@ -522,6 +522,7 @@
display: block;

img {
cursor: pointer;
position: relative;
display: block;
max-width: 100%;
Expand All @@ -530,14 +531,108 @@
}
}

.modal-overlay {
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
background: rgba(0, 0, 0, 0.8);
display: flex;
justify-content: center;
align-items: center;
z-index: 1000;
}

.slideshow-container {
position: relative;
display: flex;
align-items: center;
justify-content: center;
width: auto;
max-width: 90%;
}

.slideshow-image img {
display: block;
width: auto;
height: auto;
max-width: 100%; /* Ensure image doesn't exceed container width */
max-height: 90vh;
border-radius: 0;
box-shadow: 0 4px 10px rgba(0, 0, 0, 0.2);
transition: transform 60s ease-in-out, opacity 60 ease-in-out;
}

.arrow {
position: absolute;
display: flex;
justify-content: center;
align-items: center;
width: 40px;
height: 40px;
top: 50%;
transform: translateY(-50%);
border: none;
color: white;
font-size: 2rem;
background-color: rgba(0, 0, 0, 0.2);
cursor: pointer;
padding: 10px;
border-radius: 50%;
z-index: 1000;
transition: background-color 0.2s ease, transform 0.2s ease;
text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.8);
}

.arrow:hover {
background: rgba(92, 78, 78, 0.6);
transform: translateY(-50%) scale(1.1);
}

.arrow.left {
left: 10px;
}

.arrow.right {
right: 10px;
}

.dots {
position: fixed; /* Make the dots container fixed to always be under the image */
bottom: 10%;
left: 50%;
transform: translateX(-50%);
display: flex;
gap: 10px;
justify-content: center;
z-index: 1000;
}

.dot {
width: 12px;
height: 12px;
background: rgba(255, 255, 255, 0.6);
border-radius: 50%;
cursor: pointer;
transition: all 0.3s ease-in-out;
}

.dot.active {
background: rgba(255, 255, 255, 1);
}

.dot:hover {
background: rgba(255, 255, 255, 0.8);
}

.viewer-container .player-container {
@media screen and (min-width: 480px) {
border-radius: 10px;
}
}

.viewer-container .player-container.audio-player-container {

@media screen and (min-width: 480px) {
padding-top: 0.75 * 56.25%;
}
Expand Down
100 changes: 84 additions & 16 deletions frontend/src/static/js/components/media-viewer/ImageViewer.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React, { useContext, useEffect, useState } from 'react';
import { SiteContext } from '../../utils/contexts/';
import { MediaPageStore } from '../../utils/stores/';

export default function ImageViewer(props) {
export default function ImageViewer() {
const site = useContext(SiteContext);

let initialImage = getImageUrl();
Expand All @@ -11,6 +11,9 @@ export default function ImageViewer(props) {
initialImage = initialImage ? initialImage : '';

const [image, setImage] = useState(initialImage);
const [slideshowItems, setSlideshowItems] = useState([]);
const [isModalOpen, setIsModalOpen] = useState(false);
const [currentIndex, setCurrentIndex] = useState(0);

function onImageLoad() {
setImage(getImageUrl());
Expand All @@ -19,34 +22,99 @@ export default function ImageViewer(props) {
function getImageUrl() {
const media_data = MediaPageStore.get('media-data');

let imgUrl = 'string' === typeof media_data.poster_url ? media_data.poster_url.trim() : '';
let imgUrl =
media_data.poster_url?.trim() ||
media_data.thumbnail_url?.trim() ||
MediaPageStore.get('media-original-url')?.trim() ||
'#';

if ('' === imgUrl) {
imgUrl = 'string' === typeof media_data.thumbnail_url ? media_data.thumbnail_url.trim() : '';
}
return site.url + '/' + imgUrl.replace(/^\//g, '');
}

if ('' === imgUrl) {
imgUrl =
'string' === typeof MediaPageStore.get('media-original-url')
? MediaPageStore.get('media-original-url').trim()
: '';
const fetchSlideShowItems = () => {
const media_data = MediaPageStore.get('media-data');
const items = media_data.slideshow_items;
if (Array.isArray(items)) {
setSlideshowItems(items);
}
};

if ('' === imgUrl) {
return '#';
useEffect(() => {
if (image) {
fetchSlideShowItems();
}

return site.url + '/' + imgUrl.replace(/^\//g, '');
}
}, [image]);

useEffect(() => {
MediaPageStore.on('loaded_image_data', onImageLoad);
return () => MediaPageStore.removeListener('loaded_image_data', onImageLoad);
}, []);

useEffect(() => {
if (!isModalOpen) return;

document.addEventListener('keydown', handleKeyDown);

return () => {
document.removeEventListener('keydown', handleKeyDown);
};
}, [isModalOpen, slideshowItems]);

const handleKeyDown = (event) => {
if (event.key === 'ArrowRight') handleNext();
if (event.key === 'ArrowLeft') handlePrevious();
if (event.key === 'Escape') onClose();
};

const onClose=()=>setIsModalOpen(false)

const handleNext = () => {
setCurrentIndex((prevIndex) => (prevIndex + 1) % slideshowItems.length);
};

const handlePrevious = () => {
setCurrentIndex((prevIndex) => (prevIndex - 1 + slideshowItems.length) % slideshowItems.length);
};

const handleDotClick = (index) => setCurrentIndex(index);

const handleImageClick = (index) => {
const mediaPageUrl = site.url + slideshowItems[index]?.url;
window.location.href = mediaPageUrl;
};

return !image ? null : (
<div className="viewer-image-container">
<img src={image} alt={MediaPageStore.get('media-data').title || null} />
<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 && 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">
&#8249;
</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">
&#8250;
</button>
<div className="dots">
{slideshowItems.map((_, index) => (
<span
key={index}
className={`dot ${currentIndex === index ? 'active' : ''}`}
onClick={() => handleDotClick(index)}
></span>
))}
</div>
</div>
</div>
)}
</div>
);
}
2 changes: 1 addition & 1 deletion static/css/media.css

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion static/js/media.js

Large diffs are not rendered by default.

Loading