From f2ecc1803f3ea294a0c6b7915b61348ed0395b26 Mon Sep 17 00:00:00 2001 From: Marcin Zelent Date: Wed, 16 Nov 2022 15:16:38 +0100 Subject: Remade and extended the app using React --- components/Gallery/Gallery.tsx | 80 ------------------------------------------ 1 file changed, 80 deletions(-) delete mode 100644 components/Gallery/Gallery.tsx (limited to 'components/Gallery/Gallery.tsx') diff --git a/components/Gallery/Gallery.tsx b/components/Gallery/Gallery.tsx deleted file mode 100644 index dfadbc0..0000000 --- a/components/Gallery/Gallery.tsx +++ /dev/null @@ -1,80 +0,0 @@ -import { useEffect, useRef } from 'react'; - -import { Photo } from 'models'; -import useEvent from 'lib/useEvent'; -import styles from './Gallery.module.css'; - -interface Props { - currentPhoto: Photo; - handleClose: () => void; - handlePhotoChange: (direction: boolean) => void; -} - -export default function Gallery({ - currentPhoto, - handleClose, - handlePhotoChange, -}: Props): JSX.Element { - const wrapperRef = useRef(null); - - useEffect(() => { - function handleClickOutside(e: MouseEvent) { - if ( - wrapperRef.current && - !wrapperRef.current.contains(e.target) && - (e.target as Node).nodeName !== 'BUTTON' - ) { - handleClose(); - } - } - - document.addEventListener('mousedown', handleClickOutside); - return () => { - document.removeEventListener('mousedown', handleClickOutside); - }; - }, [wrapperRef]); - - useEvent('keydown', (e: KeyboardEvent) => { - if (e.key === 'ArrowLeft') { - handlePhotoChange(false); - } else if (e.key === 'ArrowRight') { - handlePhotoChange(true); - } else if (e.key === 'Escape') { - handleClose(); - } - }); - - return ( -
- -
- {currentPhoto.name} -
- - -
- ); -} -- cgit v1.2.3