1
0
Fork 0
mirror of https://github.com/muerwre/vault-frontend.git synced 2025-04-25 04:46:40 +07:00

closing modal on back button

This commit is contained in:
Fedor Katurov 2020-06-26 11:33:10 +07:00
parent 5a6e34d769
commit 49efc452d3

View file

@ -67,6 +67,20 @@ const PhotoSwipeUnconnected: FC<Props> = ({ photoswipe, modalSetShown }) => {
});
}, [photoswipe.images, photoswipe.index]);
const closeOnHashChange = useCallback(() => {
if (window.location.hash !== '#preview') return closeModal();
}, [closeModal]);
useEffect(() => {
window.addEventListener('hashchange', closeOnHashChange);
return () => window.removeEventListener('hashchange', closeOnHashChange);
}, [closeOnHashChange]);
useEffect(() => {
window.location.hash = 'preview';
return () => (window.location.hash = '');
}, []);
return (
<div className="pswp" tabIndex={-1} role="dialog" aria-hidden="true" ref={ref}>
<div className={classNames('pswp__bg', styles.bg)} />