Compare commits

..

No commits in common. "3a94fbc0ae3789252e4ff2b08f5f10d89042be14" and "cc059f6cb401069b26391f18d4938ad9ef9bbf6d" have entirely different histories.

5 changed files with 59 additions and 106 deletions

View File

@ -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, KeyboardCode } from '../../types' import { ProfileMetadata, User, UserRole } 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,10 +41,6 @@ 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
@ -365,7 +361,6 @@ export const DrawPDFFields = (props: Props) => {
rect rect
} }
} }
/** /**
* Renders the pdf pages and drawing elements * Renders the pdf pages and drawing elements
*/ */
@ -497,90 +492,62 @@ export const DrawPDFFields = (props: Props) => {
fileIndex, fileIndex,
pageIndex, pageIndex,
drawnFieldIndex drawnFieldIndex
) && ) && (
(!hideSignersForDrawnField || <div
!hideSignersForDrawnField[drawnFieldIndex]) && ( onPointerDown={handleUserSelectPointerDown}
<div className={styles.userSelect}
onPointerDown={handleUserSelectPointerDown} >
className={styles.userSelect} <FormControl fullWidth size="small">
> <InputLabel id="counterparts">Counterpart</InputLabel>
<FormControl fullWidth size="small"> <Select
<InputLabel id="counterparts"> value={getAvailableSigner(drawnField.counterpart)}
Counterpart onChange={(event) => {
</InputLabel> drawnField.counterpart = event.target.value
<Select setLastSigner(event.target.value)
value={getAvailableSigner(drawnField.counterpart)} refreshPdfFiles()
onChange={(event) => { }}
drawnField.counterpart = event.target.value labelId="counterparts"
setLastSigner(event.target.value) label="Counterparts"
refreshPdfFiles() sx={{
}} background: 'white'
labelId="counterparts" }}
label="Counterparts" renderValue={(value) =>
sx={{ renderCounterpartValue(value)
background: 'white' }
}} >
renderValue={(value) => {signers.map((signer, index) => {
renderCounterpartValue(value) const npub = hexToNpub(signer.pubkey)
} const metadata = props.metadata[signer.pubkey]
onClose={(event: React.SyntheticEvent) => { const displayValue = getProfileUsername(
// get native event npub,
const { nativeEvent } = event metadata
)
// check if event is a keyboard event return (
if (nativeEvent instanceof KeyboardEvent) { <MenuItem key={index} value={npub}>
// check if event code is Escape <ListItemIcon>
if ( <AvatarIconButton
nativeEvent.code === KeyboardCode.Escape src={metadata?.picture}
) { hexKey={signer.pubkey}
// set hide signers for this DrawnField aria-label={`account of user ${displayValue}`}
if (hideSignersForDrawnField) { color="inherit"
setHideSignersForDrawnField((prev) => ({ sx={{
...prev, padding: 0,
[drawnFieldIndex]: true '> img': {
})) width: '30px',
} else { height: '30px'
setHideSignersForDrawnField({ }
[drawnFieldIndex]: true }}
}) />
} </ListItemIcon>
} <ListItemText>{displayValue}</ListItemText>
} </MenuItem>
}} )
> })}
{signers.map((signer, index) => { </Select>
const npub = hexToNpub(signer.pubkey) </FormControl>
const metadata = props.metadata[signer.pubkey] </div>
const displayValue = getProfileUsername( )}
npub,
metadata
)
return (
<MenuItem key={index} value={npub}>
<ListItemIcon>
<AvatarIconButton
src={metadata?.picture}
hexKey={signer.pubkey}
aria-label={`account of user ${displayValue}`}
color="inherit"
sx={{
padding: 0,
'> img': {
width: '30px',
height: '30px'
}
}}
/>
</ListItemIcon>
<ListItemText>{displayValue}</ListItemText>
</MenuItem>
)
})}
</Select>
</FormControl>
</div>
)}
</div> </div>
) )
})} })}

View File

@ -21,8 +21,7 @@ import {
ProfileMetadata, ProfileMetadata,
SignedEvent, SignedEvent,
User, User,
UserRole, UserRole
KeyboardCode
} from '../../types' } from '../../types'
import { import {
encryptArrayBuffer, encryptArrayBuffer,
@ -88,10 +87,7 @@ export const CreatePage = () => {
const [userInput, setUserInput] = useState('') const [userInput, setUserInput] = useState('')
const handleInputKeyDown = (event: React.KeyboardEvent<HTMLDivElement>) => { const handleInputKeyDown = (event: React.KeyboardEvent<HTMLDivElement>) => {
if ( if (event.code === 'Enter' || event.code === 'NumpadEnter') {
event.code === KeyboardCode.Enter ||
event.code === KeyboardCode.NumpadEnter
) {
event.preventDefault() event.preventDefault()
handleAddUser() handleAddUser()
} }

View File

@ -9,7 +9,6 @@ import { toast } from 'react-toastify'
import { LoadingSpinner } from '../../components/LoadingSpinner' import { LoadingSpinner } from '../../components/LoadingSpinner'
import { AuthController } from '../../controllers' import { AuthController } from '../../controllers'
import { updateKeyPair, updateLoginMethod } from '../../store/actions' import { updateKeyPair, updateLoginMethod } from '../../store/actions'
import { KeyboardCode } from '../../types'
import { LoginMethod } from '../../store/auth/types' import { LoginMethod } from '../../store/auth/types'
import { hexToBytes } from '@noble/hashes/utils' import { hexToBytes } from '@noble/hashes/utils'
@ -53,10 +52,7 @@ export const Nostr = () => {
* Call login function when enter is pressed * Call login function when enter is pressed
*/ */
const handleInputKeyDown = (event: React.KeyboardEvent<HTMLDivElement>) => { const handleInputKeyDown = (event: React.KeyboardEvent<HTMLDivElement>) => {
if ( if (event.code === 'Enter' || event.code === 'NumpadEnter') {
event.code === KeyboardCode.Enter ||
event.code === KeyboardCode.NumpadEnter
) {
event.preventDefault() event.preventDefault()
login() login()
} }

View File

@ -1,5 +0,0 @@
export enum KeyboardCode {
Escape = 'Escape',
Enter = 'Enter',
NumpadEnter = 'NumpadEnter'
}

View File

@ -4,4 +4,3 @@ export * from './nostr'
export * from './profile' export * from './profile'
export * from './relay' export * from './relay'
export * from './zip' export * from './zip'
export * from './event'