From 1391f882636635b57254e1ab09cf0573234cc9e1 Mon Sep 17 00:00:00 2001 From: Mo Date: Thu, 21 Apr 2022 07:36:56 -0500 Subject: [PATCH] feat: preview improvements (#989) * feat: preview file on click * fix: maintain aspect ratio of image when previewing * fix: use min width instead of width --- .../AttachedFilesPopover/PopoverFileItem.tsx | 9 ++++- .../Components/Files/ImagePreview.tsx | 35 +++++++++---------- 2 files changed, 24 insertions(+), 20 deletions(-) diff --git a/app/assets/javascripts/Components/AttachedFilesPopover/PopoverFileItem.tsx b/app/assets/javascripts/Components/AttachedFilesPopover/PopoverFileItem.tsx index d5b61ceb3..010d2527b 100644 --- a/app/assets/javascripts/Components/AttachedFilesPopover/PopoverFileItem.tsx +++ b/app/assets/javascripts/Components/AttachedFilesPopover/PopoverFileItem.tsx @@ -7,6 +7,7 @@ import { useEffect, useRef, useState } from 'preact/hooks' import { Icon, ICONS } from '@/Components/Icon' import { PopoverFileItemAction, PopoverFileItemActionType } from './PopoverFileItemAction' import { PopoverFileSubmenu } from './PopoverFileSubmenu' +import { useFilePreviewModal } from '@/Components/Files/FilePreviewModalProvider' export const getFileIconComponent = (iconType: string, className: string) => { const IconComponent = ICONS[iconType as keyof typeof ICONS] @@ -29,6 +30,8 @@ export const PopoverFileItem: FunctionComponent = ({ getIconType, closeOnBlur, }) => { + const filePreviewModal = useFilePreviewModal() + const [fileName, setFileName] = useState(file.name) const [isRenamingFile, setIsRenamingFile] = useState(false) const itemRef = useRef(null) @@ -65,13 +68,17 @@ export const PopoverFileItem: FunctionComponent = ({ renameFile(file, fileName).catch(console.error) } + const clickHandler = () => { + filePreviewModal.activate(file) + } + return (
-
+
{getFileIconComponent(getIconType(file.mimeType), 'w-8 h-8 flex-shrink-0')}
{isRenamingFile ? ( diff --git a/app/assets/javascripts/Components/Files/ImagePreview.tsx b/app/assets/javascripts/Components/Files/ImagePreview.tsx index 05df08fa5..49d827513 100644 --- a/app/assets/javascripts/Components/Files/ImagePreview.tsx +++ b/app/assets/javascripts/Components/Files/ImagePreview.tsx @@ -1,6 +1,6 @@ import { IconType } from '@standardnotes/snjs' import { FunctionComponent } from 'preact' -import { useEffect, useRef, useState } from 'preact/hooks' +import { useRef, useState } from 'preact/hooks' import { IconButton } from '../Button/IconButton' type Props = { @@ -11,19 +11,16 @@ export const ImagePreview: FunctionComponent = ({ objectUrl }) => { const initialImgHeightRef = useRef() const [imageZoomPercent, setImageZoomPercent] = useState(100) - const [imageHeight, setImageHeight] = useState(initialImgHeightRef.current) - - useEffect(() => { - if (initialImgHeightRef.current) { - setImageHeight(imageZoomPercent * (initialImgHeightRef.current / 100)) - } - }, [imageZoomPercent]) return (
{ if (!initialImgHeightRef.current) { initialImgHeightRef.current = imgElement?.height @@ -32,16 +29,6 @@ export const ImagePreview: FunctionComponent = ({ objectUrl }) => { />
Zoom: - { - setImageZoomPercent((percent) => percent + 10) - }} - /> - {imageZoomPercent}% = ({ objectUrl }) => { }) }} /> + {imageZoomPercent}% + { + setImageZoomPercent((percent) => percent + 10) + }} + />
)