diff --git a/src/components/DrawPDFFields/index.tsx b/src/components/DrawPDFFields/index.tsx index 076c6fb..543edf9 100644 --- a/src/components/DrawPDFFields/index.tsx +++ b/src/components/DrawPDFFields/index.tsx @@ -9,8 +9,16 @@ import { } from '@mui/material' import styles from './style.module.scss' import React, { useEffect, useState } from 'react' -import { ProfileMetadata, User, UserRole } from '../../types' -import { MouseState, PdfPage, DrawnField, DrawTool } from '../../types/drawing' +import { + ProfileMetadata, + User, + UserRole, + KeyboardCode, + MouseState, + PdfPage, + DrawnField, + DrawTool +} from '../../types' import { hexToNpub, npubToHex, getProfileUsername } from '../../utils' import { SigitFile } from '../../utils/file' import { getToolboxLabelByMarkType } from '../../utils/mark' @@ -41,6 +49,10 @@ export const DrawPDFFields = (props: Props) => { const signers = users.filter((u) => u.role === UserRole.signer) const defaultSignerNpub = signers.length ? hexToNpub(signers[0].pubkey) : '' const [lastSigner, setLastSigner] = useState(defaultSignerNpub) + const [hideSignersForDrawnField, setHideSignersForDrawnField] = useState<{ + [key: number]: boolean + } | null>() + /** * Return first pubkey that is present in the signers list * @param pubkeys @@ -361,6 +373,7 @@ export const DrawPDFFields = (props: Props) => { rect } } + /** * Renders the pdf pages and drawing elements */ @@ -492,62 +505,90 @@ export const DrawPDFFields = (props: Props) => { fileIndex, pageIndex, drawnFieldIndex - ) && ( -
- - Counterpart - { + drawnField.counterpart = event.target.value + setLastSigner(event.target.value) + refreshPdfFiles() + }} + labelId="counterparts" + label="Counterparts" + sx={{ + background: 'white' + }} + renderValue={(value) => + renderCounterpartValue(value) + } + onClose={(event: React.SyntheticEvent) => { + // get native event + const { nativeEvent } = event - return ( - - - img': { - width: '30px', - height: '30px' - } - }} - /> - - {displayValue} - - ) - })} - - -
- )} + // check if event is a keyboard event + if (nativeEvent instanceof KeyboardEvent) { + // check if event code is Escape + if ( + nativeEvent.code === KeyboardCode.Escape + ) { + // set hide signers for this DrawnField + if (hideSignersForDrawnField) { + setHideSignersForDrawnField((prev) => ({ + ...prev, + [drawnFieldIndex]: true + })) + } else { + setHideSignersForDrawnField({ + [drawnFieldIndex]: true + }) + } + } + } + }} + > + {signers.map((signer, index) => { + const npub = hexToNpub(signer.pubkey) + const metadata = props.metadata[signer.pubkey] + const displayValue = getProfileUsername( + npub, + metadata + ) + + return ( + + + img': { + width: '30px', + height: '30px' + } + }} + /> + + {displayValue} + + ) + })} + + + + )} ) })} diff --git a/src/components/MarkFormField/index.tsx b/src/components/MarkFormField/index.tsx index 9a14989..68e05e1 100644 --- a/src/components/MarkFormField/index.tsx +++ b/src/components/MarkFormField/index.tsx @@ -1,4 +1,4 @@ -import { CurrentUserMark } from '../../types/mark.ts' +import { CurrentUserMark } from '../../types' import styles from './style.module.scss' import { findNextIncompleteCurrentUserMark, diff --git a/src/components/PDFView/PdfItem.tsx b/src/components/PDFView/PdfItem.tsx index f1dbe87..efffe20 100644 --- a/src/components/PDFView/PdfItem.tsx +++ b/src/components/PDFView/PdfItem.tsx @@ -1,4 +1,4 @@ -import { CurrentUserMark, Mark } from '../../types/mark.ts' +import { CurrentUserMark, Mark } from '../../types' import { SigitFile } from '../../utils/file.ts' import { ExtensionFileBox } from '../ExtensionFileBox.tsx' import PdfPageItem from './PdfPageItem.tsx' diff --git a/src/components/PDFView/PdfMarkItem.tsx b/src/components/PDFView/PdfMarkItem.tsx index cb06455..39c238c 100644 --- a/src/components/PDFView/PdfMarkItem.tsx +++ b/src/components/PDFView/PdfMarkItem.tsx @@ -1,4 +1,4 @@ -import { CurrentUserMark } from '../../types/mark.ts' +import { CurrentUserMark } from '../../types' import styles from '../DrawPDFFields/style.module.scss' import { FONT_SIZE, FONT_TYPE, inPx } from '../../utils/pdf.ts' import { useScale } from '../../hooks/useScale.tsx' diff --git a/src/components/PDFView/PdfMarking.tsx b/src/components/PDFView/PdfMarking.tsx index 61968b0..b6d4eec 100644 --- a/src/components/PDFView/PdfMarking.tsx +++ b/src/components/PDFView/PdfMarking.tsx @@ -1,6 +1,6 @@ import PdfView from './index.tsx' import MarkFormField from '../MarkFormField' -import { CurrentUserMark, Mark } from '../../types/mark.ts' +import { CurrentUserMark, Mark, CurrentUserFile, Meta } from '../../types' import React, { useState, useEffect } from 'react' import { findNextIncompleteCurrentUserMark, @@ -10,11 +10,9 @@ import { import { EMPTY } from '../../utils/const.ts' import { Container } from '../Container' import signPageStyles from '../../pages/sign/style.module.scss' -import { CurrentUserFile } from '../../types/file.ts' import FileList from '../FileList' import { StickySideColumns } from '../../layouts/StickySideColumns.tsx' import { UsersDetails } from '../UsersDetails.tsx' -import { Meta } from '../../types' import { faCircleInfo, faFileDownload, diff --git a/src/components/PDFView/PdfPageItem.tsx b/src/components/PDFView/PdfPageItem.tsx index 5d4be7d..9534574 100644 --- a/src/components/PDFView/PdfPageItem.tsx +++ b/src/components/PDFView/PdfPageItem.tsx @@ -1,6 +1,5 @@ import styles from '../DrawPDFFields/style.module.scss' -import { PdfPage } from '../../types/drawing.ts' -import { CurrentUserMark, Mark } from '../../types/mark.ts' +import { PdfPage, CurrentUserMark, Mark } from '../../types' import PdfMarkItem from './PdfMarkItem.tsx' import { useEffect, useRef } from 'react' import pdfViewStyles from './style.module.scss' diff --git a/src/components/PDFView/index.tsx b/src/components/PDFView/index.tsx index acd1874..70efd0c 100644 --- a/src/components/PDFView/index.tsx +++ b/src/components/PDFView/index.tsx @@ -1,6 +1,5 @@ import PdfItem from './PdfItem.tsx' -import { CurrentUserMark, Mark } from '../../types/mark.ts' -import { CurrentUserFile } from '../../types/file.ts' +import { CurrentUserMark, Mark, CurrentUserFile } from '../../types' import { useEffect, useRef } from 'react' import { FileDivider } from '../FileDivider.tsx' import React from 'react' diff --git a/src/hooks/useProfileMetadata.tsx b/src/hooks/useProfileMetadata.tsx index f746f0d..621a296 100644 --- a/src/hooks/useProfileMetadata.tsx +++ b/src/hooks/useProfileMetadata.tsx @@ -1,5 +1,5 @@ import { useEffect, useState } from 'react' -import { ProfileMetadata } from '../types/profile' +import { ProfileMetadata } from '../types' import { MetadataController } from '../controllers/MetadataController' import { Event, kinds } from 'nostr-tools' diff --git a/src/hooks/useSigitMeta.tsx b/src/hooks/useSigitMeta.tsx index c794496..9399afa 100644 --- a/src/hooks/useSigitMeta.tsx +++ b/src/hooks/useSigitMeta.tsx @@ -3,9 +3,10 @@ import { CreateSignatureEventContent, DocSignatureEvent, Meta, - SignedEventContent + SignedEventContent, + Mark, + MetaParseError } from '../types' -import { Mark } from '../types/mark' import { fromUnixTimestamp, hexToNpub, @@ -19,7 +20,6 @@ import { verifyEvent } from 'nostr-tools' import { Event } from 'nostr-tools' import store from '../store/store' import { NostrController } from '../controllers' -import { MetaParseError } from '../types/errors/MetaParseError' /** * Flattened interface that combines properties `Meta`, `CreateSignatureEventContent`, diff --git a/src/pages/create/index.tsx b/src/pages/create/index.tsx index 3374a08..896a47e 100644 --- a/src/pages/create/index.tsx +++ b/src/pages/create/index.tsx @@ -20,7 +20,9 @@ import { Meta, ProfileMetadata, User, - UserRole + UserRole, + DrawTool, + Mark } from '../../types' import { encryptArrayBuffer, @@ -43,9 +45,7 @@ import { } from '../../utils' import { Container } from '../../components/Container' import fileListStyles from '../../components/FileList/style.module.scss' -import { DrawTool } from '../../types/drawing' import { DrawPDFFields } from '../../components/DrawPDFFields' -import { Mark } from '../../types/mark.ts' import { StickySideColumns } from '../../layouts/StickySideColumns.tsx' import { FontAwesomeIcon } from '@fortawesome/react-fontawesome' import { diff --git a/src/pages/sign/index.tsx b/src/pages/sign/index.tsx index dd31938..388a21a 100644 --- a/src/pages/sign/index.tsx +++ b/src/pages/sign/index.tsx @@ -12,7 +12,13 @@ import { toast } from 'react-toastify' import { LoadingSpinner } from '../../components/LoadingSpinner' import { NostrController } from '../../controllers' import { appPublicRoutes } from '../../routes' -import { CreateSignatureEventContent, Meta, SignedEvent } from '../../types' +import { + CreateSignatureEventContent, + Meta, + SignedEvent, + CurrentUserMark, + Mark +} from '../../types' import { decryptArrayBuffer, encryptArrayBuffer, @@ -38,7 +44,6 @@ import { import { Container } from '../../components/Container' import { DisplayMeta } from './internal/displayMeta' import styles from './style.module.scss' -import { CurrentUserMark, Mark } from '../../types/mark.ts' import { getLastSignersSig, isFullySigned } from '../../utils/sign.ts' import { filterMarksByPubkey, diff --git a/src/pages/verify/index.tsx b/src/pages/verify/index.tsx index 000341e..510e14c 100644 --- a/src/pages/verify/index.tsx +++ b/src/pages/verify/index.tsx @@ -5,7 +5,7 @@ import { useEffect, useRef, useState } from 'react' import { toast } from 'react-toastify' import { LoadingSpinner } from '../../components/LoadingSpinner' import { NostrController } from '../../controllers' -import { DocSignatureEvent, Meta } from '../../types' +import { DocSignatureEvent, Meta, CurrentUserFile, Mark } from '../../types' import { decryptArrayBuffer, getHash, @@ -28,8 +28,6 @@ import { useSigitMeta } from '../../hooks/useSigitMeta.tsx' import { StickySideColumns } from '../../layouts/StickySideColumns.tsx' import { UsersDetails } from '../../components/UsersDetails.tsx/index.tsx' import FileList from '../../components/FileList' -import { CurrentUserFile } from '../../types/file.ts' -import { Mark } from '../../types/mark.ts' import React from 'react' import { convertToSigitFile, diff --git a/src/services/LoginMethodStrategy/loginMethodStrategy.ts b/src/services/LoginMethodStrategy/loginMethodStrategy.ts index 35830bc..14427bc 100644 --- a/src/services/LoginMethodStrategy/loginMethodStrategy.ts +++ b/src/services/LoginMethodStrategy/loginMethodStrategy.ts @@ -1,6 +1,6 @@ /* eslint-disable @typescript-eslint/no-unused-vars */ import { EventTemplate, UnsignedEvent } from 'nostr-tools' -import { SignedEvent } from '../../types/nostr' +import { SignedEvent } from '../../types' /** * This interface holds all operations that are dependant on the login method and is used as the basis for the login strategies. diff --git a/src/types/errors/index.ts b/src/types/errors/index.ts index 6ef8990..3f60e09 100644 --- a/src/types/errors/index.ts +++ b/src/types/errors/index.ts @@ -27,3 +27,7 @@ export function handleError(error: unknown): Error { return new Error(`Wrapped Error: ${stringified}`) } + +export * from './DecryptionError' +export * from './MetaParseError' +export * from './TimeoutError' diff --git a/src/types/event.ts b/src/types/event.ts new file mode 100644 index 0000000..f325e79 --- /dev/null +++ b/src/types/event.ts @@ -0,0 +1,4 @@ +export enum KeyboardCode { + Escape = 'Escape', + Enter = 'Enter' +} diff --git a/src/types/index.ts b/src/types/index.ts index 6c9f259..c218f3c 100644 --- a/src/types/index.ts +++ b/src/types/index.ts @@ -4,3 +4,8 @@ export * from './nostr' export * from './profile' export * from './relay' export * from './zip' +export * from './event' +export * from './drawing' +export * from './file' +export * from './mark' +export * from './errors' diff --git a/src/utils/crypto.ts b/src/utils/crypto.ts index d66423f..d83c382 100644 --- a/src/utils/crypto.ts +++ b/src/utils/crypto.ts @@ -4,7 +4,7 @@ import { stringToHex, uint8ArrayToHexString } from '.' -import { DecryptionError } from '../types/errors/DecryptionError' +import { DecryptionError } from '../types' const ENCRYPTION_ALGO_NAME = 'AES-GCM' diff --git a/src/utils/file.ts b/src/utils/file.ts index c08d5e7..8a99e47 100644 --- a/src/utils/file.ts +++ b/src/utils/file.ts @@ -1,5 +1,5 @@ import { Meta } from '../types' -import { PdfPage } from '../types/drawing.ts' +import { PdfPage } from '../types' import { MOST_COMMON_MEDIA_TYPES } from './const.ts' import { extractMarksFromSignedMeta } from './mark.ts' import { diff --git a/src/utils/mark.ts b/src/utils/mark.ts index b77818a..f16ad10 100644 --- a/src/utils/mark.ts +++ b/src/utils/mark.ts @@ -1,9 +1,14 @@ -import { CurrentUserMark, Mark } from '../types/mark.ts' +import { + CurrentUserMark, + Mark, + Meta, + SignedEventContent, + DrawTool, + MarkType +} from '../types' import { hexToNpub } from './nostr.ts' -import { Meta, SignedEventContent } from '../types' import { Event } from 'nostr-tools' import { EMPTY } from './const.ts' -import { DrawTool, MarkType } from '../types/drawing.ts' import { faT, faSignature, diff --git a/src/utils/meta.ts b/src/utils/meta.ts index c915f66..8af7672 100644 --- a/src/utils/meta.ts +++ b/src/utils/meta.ts @@ -1,13 +1,14 @@ -import { CreateSignatureEventContent, Meta } from '../types' +import { + CreateSignatureEventContent, + Meta, + MetaParseError, + MetaParseErrorType, + handleError +} from '../types' import { fromUnixTimestamp, parseJson } from '.' import { Event, verifyEvent } from 'nostr-tools' import { toast } from 'react-toastify' import { extractFileExtensions } from './file' -import { handleError } from '../types/errors' -import { - MetaParseError, - MetaParseErrorType -} from '../types/errors/MetaParseError' export enum SignStatus { Signed = 'Signed', diff --git a/src/utils/pdf.ts b/src/utils/pdf.ts index c3e381d..ee3cf19 100644 --- a/src/utils/pdf.ts +++ b/src/utils/pdf.ts @@ -1,6 +1,5 @@ -import { PdfPage } from '../types/drawing.ts' +import { PdfPage, Mark } from '../types' import { PDFDocument, PDFFont, PDFPage, rgb } from 'pdf-lib' -import { Mark } from '../types/mark.ts' import * as PDFJS from 'pdfjs-dist' import PDFJSWorker from 'pdfjs-dist/build/pdf.worker.min.mjs?worker' if (!PDFJS.GlobalWorkerOptions.workerPort) { diff --git a/src/utils/utils.ts b/src/utils/utils.ts index 11053b9..040c952 100644 --- a/src/utils/utils.ts +++ b/src/utils/utils.ts @@ -1,5 +1,4 @@ -import { TimeoutError } from '../types/errors/TimeoutError.ts' -import { CurrentUserFile } from '../types/file.ts' +import { TimeoutError, CurrentUserFile } from '../types' import { SigitFile } from './file.ts' export const compareObjects = (