From 738a6b87f56758e8673d55d0529e34362f3254ac Mon Sep 17 00:00:00 2001 From: enes Date: Thu, 8 Aug 2024 12:37:47 +0200 Subject: [PATCH 1/5] refactor(pdf): use minified and remove unnecessary vite config --- src/components/DrawPDFFields/index.tsx | 2 +- src/utils/pdf.ts | 2 +- vite.config.ts | 11 +---------- 3 files changed, 3 insertions(+), 12 deletions(-) diff --git a/src/components/DrawPDFFields/index.tsx b/src/components/DrawPDFFields/index.tsx index 63eb9ee..e98187c 100644 --- a/src/components/DrawPDFFields/index.tsx +++ b/src/components/DrawPDFFields/index.tsx @@ -37,7 +37,7 @@ import { truncate } from 'lodash' import { hexToNpub } from '../../utils' import { toPdfFiles } from '../../utils/pdf.ts' PDFJS.GlobalWorkerOptions.workerSrc = new URL( - 'pdfjs-dist/build/pdf.worker.mjs', + 'pdfjs-dist/build/pdf.worker.min.mjs', import.meta.url ).toString() diff --git a/src/utils/pdf.ts b/src/utils/pdf.ts index 78bab85..28bbfde 100644 --- a/src/utils/pdf.ts +++ b/src/utils/pdf.ts @@ -4,7 +4,7 @@ import { PDFDocument } from 'pdf-lib' import { Mark } from '../types/mark.ts' PDFJS.GlobalWorkerOptions.workerSrc = new URL( - 'pdfjs-dist/build/pdf.worker.mjs', + 'pdfjs-dist/build/pdf.worker.min.mjs', import.meta.url ).toString() diff --git a/vite.config.ts b/vite.config.ts index 4275495..3d09617 100644 --- a/vite.config.ts +++ b/vite.config.ts @@ -5,15 +5,6 @@ import tsconfigPaths from 'vite-tsconfig-paths' export default defineConfig({ plugins: [react(), tsconfigPaths()], build: { - target: 'ES2022', - rollupOptions: { - output: { - manualChunks(id) { - if (id.includes('pdfjs-dist/build/pdf.worker.mjs')) { - return 'pdf.worker' - } - } - } - } + target: 'ES2022' } }) -- 2.34.1 From 7b5a12246d792672734747ca33ff77cfc05c0537 Mon Sep 17 00:00:00 2001 From: enes Date: Thu, 8 Aug 2024 12:41:39 +0200 Subject: [PATCH 2/5] fix(git-hooks): add executable flag --- .git-hooks/commit-msg | 0 .git-hooks/pre-commit | 0 2 files changed, 0 insertions(+), 0 deletions(-) mode change 100644 => 100755 .git-hooks/commit-msg mode change 100644 => 100755 .git-hooks/pre-commit diff --git a/.git-hooks/commit-msg b/.git-hooks/commit-msg old mode 100644 new mode 100755 diff --git a/.git-hooks/pre-commit b/.git-hooks/pre-commit old mode 100644 new mode 100755 -- 2.34.1 From 5015cefe98c212dbe4df81ae08602b051022ca52 Mon Sep 17 00:00:00 2001 From: enes Date: Thu, 8 Aug 2024 12:43:49 +0200 Subject: [PATCH 3/5] refactor: update loading description --- src/layouts/Main.tsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/layouts/Main.tsx b/src/layouts/Main.tsx index c8f9f27..51c2086 100644 --- a/src/layouts/Main.tsx +++ b/src/layouts/Main.tsx @@ -136,7 +136,7 @@ export const MainLayout = () => { } setIsLoading(true) - setLoadingSpinnerDesc(`Loading SIGit History`) + setLoadingSpinnerDesc(`Loading SIGit history...`) getUsersAppData() .then((appData) => { if (appData) { @@ -145,7 +145,7 @@ export const MainLayout = () => { }) .finally(() => setIsLoading(false)) } - }, [authState]) + }, [authState, dispatch]) if (isLoading) return -- 2.34.1 From 748cb16f9fe44f8fc06ac6142cdd01c348bc7c1c Mon Sep 17 00:00:00 2001 From: enes Date: Thu, 8 Aug 2024 12:49:55 +0200 Subject: [PATCH 4/5] fix: loading spinner states, timestamp the file, and lint fixes --- src/pages/create/index.tsx | 42 ++++++++++++++++++++++++-------------- 1 file changed, 27 insertions(+), 15 deletions(-) diff --git a/src/pages/create/index.tsx b/src/pages/create/index.tsx index 023dd02..e34b06d 100644 --- a/src/pages/create/index.tsx +++ b/src/pages/create/index.tsx @@ -24,7 +24,7 @@ import JSZip from 'jszip' import { MuiFileInput } from 'mui-file-input' import { Event, kinds } from 'nostr-tools' import { useEffect, useRef, useState } from 'react' -import { DndProvider, useDrag, useDrop } from 'react-dnd' +import { DndProvider, DragSourceMonitor, useDrag, useDrop } from 'react-dnd' import { HTML5Backend } from 'react-dnd-html5-backend' import { useSelector } from 'react-redux' import { useLocation, useNavigate } from 'react-router-dom' @@ -127,7 +127,7 @@ export const CreatePage = () => { }) } }) - }, []) + }, [metadata, users]) // Set up event listener for authentication event nostrController.on('nsecbunker-auth', (url) => { setAuthUrl(url) @@ -309,14 +309,16 @@ export const CreatePage = () => { } // Handle errors during file arrayBuffer conversion - const handleFileError = (file: File) => (err: any) => { + const handleFileError = (file: File) => (err: unknown) => { console.log( `Error while getting arrayBuffer of file ${file.name} :>> `, err ) - toast.error( - err.message || `Error while getting arrayBuffer of file ${file.name}` - ) + if (err instanceof Error) { + toast.error( + err.message || `Error while getting arrayBuffer of file ${file.name}` + ) + } return null } @@ -368,10 +370,12 @@ export const CreatePage = () => { } // Handle errors during zip file generation - const handleZipError = (err: any) => { + const handleZipError = (err: unknown) => { console.log('Error in zip:>> ', err) setIsLoading(false) - toast.error(err.message || 'Error occurred in generating zip file') + if (err instanceof Error) { + toast.error(err.message || 'Error occurred in generating zip file') + } return null } @@ -438,10 +442,12 @@ export const CreatePage = () => { } // Handle errors during file upload - const handleUploadError = (err: any) => { + const handleUploadError = (err: unknown) => { console.log('Error in upload:>> ', err) setIsLoading(false) - toast.error(err.message || 'Error occurred in uploading file') + if (err instanceof Error) { + toast.error(err.message || 'Error occurred in uploading file') + } return null } @@ -474,9 +480,13 @@ export const CreatePage = () => { encryptionKey ) - if (!finalZipFile) return + if (!finalZipFile) { + setIsLoading(false) + return + } - saveAs(finalZipFile, 'request.sigit.zip') + saveAs(finalZipFile, `request-${now()}.sigit.zip`) + setIsLoading(false) } const generateFilesZip = async (): Promise => { @@ -659,9 +669,11 @@ export const CreatePage = () => { } const arrayBuffer = await generateZipFile(zip) - if (!arrayBuffer) return + if (!arrayBuffer) { + setIsLoading(false) + return + } - setLoadingSpinnerDesc('Encrypting zip file') const encryptedArrayBuffer = await encryptZipFile( arrayBuffer, encryptionKey @@ -967,7 +979,7 @@ const SignerRow = ({ item: () => { return { id: user.pubkey, index } }, - collect: (monitor: any) => ({ + collect: (monitor: DragSourceMonitor) => ({ isDragging: monitor.isDragging() }) }) -- 2.34.1 From 691f060ca048e3313743c62a3ae0b339a6964e2d Mon Sep 17 00:00:00 2001 From: enes Date: Thu, 8 Aug 2024 13:02:59 +0200 Subject: [PATCH 5/5] ci: reduce warning limit --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 6a8af40..976298b 100644 --- a/package.json +++ b/package.json @@ -7,7 +7,7 @@ "scripts": { "dev": "vite", "build": "tsc && vite build", - "lint": "eslint . --ext ts,tsx --report-unused-disable-directives --max-warnings 41", + "lint": "eslint . --ext ts,tsx --report-unused-disable-directives --max-warnings 32", "lint:fix": "eslint . --fix --ext ts,tsx --report-unused-disable-directives --max-warnings 0", "lint:staged": "eslint --fix --ext ts,tsx --report-unused-disable-directives --max-warnings 0", "formatter:check": "prettier --check \"src/**/*.{ts,tsx,js,jsx,html,css,sass,less,yml,md,graphql}\"", -- 2.34.1