From 096d82f7af73613a3d8bc994bec2ec10a92a527c Mon Sep 17 00:00:00 2001 From: Aman Harwara Date: Wed, 23 Nov 2022 00:55:20 +0530 Subject: [PATCH] fix: lazy load embedded files in super editor (#2043) --- .../Components/FilePreview/FilePreview.tsx | 30 +++++++++++---- .../FilePreview/FilePreviewError.tsx | 4 +- .../Components/NoteView/NoteView.tsx | 2 +- .../Nodes/FileComponent.tsx | 38 ++++++++++++++++++- 4 files changed, 62 insertions(+), 12 deletions(-) diff --git a/packages/web/src/javascripts/Components/FilePreview/FilePreview.tsx b/packages/web/src/javascripts/Components/FilePreview/FilePreview.tsx index b86a2506c..8f1febf9b 100644 --- a/packages/web/src/javascripts/Components/FilePreview/FilePreview.tsx +++ b/packages/web/src/javascripts/Components/FilePreview/FilePreview.tsx @@ -6,7 +6,8 @@ import Spinner from '@/Components/Spinner/Spinner' import FilePreviewError from './FilePreviewError' import { isFileTypePreviewable } from './isFilePreviewable' import PreviewComponent from './PreviewComponent' -import ProtectedItemOverlay from '../ProtectedItemOverlay/ProtectedItemOverlay' +import Button from '../Button/Button' +import { ProtectedIllustration } from '@standardnotes/icons' type Props = { application: WebApplication @@ -77,13 +78,28 @@ const FilePreview = ({ file, application }: Props) => { }, [application.files, downloadedBytes, file, isFilePreviewable, isAuthorized]) if (!isAuthorized) { + const hasProtectionSources = application.hasProtectionSources() + return ( - application.protections.authorizeItemAccess(file)} - hasProtectionSources={application.hasProtectionSources()} - /> +
+ +
This file is protected.
+

+ {hasProtectionSources + ? 'Authenticate to view this file.' + : 'Add a passcode or create an account to require authentication to view this file.'} +

+
+ {!hasProtectionSources && ( + + )} + +
+
) } diff --git a/packages/web/src/javascripts/Components/FilePreview/FilePreviewError.tsx b/packages/web/src/javascripts/Components/FilePreview/FilePreviewError.tsx index 29119f021..67f9a9f36 100644 --- a/packages/web/src/javascripts/Components/FilePreview/FilePreviewError.tsx +++ b/packages/web/src/javascripts/Components/FilePreview/FilePreviewError.tsx @@ -17,7 +17,7 @@ const FilePreviewError = ({ file, filesController, isFilePreviewable, tryAgainCa
This file can't be previewed.
{isFilePreviewable ? ( <> -
+
There was an error loading the file. Try again, or download the file and open it using another application.
@@ -41,7 +41,7 @@ const FilePreviewError = ({ file, filesController, isFilePreviewable, tryAgainCa ) : ( <> -
+
To view this file, download it and open it using another application.