mirror of
https://github.com/D4M13N-D3V/neroshitron.git
synced 2025-03-14 10:05:04 +00:00
fix: ability to go back using escape
This commit is contained in:
parent
d8e30415cb
commit
b14c9d54ad
@ -16,28 +16,12 @@ const Gallery = ({ id, closeMenu }: GalleryProps) => {
|
||||
const [images, setImages] = useState<string[]>([]);
|
||||
const [galleryId, setGalleryId] = useState(id as string);
|
||||
const [currentIndex, setCurrentIndex] = useState(0);
|
||||
const goToNext = () => {
|
||||
setCurrentIndex(prevIndex => (prevIndex + 1) % images.length);
|
||||
}
|
||||
|
||||
const goToPrevious = () => {
|
||||
setCurrentIndex(prevIndex => (prevIndex - 1 + images.length) % images.length);
|
||||
}
|
||||
console.log(id)
|
||||
const getData = async () => {
|
||||
const thumbnailResponse = await fetch('/api/galleries/' + String(galleryId) + '/images');
|
||||
const thumbnailUrl = await thumbnailResponse.json() as string[];
|
||||
setImages(thumbnailUrl);
|
||||
}
|
||||
const generateRandomString = function (length:number) {
|
||||
let result = '';
|
||||
let characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
|
||||
let charactersLength = characters.length;
|
||||
for ( let i = 0; i < length; i++ ) {
|
||||
result += characters.charAt(Math.floor(Math.random() * charactersLength));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
const next = () => {
|
||||
if (currentIndex < images.length - 1) {
|
||||
@ -119,6 +103,9 @@ const Gallery = ({ id, closeMenu }: GalleryProps) => {
|
||||
case 'D':
|
||||
next();
|
||||
break;
|
||||
case 'Escape':
|
||||
close();
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
@ -132,7 +119,7 @@ const Gallery = ({ id, closeMenu }: GalleryProps) => {
|
||||
window.removeEventListener('keydown', handleKeyDown);
|
||||
};
|
||||
|
||||
}, [currentIndex]);
|
||||
}, [selectedImage,currentIndex]);
|
||||
|
||||
const handleClick = (image: string) => {
|
||||
setSelectedImage(image);
|
||||
@ -152,6 +139,7 @@ const Gallery = ({ id, closeMenu }: GalleryProps) => {
|
||||
const close = () => {
|
||||
if (selectedImage != null) {
|
||||
setSelectedImage(null);
|
||||
setImages([]);
|
||||
}
|
||||
else {
|
||||
closeMenu();
|
||||
|
Loading…
x
Reference in New Issue
Block a user