add copy event handler

This commit is contained in:
Abhinav 2022-11-22 20:55:31 +05:30
parent 35f3a14787
commit 48008ea040

View file

@ -104,17 +104,15 @@ function PhotoViewer(props: Iprops) {
useEffect(() => { useEffect(() => {
if (!photoSwipe) return; if (!photoSwipe) return;
function handleCopyEvent() {
copyToClipboardHelper(photoSwipe.currItem as EnteFile);
}
function handleKeyUp(event: KeyboardEvent) { function handleKeyUp(event: KeyboardEvent) {
if (!isOpen || showInfo) { if (!isOpen || showInfo) {
return; return;
} }
addLocalLog( addLocalLog(() => 'Event: ' + event.key);
() =>
'Event: ' +
event.key +
' isShiftPressedx: ' +
event.shiftKey
);
switch (event.key) { switch (event.key) {
case 'i': case 'i':
case 'I': case 'I':
@ -140,19 +138,17 @@ function PhotoViewer(props: Iprops) {
case 'L': case 'L':
onFavClick(photoSwipe?.currItem as EnteFile); onFavClick(photoSwipe?.currItem as EnteFile);
break; break;
case 'c':
case 'C':
copyFileToClipboard(photoSwipe.currItem.src);
break;
default: default:
break; break;
} }
} }
window.addEventListener('keyup', handleKeyUp); window.addEventListener('keyup', handleKeyUp);
window.addEventListener('copy', handleCopyEvent);
return () => { return () => {
addLocalLog(() => 'Removing listener'); addLocalLog(() => 'Removing listener');
window.removeEventListener('keyup', handleKeyUp); window.removeEventListener('keyup', handleKeyUp);
window.removeEventListener('copy', handleCopyEvent);
}; };
}, [isOpen, photoSwipe, showInfo]); }, [isOpen, photoSwipe, showInfo]);