Skip to content

Commit

Permalink
(feat: add keyboard shortcuts for media previews)
Browse files Browse the repository at this point in the history
  • Loading branch information
charli117 committed Dec 9, 2024
1 parent 44019a5 commit c9f11ce
Show file tree
Hide file tree
Showing 5 changed files with 782 additions and 734 deletions.
2 changes: 1 addition & 1 deletion web/app/components/base/file-uploader/audio-preview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const AudioPreview: FC<AudioPreviewProps> = ({
onCancel,
}) => {
useKeyboardShortcuts({
esc: onCancel
esc: onCancel,
})

return createPortal(
Expand Down
8 changes: 4 additions & 4 deletions web/app/components/base/file-uploader/pdf-preview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,12 @@ const PdfPreview: FC<PdfPreviewProps> = ({
tabIndex={-1}
>
<div
className='h-[95vh] w-[100vw] max-w-full max-h-full overflow-hidden'
style={{ transform: `scale(${scale})`, transformOrigin: 'center', scrollbarWidth: 'none', msOverflowStyle: 'none' }}
className='h-[95vh] w-[100vw] max-w-full max-h-full overflow-hidden'
style={{ transform: `scale(${scale})`, transformOrigin: 'center', scrollbarWidth: 'none', msOverflowStyle: 'none' }}
>
<PdfLoader
url={url}
beforeLoad={<div className='flex justify-center items-center h-64'><Loading type='app' /></div>}
url={url}
beforeLoad={<div className='flex justify-center items-center h-64'><Loading type='app' /></div>}
>
{(pdfDocument) => {
return (
Expand Down
10 changes: 5 additions & 5 deletions web/app/components/base/image-uploader/image-preview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -194,11 +194,11 @@ const ImagePreview: FC<ImagePreviewProps> = ({
}, [handleMouseUp])

useKeyboardShortcuts({
esc: onCancel,
up: zoomIn,
down: zoomOut,
left: onPrev ? onPrev : () => {},
right: onNext ? onNext : () => {},
esc: onCancel,
up: zoomIn,
down: zoomOut,
left: onPrev || (() => {}),
right: onNext || (() => {}),
})

return createPortal(
Expand Down
5 changes: 2 additions & 3 deletions web/hooks/use-keyboard-short.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import { useHotkeys } from 'react-hotkeys-hook'


export function useKeyboardShortcuts(shortcuts: { [x: string]: any }) {
Object.keys(shortcuts).forEach(key => {
Object.keys(shortcuts).forEach((key) => {
const action = shortcuts[key]
useHotkeys(key, action)
})
}
}
Loading

0 comments on commit c9f11ce

Please sign in to comment.