chore: fixes linting errors and adds comments

This commit is contained in:
eugene 2024-08-05 14:46:42 +03:00
parent c9c874ae98
commit b44f7fb5e3
7 changed files with 10 additions and 62 deletions

View File

@ -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;

View File

@ -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

View File

@ -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;

View File

@ -6,4 +6,4 @@ export * from './nostr'
export * from './string'
export * from './zip'
export * from './utils'
export { extractMarksFromSignedMeta } from './mark.ts'
export * from './mark'

View File

@ -85,7 +85,7 @@ const updateCurrentUserMarks = (currentUserMarks: CurrentUserMark[], markToUpdat
]
}
const isLast = (index: number, arr: any[]) => (index === (arr.length -1))
const isLast = <T>(index: number, arr: T[]) => (index === (arr.length -1))
export {
getCurrentUserMarks,

View File

@ -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);
}

View File

@ -22,8 +22,9 @@ const readContentOfZipEntry = async <T extends OutputType>(
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 <T extends OutputType>(
)
return null
})
// Return the file content or null if an error occurred
return fileContent
}
const loadZip = async (data: InputFileFormat): Promise<JSZip | null> => {