Attempt to enable shortcuts on photoView

This commit is contained in:
Neeraj Gupta 2022-10-28 19:12:00 +05:30
parent bce60813fd
commit c47ebfdc2e
No known key found for this signature in database
GPG key ID: 3C5A1684DC1729E1

View file

@ -72,6 +72,34 @@ function PhotoViewer(props: Iprops) {
useEffect(() => { useEffect(() => {
if (!pswpElement) return; if (!pswpElement) return;
function handleKeyUp(event) {
if (!isOpen) {
return;
}
console.log(
'Event: ' + event.key + ' isShiftPressedx: ' + event.shiftKey
);
switch (event.key) {
case 'i':
if (isOpen && !showInfo) {
setShowInfo(true);
}
break;
case 'Backspace':
confirmTrashFile(photoSwipe?.currItem as EnteFile);
break;
case 'd':
case 'D':
if (event.shiftKey) {
downloadFileHelper(photoSwipe?.currItem as EnteFile);
}
break;
default:
break;
}
}
window.addEventListener('keyup', handleKeyUp);
if (isOpen) { if (isOpen) {
openPhotoSwipe(); openPhotoSwipe();
} }
@ -80,6 +108,8 @@ function PhotoViewer(props: Iprops) {
} }
return () => { return () => {
closePhotoSwipe(); closePhotoSwipe();
console.log('Removing listner');
window.removeEventListener('keyup', handleKeyUp);
}; };
}, [isOpen]); }, [isOpen]);
@ -277,8 +307,12 @@ function PhotoViewer(props: Iprops) {
needUpdate.current = true; needUpdate.current = true;
}; };
const confirmTrashFile = (file: EnteFile) => const confirmTrashFile = (file: EnteFile) => {
if (props.isSharedCollection || props.isTrashCollection) {
return;
}
appContext.setDialogMessage(getTrashFileMessage(() => trashFile(file))); appContext.setDialogMessage(getTrashFileMessage(() => trashFile(file)));
};
const updateItems = (items = []) => { const updateItems = (items = []) => {
if (photoSwipe) { if (photoSwipe) {
@ -336,15 +370,16 @@ function PhotoViewer(props: Iprops) {
}; };
const downloadFileHelper = async (file) => { const downloadFileHelper = async (file) => {
appContext.startLoading(); if (props.enableDownload) {
await downloadFile( appContext.startLoading();
file, await downloadFile(
publicCollectionGalleryContext.accessedThroughSharedURL, file,
publicCollectionGalleryContext.token, publicCollectionGalleryContext.accessedThroughSharedURL,
publicCollectionGalleryContext.passwordToken publicCollectionGalleryContext.token,
); publicCollectionGalleryContext.passwordToken
);
appContext.finishLoading(); appContext.finishLoading();
}
}; };
const scheduleUpdate = () => (needUpdate.current = true); const scheduleUpdate = () => (needUpdate.current = true);
const { id } = props; const { id } = props;