From b44f7fb5e31afc27c8ae268719ac14f8c0c2a2e8 Mon Sep 17 00:00:00 2001 From: Eugene Date: Mon, 5 Aug 2024 14:46:42 +0300 Subject: [PATCH] chore: fixes linting errors and adds comments --- src/pages/sign/MarkFormField.tsx | 4 +--- src/pages/sign/index.tsx | 8 ++------ src/types/mark.ts | 34 -------------------------------- src/utils/index.ts | 2 +- src/utils/mark.ts | 2 +- src/utils/misc.ts | 14 ++----------- src/utils/zip.ts | 8 +++----- 7 files changed, 10 insertions(+), 62 deletions(-) diff --git a/src/pages/sign/MarkFormField.tsx b/src/pages/sign/MarkFormField.tsx index c843045..4de82a4 100644 --- a/src/pages/sign/MarkFormField.tsx +++ b/src/pages/sign/MarkFormField.tsx @@ -1,4 +1,4 @@ -import { CurrentUserMark, Mark } from '../../types/mark.ts' +import { CurrentUserMark } from '../../types/mark.ts' import styles from './style.module.scss' import { Box, Button, TextField } from '@mui/material' @@ -13,8 +13,6 @@ interface MarkFormFieldProps { /** * Responsible for rendering a form field connected to a mark and keeping track of its value. - * @param props - * @constructor */ const MarkFormField = (props: MarkFormFieldProps) => { const { handleSubmit, handleChange, selectedMark, selectedMarkValue } = props; diff --git a/src/pages/sign/index.tsx b/src/pages/sign/index.tsx index 02631dc..e0ef228 100644 --- a/src/pages/sign/index.tsx +++ b/src/pages/sign/index.tsx @@ -337,15 +337,13 @@ export const SignPage = () => { if (!keysFileContent) return null - const parsedJSON = await parseJson<{ sender: string; keys: string[] }>( + return await parseJson<{ sender: string; keys: string[] }>( keysFileContent ).catch((err) => { console.log(`Error parsing content of keys.json:`, err) toast.error(err.message || `Error parsing content of keys.json`) return null }) - - return parsedJSON } const decrypt = async (file: File) => { @@ -603,15 +601,13 @@ export const SignPage = () => { if (!arraybuffer) return null - const finalZipFile = new File( + return new File( [new Blob([arraybuffer])], `${unixNow}.sigit.zip`, { type: 'application/zip' } ) - - return finalZipFile } // Handle errors during zip file generation diff --git a/src/types/mark.ts b/src/types/mark.ts index 5381298..8be57ac 100644 --- a/src/types/mark.ts +++ b/src/types/mark.ts @@ -15,40 +15,6 @@ export interface Mark { value?: string; } -export interface MarkConfig { - /** - * @key user npub - */ - [key: string]: User -} - -export interface User { - /** - * @key png (pdf page) file hash - */ - [key: string]: MarkConfigDetails[] -} - -export interface MarkDetails { - /** - * @key coords in format X:10;Y:50 - */ - [key: string]: MarkValue -} - -export interface MarkValue { - value: string -} - -export interface MarkConfigDetails { - type: MarkType; - /** - * Coordinates in format: X:10;Y:50 - */ - location: MarkLocation; - value?: MarkValue -} - export interface MarkLocation { top: number; left: number; diff --git a/src/utils/index.ts b/src/utils/index.ts index f65fb79..1b0c133 100644 --- a/src/utils/index.ts +++ b/src/utils/index.ts @@ -6,4 +6,4 @@ export * from './nostr' export * from './string' export * from './zip' export * from './utils' -export { extractMarksFromSignedMeta } from './mark.ts' +export * from './mark' diff --git a/src/utils/mark.ts b/src/utils/mark.ts index 59860ce..13cff84 100644 --- a/src/utils/mark.ts +++ b/src/utils/mark.ts @@ -85,7 +85,7 @@ const updateCurrentUserMarks = (currentUserMarks: CurrentUserMark[], markToUpdat ] } -const isLast = (index: number, arr: any[]) => (index === (arr.length -1)) +const isLast = (index: number, arr: T[]) => (index === (arr.length -1)) export { getCurrentUserMarks, diff --git a/src/utils/misc.ts b/src/utils/misc.ts index e6f5058..728408c 100644 --- a/src/utils/misc.ts +++ b/src/utils/misc.ts @@ -12,11 +12,10 @@ import { toast } from 'react-toastify' import { NostrController } from '../controllers' import { AuthState } from '../store/auth/types' import store from '../store/store' -import { CreateSignatureEventContent, Meta, SignedEventContent } from '../types' +import { CreateSignatureEventContent, Meta } from '../types' import { hexToNpub, now } from './nostr' import { parseJson } from './string' import { hexToBytes } from '@noble/hashes/utils' -import { Mark } from '../types/mark.ts' /** * Uploads a file to a file storage service. @@ -84,14 +83,12 @@ export const signEventForMetaFile = async ( } // Sign the event - const signedEvent = await nostrController.signEvent(event).catch((err) => { + return await nostrController.signEvent(event).catch((err) => { console.error(err) toast.error(err.message || 'Error occurred in signing nostr event') setIsLoading(false) // Set loading state to false return null }) - - return signedEvent // Return the signed event } /** @@ -265,10 +262,3 @@ export const extractZipUrlAndEncryptionKey = async (meta: Meta) => { return null } - -export const extractMarksFromSignedMeta = (meta: Meta): Mark[] => { - return Object.values(meta.docSignatures) - .map((val: string) => JSON.parse(val as string)) - .map((val: Event) => JSON.parse(val.content)) - .flatMap((val: SignedEventContent) => val.marks); -} diff --git a/src/utils/zip.ts b/src/utils/zip.ts index c289cbe..2d33aa5 100644 --- a/src/utils/zip.ts +++ b/src/utils/zip.ts @@ -22,8 +22,9 @@ const readContentOfZipEntry = async ( return null } - // Read the content of the zip entry asynchronously - const fileContent = await zipEntry.async(outputType).catch((err) => { + // Read and return the content of the zip entry asynchronously + // or null if an error has occurred + return await zipEntry.async(outputType).catch((err) => { // Handle any errors that occur during the read operation console.log(`Error reading content of ${filePath}:`, err) toast.error( @@ -31,9 +32,6 @@ const readContentOfZipEntry = async ( ) return null }) - - // Return the file content or null if an error occurred - return fileContent } const loadZip = async (data: InputFileFormat): Promise => {