diff --git a/src/components/AppBar/AppBar.tsx b/src/components/AppBar/AppBar.tsx index 4176a42..ff68469 100644 --- a/src/components/AppBar/AppBar.tsx +++ b/src/components/AppBar/AppBar.tsx @@ -28,9 +28,9 @@ import { } from '../../routes' import { clearAuthToken, + getProfileUsername, hexToNpub, - saveNsecBunkerDelegatedKey, - shorten + saveNsecBunkerDelegatedKey } from '../../utils' import styles from './style.module.scss' import { setUserRobotImage } from '../../store/userRobotImage/action' @@ -58,9 +58,8 @@ export const AppBar = () => { useEffect(() => { if (metadataState) { if (metadataState.content) { - const { picture, display_name, name } = JSON.parse( - metadataState.content - ) + const profileMetadata = JSON.parse(metadataState.content) + const { picture } = profileMetadata if (picture || userRobotImage) { setUserAvatar(picture || userRobotImage) @@ -70,7 +69,7 @@ export const AppBar = () => { ? hexToNpub(authState.usersPubkey) : '' - setUsername(shorten(display_name || name || npub, 7)) + setUsername(getProfileUsername(npub, profileMetadata)) } else { setUserAvatar(userRobotImage || '') setUsername('') @@ -133,8 +132,10 @@ export const AppBar = () => {
- SIGit is currently Alpha software (available for internal - testing), use at your own risk! +

+ SIGit is currently Alpha software (available for internal + testing), use at your own risk! +

+ )}
) })} @@ -524,28 +558,19 @@ export const DrawPDFFields = (props: Props) => { ) } - const renderCounterpartValue = (value: string) => { - const user = users.find((u) => u.pubkey === npubToHex(value)) - if (user) { - let displayValue = truncate(value, { - length: 16 - }) + const renderCounterpartValue = (npub: string) => { + let displayValue = _.truncate(npub, { length: 16 }) - const metadata = props.metadata[user.pubkey] + const signer = signers.find((u) => u.pubkey === npubToHex(npub)) + if (signer) { + const metadata = props.metadata[signer.pubkey] + displayValue = getProfileUsername(npub, metadata) - if (metadata) { - displayValue = truncate( - metadata.name || metadata.display_name || metadata.username || value, - { - length: 16 - } - ) - } return ( - <> +
{ }} /> {displayValue} - +
) } - return value - } - - if (parsingPdf) { - return - } - - if (!sigitFiles.length) { - return '' + return displayValue } return ( @@ -589,7 +606,7 @@ export const DrawPDFFields = (props: Props) => { )} - {i < selectedFiles.length - 1 && } + {i < sigitFiles.length - 1 && } ) })} diff --git a/src/components/DrawPDFFields/style.module.scss b/src/components/DrawPDFFields/style.module.scss index 13afb9f..8c0b3b8 100644 --- a/src/components/DrawPDFFields/style.module.scss +++ b/src/components/DrawPDFFields/style.module.scss @@ -84,3 +84,14 @@ padding: 5px 0; } } + +.counterpartSelectValue { + display: flex; +} + +.counterpartAvatar { + img { + width: 21px; + height: 21px; + } +} diff --git a/src/components/UserAvatar/index.tsx b/src/components/UserAvatar/index.tsx index 0ea1fc1..4c49e33 100644 --- a/src/components/UserAvatar/index.tsx +++ b/src/components/UserAvatar/index.tsx @@ -5,7 +5,7 @@ import { AvatarIconButton } from '../UserAvatarIconButton' import { Link } from 'react-router-dom' import { useProfileMetadata } from '../../hooks/useProfileMetadata' import { Tooltip } from '@mui/material' -import { shorten } from '../../utils' +import { getProfileUsername } from '../../utils' import { TooltipChild } from '../TooltipChild' interface UserAvatarProps { @@ -22,7 +22,7 @@ export const UserAvatar = ({ isNameVisible = false }: UserAvatarProps) => { const profile = useProfileMetadata(pubkey) - const name = profile?.display_name || profile?.name || shorten(pubkey) + const name = getProfileUsername(pubkey, profile) const image = profile?.picture return ( diff --git a/src/pages/create/index.tsx b/src/pages/create/index.tsx index 7b04b01..d4d82b2 100644 --- a/src/pages/create/index.tsx +++ b/src/pages/create/index.tsx @@ -40,7 +40,8 @@ import { signEventForMetaFile, updateUsersAppData, uploadToFileStorage, - DEFAULT_TOOLBOX + DEFAULT_TOOLBOX, + settleAllFullfilfedPromises } from '../../utils' import { Container } from '../../components/Container' import fileListStyles from '../../components/FileList/style.module.scss' @@ -61,7 +62,8 @@ import { faTrash, faUpload } from '@fortawesome/free-solid-svg-icons' -import { SigitFile } from '../../utils/file.ts' +import { getSigitFile, SigitFile } from '../../utils/file.ts' +import _ from 'lodash' import { generateTimestamp } from '../../utils/opentimestamps.ts' export const CreatePage = () => { @@ -108,9 +110,31 @@ export const CreatePage = () => { {} ) const [drawnFiles, setDrawnFiles] = useState([]) + const [parsingPdf, setIsParsing] = useState(false) + useEffect(() => { + if (selectedFiles) { + /** + * Reads the binary files and converts to internal file type + * and sets to a state (adds images if it's a PDF) + */ + const parsePages = async () => { + const files = await settleAllFullfilfedPromises( + selectedFiles, + getSigitFile + ) + + setDrawnFiles(files) + } + + setIsParsing(true) + + parsePages().finally(() => { + setIsParsing(false) + }) + } + }, [selectedFiles]) const [selectedTool, setSelectedTool] = useState() - const [toolbox] = useState(DEFAULT_TOOLBOX) /** * Changes the drawing tool @@ -284,6 +308,19 @@ export const CreatePage = () => { const handleRemoveUser = (pubkey: string) => { setUsers((prev) => prev.filter((user) => user.pubkey !== pubkey)) + + // Set counterpart to '' + const drawnFilesCopy = _.cloneDeep(drawnFiles) + drawnFilesCopy.forEach((s) => { + s.pages?.forEach((p) => { + p.drawnFields.forEach((d) => { + if (d.counterpart === hexToNpub(pubkey)) { + d.counterpart = '' + } + }) + }) + }) + setDrawnFiles(drawnFilesCopy) } /** @@ -739,10 +776,6 @@ export const CreatePage = () => { } } - const onDrawFieldsChange = (sigitFiles: SigitFile[]) => { - setDrawnFiles(sigitFiles) - } - if (authUrl) { return (