From fc3a468675b0093f0fcf3a3b005b4eff0d53d351 Mon Sep 17 00:00:00 2001 From: Michael Yankelev Date: Fri, 12 Nov 2021 16:49:15 +0200 Subject: [PATCH 1/4] ensure no error is returned --- .../Modules/FileBrowsers/hooks/useGetFile.tsx | 5 +- .../Components/Modules/FilePreviewModal.tsx | 49 ++++++++++--------- .../files-ui/src/Contexts/FilesContext.tsx | 28 +++++------ 3 files changed, 41 insertions(+), 41 deletions(-) diff --git a/packages/files-ui/src/Components/Modules/FileBrowsers/hooks/useGetFile.tsx b/packages/files-ui/src/Components/Modules/FileBrowsers/hooks/useGetFile.tsx index 4f3b9363de..6bd110f4d4 100644 --- a/packages/files-ui/src/Components/Modules/FileBrowsers/hooks/useGetFile.tsx +++ b/packages/files-ui/src/Components/Modules/FileBrowsers/hooks/useGetFile.tsx @@ -59,14 +59,13 @@ export const useGetFile = () => { setIsDownloading(false) return content - } catch (error) { - setIsDownloading(false) - + } catch (error) { // If no error is thrown, this was due to a cancellation by the user. if (error) { console.error(error) setError(t`There was an error getting the preview.`) } + setIsDownloading(false) } }, [bucket, getFileContent]) diff --git a/packages/files-ui/src/Components/Modules/FilePreviewModal.tsx b/packages/files-ui/src/Components/Modules/FilePreviewModal.tsx index d2db47bbf4..8b964165f4 100644 --- a/packages/files-ui/src/Components/Modules/FilePreviewModal.tsx +++ b/packages/files-ui/src/Components/Modules/FilePreviewModal.tsx @@ -162,7 +162,7 @@ const useStyles = makeStyles( position: "absolute" } }, - focusVisible:{ + focusVisible: { backgroundColor: "transparent !important" }, menuWrapper: { @@ -185,7 +185,7 @@ interface Props { const FilePreviewModal = ({ file, nextFile, previousFile, closePreview, filePath }: Props) => { const classes = useStyles() const { downloadFile } = useFiles() - const [fileContent, setFileContent] = useState() + const [fileContent, setFileContent] = useState() const { bucket } = useFileBrowser() const { buckets } = useFiles() const { desktop } = useThemeSwitcher() @@ -217,6 +217,7 @@ const FilePreviewModal = ({ file, nextFile, previousFile, closePreview, filePath setFileContent(undefined) if (previewRendererKey) { + debugger getFile({ file, filePath: getPathWithFile(filePath, file.name), bucketId }) .then((content) => { setFileContent(content) @@ -296,7 +297,7 @@ const FilePreviewModal = ({ file, nextFile, previousFile, closePreview, filePath } + icon={} options={menuItems} style={{ focusVisible: classes.focusVisible, @@ -369,27 +370,27 @@ const FilePreviewModal = ({ file, nextFile, previousFile, closePreview, filePath {!isDownloading && !error && !compatibleFilesMatcher.match(content_type) && ( -
- - - File format not supported. - - -
- )} +
+ + + File format not supported. + + +
+ )} {!isDownloading && !error && compatibleFilesMatcher.match(content_type) && diff --git a/packages/files-ui/src/Contexts/FilesContext.tsx b/packages/files-ui/src/Contexts/FilesContext.tsx index 88c53a15e8..5b11d4e31a 100644 --- a/packages/files-ui/src/Contexts/FilesContext.tsx +++ b/packages/files-ui/src/Contexts/FilesContext.tsx @@ -11,7 +11,7 @@ import { } from "@chainsafe/files-api-client" import React, { useCallback, useEffect } from "react" import { useState } from "react" -import { decryptFile, encryptFile } from "../Utils/encryption" +import { decryptFile, encryptFile } from "../Utils/encryption" import { ToastParams, useToasts } from "@chainsafe/common-components" import axios, { CancelToken } from "axios" import { plural, t } from "@lingui/macro" @@ -159,7 +159,7 @@ const FilesProvider = ({ children }: FilesContextProps) => { let encryptionKey = "" - switch(bucket.type) { + switch (bucket.type) { case "csf": case "trash": { encryptionKey = personalEncryptionKey @@ -168,7 +168,8 @@ const FilesProvider = ({ children }: FilesContextProps) => { case "share": { encryptionKey = await getKeyForSharedBucket(bucket) break - }} + } + } return encryptionKey }, [getKeyForSharedBucket, personalEncryptionKey, userId]) @@ -481,7 +482,7 @@ const FilesProvider = ({ children }: FilesContextProps) => { } } catch (error) { if (axios.isCancel(error)) { - return Promise.reject(error) + return Promise.reject() } else { console.error(error) return Promise.reject(error) @@ -493,7 +494,7 @@ const FilesProvider = ({ children }: FilesContextProps) => { itemsToDownload: FileSystemItem[], currentPath: string, bucketId: string - ): Promise => { + ): Promise => { return await itemsToDownload.reduce( async (acc: Promise, item: FileSystemItem): Promise => { if (item.isFolder) { @@ -566,7 +567,7 @@ const FilesProvider = ({ children }: FilesContextProps) => { } }) - if(file) { + if (file) { const fileArrayBuffer = await file.arrayBuffer() const fullPath = getPathWithFile(item.path, item.name) const relativeFilePath = getRelativePath(fullPath, currentPath) @@ -662,7 +663,7 @@ const FilesProvider = ({ children }: FilesContextProps) => { return Promise.resolve() } catch (error: any) { console.error(error) - let errorMessage = `${t`An error occurred: `} ${typeof(error) === "string" + let errorMessage = `${t`An error occurred: `} ${typeof (error) === "string" ? error : error?.error?.message || ""}` if (axios.isCancel(error)) { @@ -680,7 +681,7 @@ const FilesProvider = ({ children }: FilesContextProps) => { } }, [getFileContent, addToast, updateToast]) - const createSharedFolder = useCallback(async (name: string, writerUsers?: SharedFolderUser[], readerUsers?: SharedFolderUser[]) => { + const createSharedFolder = useCallback(async (name: string, writerUsers?: SharedFolderUser[], readerUsers?: SharedFolderUser[]) => { if (!publicKey) return const bucketEncryptionKey = Buffer.from( @@ -806,7 +807,7 @@ const FilesProvider = ({ children }: FilesContextProps) => { } }) - if(file) { + if (file) { await encryptAndUploadFiles( destinationBucket, [new File([file], item.name, { type: item.content_type })], @@ -841,7 +842,7 @@ const FilesProvider = ({ children }: FilesContextProps) => { ? t`${successCount} files transferred successfully, ${totalFileNumber - successCount} failed` : t`${inSharedBucket ? "Copying" : "Sharing"} failed`, type: successCount ? "success" : "error", - progress: undefined, + progress: undefined, isClosable: true }, true) setTransfersInProgress(false) @@ -855,15 +856,14 @@ const FilesProvider = ({ children }: FilesContextProps) => { : t`${inSharedBucket ? "Copying" : "Sharing"} failed` if (axios.isCancel(error)) { errorMessage = successCount - ? t`${ - inSharedBucket ? "Copying" : "Sharing" - } cancelled - ${successCount} files ${inSharedBucket ? "copied" : "shared"} successfully` + ? t`${inSharedBucket ? "Copying" : "Sharing" + } cancelled - ${successCount} files ${inSharedBucket ? "copied" : "shared"} successfully` : t`${inSharedBucket ? "Copying" : "Sharing"} cancelled` } updateToast(toastId, { title: errorMessage, type: "error", - progress: undefined, + progress: undefined, isClosable: true }, true) } From 6c76bf1c55e39b4f50e915c8c854bc6be6c9f261 Mon Sep 17 00:00:00 2001 From: Michael Yankelev Date: Fri, 12 Nov 2021 18:20:40 +0200 Subject: [PATCH 2/4] ensure download remains active --- .../src/Components/Modules/FileBrowsers/hooks/useGetFile.tsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/files-ui/src/Components/Modules/FileBrowsers/hooks/useGetFile.tsx b/packages/files-ui/src/Components/Modules/FileBrowsers/hooks/useGetFile.tsx index 6bd110f4d4..a553878fd7 100644 --- a/packages/files-ui/src/Components/Modules/FileBrowsers/hooks/useGetFile.tsx +++ b/packages/files-ui/src/Components/Modules/FileBrowsers/hooks/useGetFile.tsx @@ -59,13 +59,13 @@ export const useGetFile = () => { setIsDownloading(false) return content - } catch (error) { + } catch (error) { // If no error is thrown, this was due to a cancellation by the user. if (error) { console.error(error) setError(t`There was an error getting the preview.`) + setIsDownloading(false) } - setIsDownloading(false) } }, [bucket, getFileContent]) From f926f9aaef701327c9dd4181bab8f6a500f62393 Mon Sep 17 00:00:00 2001 From: Michael Yankelev Date: Fri, 12 Nov 2021 18:42:23 +0200 Subject: [PATCH 3/4] remove debugger --- packages/files-ui/src/Components/Modules/FilePreviewModal.tsx | 1 - packages/files-ui/src/Contexts/FilesContext.tsx | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/packages/files-ui/src/Components/Modules/FilePreviewModal.tsx b/packages/files-ui/src/Components/Modules/FilePreviewModal.tsx index 8b964165f4..f1a2335b18 100644 --- a/packages/files-ui/src/Components/Modules/FilePreviewModal.tsx +++ b/packages/files-ui/src/Components/Modules/FilePreviewModal.tsx @@ -217,7 +217,6 @@ const FilePreviewModal = ({ file, nextFile, previousFile, closePreview, filePath setFileContent(undefined) if (previewRendererKey) { - debugger getFile({ file, filePath: getPathWithFile(filePath, file.name), bucketId }) .then((content) => { setFileContent(content) diff --git a/packages/files-ui/src/Contexts/FilesContext.tsx b/packages/files-ui/src/Contexts/FilesContext.tsx index 5b11d4e31a..ba181c525a 100644 --- a/packages/files-ui/src/Contexts/FilesContext.tsx +++ b/packages/files-ui/src/Contexts/FilesContext.tsx @@ -857,7 +857,7 @@ const FilesProvider = ({ children }: FilesContextProps) => { if (axios.isCancel(error)) { errorMessage = successCount ? t`${inSharedBucket ? "Copying" : "Sharing" - } cancelled - ${successCount} files ${inSharedBucket ? "copied" : "shared"} successfully` + } cancelled - ${successCount} files ${inSharedBucket ? "copied" : "shared"} successfully` : t`${inSharedBucket ? "Copying" : "Sharing"} cancelled` } updateToast(toastId, { From 98bb673e3059a216e77cf840670526d89141aa9e Mon Sep 17 00:00:00 2001 From: Michael Yankelev Date: Fri, 12 Nov 2021 18:44:38 +0200 Subject: [PATCH 4/4] lint --- .../Components/Modules/FilePreviewModal.tsx | 42 +++++++++---------- 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/packages/files-ui/src/Components/Modules/FilePreviewModal.tsx b/packages/files-ui/src/Components/Modules/FilePreviewModal.tsx index f1a2335b18..11d77e7ef3 100644 --- a/packages/files-ui/src/Components/Modules/FilePreviewModal.tsx +++ b/packages/files-ui/src/Components/Modules/FilePreviewModal.tsx @@ -369,27 +369,27 @@ const FilePreviewModal = ({ file, nextFile, previousFile, closePreview, filePath {!isDownloading && !error && !compatibleFilesMatcher.match(content_type) && ( -
- - - File format not supported. - - -
- )} +
+ + + File format not supported. + + +
+ )} {!isDownloading && !error && compatibleFilesMatcher.match(content_type) &&