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 [images, setImages] = useState<string[]>([]);
|
||||||
const [galleryId, setGalleryId] = useState(id as string);
|
const [galleryId, setGalleryId] = useState(id as string);
|
||||||
const [currentIndex, setCurrentIndex] = useState(0);
|
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 getData = async () => {
|
||||||
const thumbnailResponse = await fetch('/api/galleries/' + String(galleryId) + '/images');
|
const thumbnailResponse = await fetch('/api/galleries/' + String(galleryId) + '/images');
|
||||||
const thumbnailUrl = await thumbnailResponse.json() as string[];
|
const thumbnailUrl = await thumbnailResponse.json() as string[];
|
||||||
setImages(thumbnailUrl);
|
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 = () => {
|
const next = () => {
|
||||||
if (currentIndex < images.length - 1) {
|
if (currentIndex < images.length - 1) {
|
||||||
@ -119,6 +103,9 @@ const Gallery = ({ id, closeMenu }: GalleryProps) => {
|
|||||||
case 'D':
|
case 'D':
|
||||||
next();
|
next();
|
||||||
break;
|
break;
|
||||||
|
case 'Escape':
|
||||||
|
close();
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -132,7 +119,7 @@ const Gallery = ({ id, closeMenu }: GalleryProps) => {
|
|||||||
window.removeEventListener('keydown', handleKeyDown);
|
window.removeEventListener('keydown', handleKeyDown);
|
||||||
};
|
};
|
||||||
|
|
||||||
}, [currentIndex]);
|
}, [selectedImage,currentIndex]);
|
||||||
|
|
||||||
const handleClick = (image: string) => {
|
const handleClick = (image: string) => {
|
||||||
setSelectedImage(image);
|
setSelectedImage(image);
|
||||||
@ -152,6 +139,7 @@ const Gallery = ({ id, closeMenu }: GalleryProps) => {
|
|||||||
const close = () => {
|
const close = () => {
|
||||||
if (selectedImage != null) {
|
if (selectedImage != null) {
|
||||||
setSelectedImage(null);
|
setSelectedImage(null);
|
||||||
|
setImages([]);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
closeMenu();
|
closeMenu();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user