issue-236-fixed #239
@ -9,7 +9,7 @@ import {
|
|||||||
} from '@mui/material'
|
} from '@mui/material'
|
||||||
import styles from './style.module.scss'
|
import styles from './style.module.scss'
|
||||||
import React, { useEffect, useState } from 'react'
|
import React, { useEffect, useState } from 'react'
|
||||||
import { ProfileMetadata, User, UserRole } from '../../types'
|
import { ProfileMetadata, User, UserRole, KeyboardCode } from '../../types'
|
||||||
import { MouseState, PdfPage, DrawnField, DrawTool } from '../../types/drawing'
|
import { MouseState, PdfPage, DrawnField, DrawTool } from '../../types/drawing'
|
||||||
import { hexToNpub, npubToHex, getProfileUsername } from '../../utils'
|
import { hexToNpub, npubToHex, getProfileUsername } from '../../utils'
|
||||||
import { SigitFile } from '../../utils/file'
|
import { SigitFile } from '../../utils/file'
|
||||||
@ -41,6 +41,10 @@ export const DrawPDFFields = (props: Props) => {
|
|||||||
const signers = users.filter((u) => u.role === UserRole.signer)
|
const signers = users.filter((u) => u.role === UserRole.signer)
|
||||||
const defaultSignerNpub = signers.length ? hexToNpub(signers[0].pubkey) : ''
|
const defaultSignerNpub = signers.length ? hexToNpub(signers[0].pubkey) : ''
|
||||||
const [lastSigner, setLastSigner] = useState(defaultSignerNpub)
|
const [lastSigner, setLastSigner] = useState(defaultSignerNpub)
|
||||||
|
const [hideSignersForDrawnField, setHideSignersForDrawnField] = useState<{
|
||||||
|
[key: number]: boolean
|
||||||
|
} | null>()
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return first pubkey that is present in the signers list
|
* Return first pubkey that is present in the signers list
|
||||||
* @param pubkeys
|
* @param pubkeys
|
||||||
@ -361,6 +365,7 @@ export const DrawPDFFields = (props: Props) => {
|
|||||||
rect
|
rect
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Renders the pdf pages and drawing elements
|
* Renders the pdf pages and drawing elements
|
||||||
*/
|
*/
|
||||||
@ -492,13 +497,17 @@ export const DrawPDFFields = (props: Props) => {
|
|||||||
fileIndex,
|
fileIndex,
|
||||||
pageIndex,
|
pageIndex,
|
||||||
drawnFieldIndex
|
drawnFieldIndex
|
||||||
) && (
|
) &&
|
||||||
|
(!hideSignersForDrawnField ||
|
||||||
|
!hideSignersForDrawnField[drawnFieldIndex]) && (
|
||||||
<div
|
<div
|
||||||
onPointerDown={handleUserSelectPointerDown}
|
onPointerDown={handleUserSelectPointerDown}
|
||||||
className={styles.userSelect}
|
className={styles.userSelect}
|
||||||
>
|
>
|
||||||
<FormControl fullWidth size="small">
|
<FormControl fullWidth size="small">
|
||||||
<InputLabel id="counterparts">Counterpart</InputLabel>
|
<InputLabel id="counterparts">
|
||||||
|
Counterpart
|
||||||
|
</InputLabel>
|
||||||
<Select
|
<Select
|
||||||
value={getAvailableSigner(drawnField.counterpart)}
|
value={getAvailableSigner(drawnField.counterpart)}
|
||||||
onChange={(event) => {
|
onChange={(event) => {
|
||||||
@ -514,6 +523,30 @@ export const DrawPDFFields = (props: Props) => {
|
|||||||
renderValue={(value) =>
|
renderValue={(value) =>
|
||||||
renderCounterpartValue(value)
|
renderCounterpartValue(value)
|
||||||
}
|
}
|
||||||
|
onClose={(event: React.SyntheticEvent) => {
|
||||||
|
// get native event
|
||||||
|
const { nativeEvent } = event
|
||||||
|
|
||||||
|
// 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) => {
|
{signers.map((signer, index) => {
|
||||||
const npub = hexToNpub(signer.pubkey)
|
const npub = hexToNpub(signer.pubkey)
|
||||||
|
5
src/types/event.ts
Normal file
5
src/types/event.ts
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
export enum KeyboardCode {
|
||||||
|
Escape = 'Escape',
|
||||||
|
Enter = 'Enter',
|
||||||
|
NumpadEnter = 'NumpadEnter'
|
||||||
|
}
|
@ -4,3 +4,4 @@ export * from './nostr'
|
|||||||
export * from './profile'
|
export * from './profile'
|
||||||
export * from './relay'
|
export * from './relay'
|
||||||
export * from './zip'
|
export * from './zip'
|
||||||
|
export * from './event'
|
||||||
|
Loading…
Reference in New Issue
Block a user