From d7dbb2810fe5e6b25168f71174da74ae4104746c Mon Sep 17 00:00:00 2001 From: Eric Han Date: Mon, 11 Mar 2024 15:42:13 +0800 Subject: [PATCH 1/5] fix PDF thumbnail reload when hovering on it --- src/components/PDFThumbnail/index.native.tsx | 4 ++-- src/components/PDFThumbnail/index.tsx | 5 ++++- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/components/PDFThumbnail/index.native.tsx b/src/components/PDFThumbnail/index.native.tsx index 4d3a33ae4e67..5f56171dd5b4 100644 --- a/src/components/PDFThumbnail/index.native.tsx +++ b/src/components/PDFThumbnail/index.native.tsx @@ -6,7 +6,7 @@ import useThemeStyles from '@hooks/useThemeStyles'; import addEncryptedAuthTokenToURL from '@libs/addEncryptedAuthTokenToURL'; import type PDFThumbnailProps from './types'; -function PDFThumbnail({previewSourceURL, style, isAuthTokenRequired = false, enabled = true, onPassword = () => {}}: PDFThumbnailProps) { +function PDFThumbnail({previewSourceURL, style, isAuthTokenRequired = false, enabled = true, onPassword = undefined}: PDFThumbnailProps) { const styles = useThemeStyles(); const sizeStyles = [styles.w100, styles.h100]; @@ -22,7 +22,7 @@ function PDFThumbnail({previewSourceURL, style, isAuthTokenRequired = false, ena singlePage style={sizeStyles} onError={(error) => { - if (!('message' in error && typeof error.message === 'string' && error.message.match(/password/i))) { + if (!onPassword || !('message' in error && typeof error.message === 'string' && error.message.match(/password/i))) { return; } onPassword(); diff --git a/src/components/PDFThumbnail/index.tsx b/src/components/PDFThumbnail/index.tsx index e69e4dd5075b..1f8341446ce3 100644 --- a/src/components/PDFThumbnail/index.tsx +++ b/src/components/PDFThumbnail/index.tsx @@ -12,7 +12,7 @@ if (!pdfjs.GlobalWorkerOptions.workerSrc) { pdfjs.GlobalWorkerOptions.workerSrc = URL.createObjectURL(new Blob([pdfWorkerSource], {type: 'text/javascript'})); } -function PDFThumbnail({previewSourceURL, style, isAuthTokenRequired = false, enabled = true, onPassword = () => {}}: PDFThumbnailProps) { +function PDFThumbnail({previewSourceURL, style, isAuthTokenRequired = false, enabled = true, onPassword = undefined}: PDFThumbnailProps) { const styles = useThemeStyles(); const thumbnail = useMemo( @@ -26,6 +26,9 @@ function PDFThumbnail({previewSourceURL, style, isAuthTokenRequired = false, ena }} externalLinkTarget="_blank" onPassword={() => { + if (!onPassword) { + return; + } onPassword(); }} > From bb5bf80b82d677e25ac3b3e9cb464c3a0a53990e Mon Sep 17 00:00:00 2001 From: Eric Han <117511920+eh2077@users.noreply.github.com> Date: Mon, 11 Mar 2024 23:18:51 +0800 Subject: [PATCH 2/5] Update src/components/PDFThumbnail/index.native.tsx Co-authored-by: Abdelhafidh Belalia <16493223+s77rt@users.noreply.github.com> --- src/components/PDFThumbnail/index.native.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/PDFThumbnail/index.native.tsx b/src/components/PDFThumbnail/index.native.tsx index 5f56171dd5b4..753a06451f8a 100644 --- a/src/components/PDFThumbnail/index.native.tsx +++ b/src/components/PDFThumbnail/index.native.tsx @@ -6,7 +6,7 @@ import useThemeStyles from '@hooks/useThemeStyles'; import addEncryptedAuthTokenToURL from '@libs/addEncryptedAuthTokenToURL'; import type PDFThumbnailProps from './types'; -function PDFThumbnail({previewSourceURL, style, isAuthTokenRequired = false, enabled = true, onPassword = undefined}: PDFThumbnailProps) { +function PDFThumbnail({previewSourceURL, style, isAuthTokenRequired = false, enabled = true, onPassword}: PDFThumbnailProps) { const styles = useThemeStyles(); const sizeStyles = [styles.w100, styles.h100]; From 797a24de09e4d631aa8be3f6fd0176d2d89ad6dc Mon Sep 17 00:00:00 2001 From: Eric Han <117511920+eh2077@users.noreply.github.com> Date: Mon, 11 Mar 2024 23:19:01 +0800 Subject: [PATCH 3/5] Update src/components/PDFThumbnail/index.native.tsx Co-authored-by: Abdelhafidh Belalia <16493223+s77rt@users.noreply.github.com> --- src/components/PDFThumbnail/index.native.tsx | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/components/PDFThumbnail/index.native.tsx b/src/components/PDFThumbnail/index.native.tsx index 753a06451f8a..0232dba99f05 100644 --- a/src/components/PDFThumbnail/index.native.tsx +++ b/src/components/PDFThumbnail/index.native.tsx @@ -22,7 +22,10 @@ function PDFThumbnail({previewSourceURL, style, isAuthTokenRequired = false, ena singlePage style={sizeStyles} onError={(error) => { - if (!onPassword || !('message' in error && typeof error.message === 'string' && error.message.match(/password/i))) { + if (!('message' in error && typeof error.message === 'string' && error.message.match(/password/i))) { + return; + } + if (!onPassword) { return; } onPassword(); From 9da2ea06dddc78d19ef8f40fbfe1e541d21f845e Mon Sep 17 00:00:00 2001 From: Eric Han <117511920+eh2077@users.noreply.github.com> Date: Mon, 11 Mar 2024 23:19:14 +0800 Subject: [PATCH 4/5] Update src/components/PDFThumbnail/index.tsx Co-authored-by: Abdelhafidh Belalia <16493223+s77rt@users.noreply.github.com> --- src/components/PDFThumbnail/index.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/PDFThumbnail/index.tsx b/src/components/PDFThumbnail/index.tsx index 1f8341446ce3..2355967210f5 100644 --- a/src/components/PDFThumbnail/index.tsx +++ b/src/components/PDFThumbnail/index.tsx @@ -12,7 +12,7 @@ if (!pdfjs.GlobalWorkerOptions.workerSrc) { pdfjs.GlobalWorkerOptions.workerSrc = URL.createObjectURL(new Blob([pdfWorkerSource], {type: 'text/javascript'})); } -function PDFThumbnail({previewSourceURL, style, isAuthTokenRequired = false, enabled = true, onPassword = undefined}: PDFThumbnailProps) { +function PDFThumbnail({previewSourceURL, style, isAuthTokenRequired = false, enabled = true, onPassword}: PDFThumbnailProps) { const styles = useThemeStyles(); const thumbnail = useMemo( From 381f1d8c34586e90619a24333982e21ce2d62d0a Mon Sep 17 00:00:00 2001 From: Eric Han <117511920+eh2077@users.noreply.github.com> Date: Mon, 11 Mar 2024 23:19:52 +0800 Subject: [PATCH 5/5] Update src/components/PDFThumbnail/index.tsx Co-authored-by: Abdelhafidh Belalia <16493223+s77rt@users.noreply.github.com> --- src/components/PDFThumbnail/index.tsx | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/src/components/PDFThumbnail/index.tsx b/src/components/PDFThumbnail/index.tsx index 2355967210f5..a5b911deb6ff 100644 --- a/src/components/PDFThumbnail/index.tsx +++ b/src/components/PDFThumbnail/index.tsx @@ -25,12 +25,7 @@ function PDFThumbnail({previewSourceURL, style, isAuthTokenRequired = false, ena cMapPacked: true, }} externalLinkTarget="_blank" - onPassword={() => { - if (!onPassword) { - return; - } - onPassword(); - }} + onPassword={onPassword} >