Compare commits

..

No commits in common. "7056ad3cd3fa12d17cec80f91dd32a557e71f378" and "dd97dfbaf0beedf31d82ef42f70209f379566df7" have entirely different histories.

16 changed files with 340 additions and 505 deletions

View File

@ -100,10 +100,10 @@ li {
// - first-child Header height, default body padding, and center content border (10px) and padding (10px) // - first-child Header height, default body padding, and center content border (10px) and padding (10px)
// - others We don't include border and padding and scroll to the top of the image // - others We don't include border and padding and scroll to the top of the image
&:first-child { &:first-child {
scroll-margin-top: $body-vertical-padding + 20px; scroll-margin-top: $header-height + $body-vertical-padding + 20px;
} }
&:not(:first-child) { &:not(:first-child) {
scroll-margin-top: $body-vertical-padding; scroll-margin-top: $header-height + $body-vertical-padding;
} }
} }
@ -148,7 +148,7 @@ li {
justify-content: start; justify-content: start;
align-items: start; align-items: start;
scroll-margin-top: $body-vertical-padding; scroll-margin-top: $header-height + $body-vertical-padding;
} }
[data-dev='true'] { [data-dev='true'] {

View File

@ -28,17 +28,14 @@ import {
} from '../../routes' } from '../../routes'
import { import {
clearAuthToken, clearAuthToken,
getProfileUsername,
hexToNpub, hexToNpub,
saveNsecBunkerDelegatedKey saveNsecBunkerDelegatedKey,
shorten
} from '../../utils' } from '../../utils'
import styles from './style.module.scss' import styles from './style.module.scss'
import { setUserRobotImage } from '../../store/userRobotImage/action' import { setUserRobotImage } from '../../store/userRobotImage/action'
import { Container } from '../Container' import { Container } from '../Container'
import { ButtonIcon } from '../ButtonIcon' import { ButtonIcon } from '../ButtonIcon'
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'
import { faClose } from '@fortawesome/free-solid-svg-icons'
import useMediaQuery from '@mui/material/useMediaQuery'
const metadataController = MetadataController.getInstance() const metadataController = MetadataController.getInstance()
@ -58,8 +55,9 @@ export const AppBar = () => {
useEffect(() => { useEffect(() => {
if (metadataState) { if (metadataState) {
if (metadataState.content) { if (metadataState.content) {
const profileMetadata = JSON.parse(metadataState.content) const { picture, display_name, name } = JSON.parse(
const { picture } = profileMetadata metadataState.content
)
if (picture || userRobotImage) { if (picture || userRobotImage) {
setUserAvatar(picture || userRobotImage) setUserAvatar(picture || userRobotImage)
@ -69,7 +67,7 @@ export const AppBar = () => {
? hexToNpub(authState.usersPubkey) ? hexToNpub(authState.usersPubkey)
: '' : ''
setUsername(getProfileUsername(npub, profileMetadata)) setUsername(shorten(display_name || name || npub, 7))
} else { } else {
setUserAvatar(userRobotImage || '') setUserAvatar(userRobotImage || '')
setUsername('') setUsername('')
@ -120,152 +118,125 @@ export const AppBar = () => {
} }
const isAuthenticated = authState?.loggedIn === true const isAuthenticated = authState?.loggedIn === true
const matches = useMediaQuery('(max-width:767px)')
const [isBannerVisible, setIsBannerVisible] = useState(true)
const handleBannerHide = () => {
setIsBannerVisible(false)
}
return ( return (
<> <AppBarMui
{isAuthenticated && isBannerVisible && ( position="fixed"
<div className={styles.banner}> className={styles.AppBar}
<Container> sx={{
<div className={styles.bannerInner}> boxShadow: 'none'
<p className={styles.bannerText}> }}
SIGit is currently Alpha software (available for internal >
testing), use at your own risk! <Container>
</p> <Toolbar className={styles.toolbar} disableGutters={true}>
<Box className={styles.logoWrapper}>
<img src="/logo.svg" alt="Logo" onClick={() => navigate('/')} />
</Box>
<Box className={styles.rightSideBox}>
{!isAuthenticated && (
<Button <Button
aria-label={`close banner`} startIcon={<ButtonIcon />}
variant="text" onClick={() => {
onClick={handleBannerHide} navigate(appPublicRoutes.nostr)
}}
variant="contained"
> >
<FontAwesomeIcon icon={faClose} /> LOGIN
</Button> </Button>
</div> )}
</Container>
</div>
)}
<AppBarMui
position={matches ? 'sticky' : 'static'}
className={styles.AppBar}
sx={{
boxShadow: 'none'
}}
>
<Container>
<Toolbar className={styles.toolbar} disableGutters={true}>
<Box className={styles.logoWrapper}>
<img src="/logo.svg" alt="Logo" onClick={() => navigate('/')} />
</Box>
<Box className={styles.rightSideBox}> {isAuthenticated && (
{!isAuthenticated && ( <>
<Button <Username
startIcon={<ButtonIcon />} username={username}
onClick={() => { avatarContent={userAvatar}
navigate(appPublicRoutes.nostr) handleClick={handleOpenUserMenu}
/>
<Menu
id="menu-appbar"
anchorEl={anchorElUser}
anchorOrigin={{
vertical: 'bottom',
horizontal: 'center'
}} }}
variant="contained" keepMounted
transformOrigin={{
vertical: 'top',
horizontal: 'center'
}}
open={!!anchorElUser}
onClose={handleCloseUserMenu}
> >
LOGIN <MenuItem
</Button> sx={{
)} justifyContent: 'center',
display: { md: 'none' },
fontWeight: 500,
fontSize: '14px',
color: 'var(--text-color)'
}}
>
<Typography variant="h6">{username}</Typography>
</MenuItem>
<MenuItem
onClick={handleProfile}
sx={{
justifyContent: 'center'
}}
>
Profile
</MenuItem>
<MenuItem
onClick={() => {
setAnchorElUser(null)
{isAuthenticated && ( navigate(appPrivateRoutes.settings)
<>
<Username
username={username}
avatarContent={userAvatar}
handleClick={handleOpenUserMenu}
/>
<Menu
id="menu-appbar"
anchorEl={anchorElUser}
anchorOrigin={{
vertical: 'bottom',
horizontal: 'center'
}} }}
keepMounted sx={{
transformOrigin={{ justifyContent: 'center'
vertical: 'top',
horizontal: 'center'
}} }}
open={!!anchorElUser} >
onClose={handleCloseUserMenu} Settings
</MenuItem>
<MenuItem
onClick={() => {
setAnchorElUser(null)
navigate(appPublicRoutes.verify)
}}
sx={{
justifyContent: 'center'
}}
>
Verify
</MenuItem>
<Link
to={appPublicRoutes.source}
target="_blank"
style={{ color: 'inherit', textDecoration: 'inherit' }}
> >
<MenuItem <MenuItem
sx={{
justifyContent: 'center',
display: { md: 'none' },
fontWeight: 500,
fontSize: '14px',
color: 'var(--text-color)'
}}
>
<Typography variant="h6">{username}</Typography>
</MenuItem>
<MenuItem
onClick={handleProfile}
sx={{ sx={{
justifyContent: 'center' justifyContent: 'center'
}} }}
> >
Profile Source
</MenuItem> </MenuItem>
<MenuItem </Link>
onClick={() => { <MenuItem
setAnchorElUser(null) onClick={handleLogout}
sx={{
navigate(appPrivateRoutes.settings) justifyContent: 'center'
}} }}
sx={{ >
justifyContent: 'center' Logout
}} </MenuItem>
> </Menu>
Settings </>
</MenuItem> )}
<MenuItem </Box>
onClick={() => { </Toolbar>
setAnchorElUser(null) </Container>
</AppBarMui>
navigate(appPublicRoutes.verify)
}}
sx={{
justifyContent: 'center'
}}
>
Verify
</MenuItem>
<Link
to={appPublicRoutes.source}
target="_blank"
style={{ color: 'inherit', textDecoration: 'inherit' }}
>
<MenuItem
sx={{
justifyContent: 'center'
}}
>
Source
</MenuItem>
</Link>
<MenuItem
onClick={handleLogout}
sx={{
justifyContent: 'center'
}}
>
Logout
</MenuItem>
</Menu>
</>
)}
</Box>
</Toolbar>
</Container>
</AppBarMui>
</>
) )
} }

View File

@ -34,42 +34,3 @@
justify-content: flex-end; justify-content: flex-end;
} }
} }
.banner {
color: #ffffff;
background-color: $primary-main;
}
.bannerInner {
display: flex;
gap: 10px;
padding-block: 10px;
z-index: 1;
width: 100%;
justify-content: space-between;
flex-direction: row;
button {
min-width: 44px;
color: inherit;
}
&:hover,
&.active,
&:focus-within {
background: $primary-main;
color: inherit;
button {
color: inherit;
}
}
}
.bannerText {
margin-left: 54px;
flex-grow: 1;
text-align: center;
}

View File

@ -11,16 +11,16 @@ 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 } 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 { truncate } from 'lodash'
import { SigitFile } from '../../utils/file' import { settleAllFullfilfedPromises, hexToNpub, npubToHex } from '../../utils'
import { getSigitFile, SigitFile } from '../../utils/file'
import { getToolboxLabelByMarkType } from '../../utils/mark' import { getToolboxLabelByMarkType } from '../../utils/mark'
import { FileDivider } from '../FileDivider' import { FileDivider } from '../FileDivider'
import { ExtensionFileBox } from '../ExtensionFileBox' import { ExtensionFileBox } from '../ExtensionFileBox'
import { FONT_SIZE, FONT_TYPE, inPx } from '../../utils/pdf' import { FONT_SIZE, FONT_TYPE, inPx } from '../../utils/pdf'
import { useScale } from '../../hooks/useScale' import { useScale } from '../../hooks/useScale'
import { AvatarIconButton } from '../UserAvatarIconButton' import { AvatarIconButton } from '../UserAvatarIconButton'
import { UserAvatar } from '../UserAvatar' import { LoadingSpinner } from '../LoadingSpinner'
import _ from 'lodash'
const DEFAULT_START_SIZE = { const DEFAULT_START_SIZE = {
width: 140, width: 140,
@ -28,50 +28,52 @@ const DEFAULT_START_SIZE = {
} as const } as const
interface Props { interface Props {
selectedFiles: File[]
users: User[] users: User[]
metadata: { [key: string]: ProfileMetadata } metadata: { [key: string]: ProfileMetadata }
sigitFiles: SigitFile[] onDrawFieldsChange: (sigitFiles: SigitFile[]) => void
setSigitFiles: React.Dispatch<React.SetStateAction<SigitFile[]>>
selectedTool?: DrawTool selectedTool?: DrawTool
} }
export const DrawPDFFields = (props: Props) => { export const DrawPDFFields = (props: Props) => {
const { selectedTool, sigitFiles, setSigitFiles, users } = props const { selectedFiles, selectedTool, onDrawFieldsChange, users } = props
const signers = users.filter((u) => u.role === UserRole.signer)
const defaultSignerNpub = signers.length ? hexToNpub(signers[0].pubkey) : ''
const [lastSigner, setLastSigner] = useState(defaultSignerNpub)
/**
* Return first pubkey that is present in the signers list
* @param pubkeys
* @returns available pubkey or empty string
*/
const getAvailableSigner = (...pubkeys: string[]) => {
const availableSigner: string | undefined = pubkeys.find((pubkey) =>
signers.some((s) => s.pubkey === npubToHex(pubkey))
)
return availableSigner || ''
}
const { to, from } = useScale() const { to, from } = useScale()
const [sigitFiles, setSigitFiles] = useState<SigitFile[]>([])
const [parsingPdf, setIsParsing] = useState<boolean>(false)
const [mouseState, setMouseState] = useState<MouseState>({ const [mouseState, setMouseState] = useState<MouseState>({
clicked: false clicked: false
}) })
const [activeDrawnField, setActiveDrawnField] = useState<{ const [activeDrawField, setActiveDrawField] = useState<number>()
fileIndex: number
pageIndex: number useEffect(() => {
drawnFieldIndex: number if (selectedFiles) {
}>() /**
const isActiveDrawnField = ( * Reads the binary files and converts to internal file type
fileIndex: number, * and sets to a state (adds images if it's a PDF)
pageIndex: number, */
drawnFieldIndex: number const parsePages = async () => {
) => const files = await settleAllFullfilfedPromises(
activeDrawnField?.fileIndex === fileIndex && selectedFiles,
activeDrawnField?.pageIndex === pageIndex && getSigitFile
activeDrawnField?.drawnFieldIndex === drawnFieldIndex )
setSigitFiles(files)
}
setIsParsing(true)
parsePages().finally(() => {
setIsParsing(false)
})
}
}, [selectedFiles])
useEffect(() => {
if (sigitFiles) onDrawFieldsChange(sigitFiles)
}, [onDrawFieldsChange, sigitFiles])
/** /**
* Drawing events * Drawing events
@ -98,12 +100,7 @@ export const DrawPDFFields = (props: Props) => {
* @param event Pointer event * @param event Pointer event
* @param page PdfPage where press happened * @param page PdfPage where press happened
*/ */
const handlePointerDown = ( const handlePointerDown = (event: React.PointerEvent, page: PdfPage) => {
event: React.PointerEvent,
page: PdfPage,
fileIndex: number,
pageIndex: number
) => {
// Proceed only if left click // Proceed only if left click
if (event.button !== 0) return if (event.button !== 0) return
@ -118,17 +115,12 @@ export const DrawPDFFields = (props: Props) => {
top: to(page.width, y), top: to(page.width, y),
width: event.pointerType === 'mouse' ? 0 : DEFAULT_START_SIZE.width, width: event.pointerType === 'mouse' ? 0 : DEFAULT_START_SIZE.width,
height: event.pointerType === 'mouse' ? 0 : DEFAULT_START_SIZE.height, height: event.pointerType === 'mouse' ? 0 : DEFAULT_START_SIZE.height,
counterpart: getAvailableSigner(lastSigner, defaultSignerNpub), counterpart: '',
type: selectedTool.identifier type: selectedTool.identifier
} }
page.drawnFields.push(newField) page.drawnFields.push(newField)
setActiveDrawnField({
fileIndex,
pageIndex,
drawnFieldIndex: page.drawnFields.length - 1
})
setMouseState((prev) => { setMouseState((prev) => {
return { return {
...prev, ...prev,
@ -197,8 +189,6 @@ export const DrawPDFFields = (props: Props) => {
*/ */
const handleDrawnFieldPointerDown = ( const handleDrawnFieldPointerDown = (
event: React.PointerEvent, event: React.PointerEvent,
fileIndex: number,
pageIndex: number,
drawnFieldIndex: number drawnFieldIndex: number
) => { ) => {
event.stopPropagation() event.stopPropagation()
@ -208,7 +198,7 @@ export const DrawPDFFields = (props: Props) => {
const drawingRectangleCoords = getPointerCoordinates(event) const drawingRectangleCoords = getPointerCoordinates(event)
setActiveDrawnField({ fileIndex, pageIndex, drawnFieldIndex }) setActiveDrawField(drawnFieldIndex)
setMouseState({ setMouseState({
dragging: true, dragging: true,
clicked: false, clicked: false,
@ -264,15 +254,13 @@ export const DrawPDFFields = (props: Props) => {
*/ */
const handleResizePointerDown = ( const handleResizePointerDown = (
event: React.PointerEvent, event: React.PointerEvent,
fileIndex: number,
pageIndex: number,
drawnFieldIndex: number drawnFieldIndex: number
) => { ) => {
// Proceed only if left click // Proceed only if left click
if (event.button !== 0) return if (event.button !== 0) return
event.stopPropagation() event.stopPropagation()
setActiveDrawnField({ fileIndex, pageIndex, drawnFieldIndex }) setActiveDrawField(drawnFieldIndex)
setMouseState({ setMouseState({
resizing: true resizing: true
}) })
@ -381,7 +369,7 @@ export const DrawPDFFields = (props: Props) => {
handlePointerMove(event, page) handlePointerMove(event, page)
}} }}
onPointerDown={(event) => { onPointerDown={(event) => {
handlePointerDown(event, page, fileIndex, pageIndex) handlePointerDown(event, page)
}} }}
draggable="false" draggable="false"
src={page.image} src={page.image}
@ -393,12 +381,7 @@ export const DrawPDFFields = (props: Props) => {
<div <div
key={drawnFieldIndex} key={drawnFieldIndex}
onPointerDown={(event) => onPointerDown={(event) =>
handleDrawnFieldPointerDown( handleDrawnFieldPointerDown(event, drawnFieldIndex)
event,
fileIndex,
pageIndex,
drawnFieldIndex
)
} }
onPointerMove={(event) => { onPointerMove={(event) => {
handleDrawnFieldPointerMove(event, drawnField, page.width) handleDrawnFieldPointerMove(event, drawnField, page.width)
@ -419,11 +402,7 @@ export const DrawPDFFields = (props: Props) => {
touchAction: 'none', touchAction: 'none',
opacity: opacity:
mouseState.dragging && mouseState.dragging &&
isActiveDrawnField( activeDrawField === drawnFieldIndex
fileIndex,
pageIndex,
drawnFieldIndex
)
? 0.8 ? 0.8
: undefined : undefined
}} }}
@ -440,12 +419,7 @@ export const DrawPDFFields = (props: Props) => {
</div> </div>
<span <span
onPointerDown={(event) => onPointerDown={(event) =>
handleResizePointerDown( handleResizePointerDown(event, drawnFieldIndex)
event,
fileIndex,
pageIndex,
drawnFieldIndex
)
} }
onPointerMove={(event) => { onPointerMove={(event) => {
handleResizePointerMove(event, drawnField, page.width) handleResizePointerMove(event, drawnField, page.width)
@ -454,11 +428,7 @@ export const DrawPDFFields = (props: Props) => {
style={{ style={{
background: background:
mouseState.resizing && mouseState.resizing &&
isActiveDrawnField( activeDrawField === drawnFieldIndex
fileIndex,
pageIndex,
drawnFieldIndex
)
? 'var(--primary-main)' ? 'var(--primary-main)'
: undefined : undefined
}} }}
@ -476,59 +446,56 @@ export const DrawPDFFields = (props: Props) => {
> >
<Close fontSize="small" /> <Close fontSize="small" />
</span> </span>
{!isActiveDrawnField( <div
fileIndex, onPointerDown={handleUserSelectPointerDown}
pageIndex, className={styles.userSelect}
drawnFieldIndex >
) && <FormControl fullWidth size="small">
!!drawnField.counterpart && ( <InputLabel id="counterparts">Counterpart</InputLabel>
<div className={styles.counterpartAvatar}> <Select
<UserAvatar value={drawnField.counterpart}
pubkey={npubToHex(drawnField.counterpart)!} onChange={(event) => {
/> drawnField.counterpart = event.target.value
</div> refreshPdfFiles()
)} }}
{isActiveDrawnField( labelId="counterparts"
fileIndex, label="Counterparts"
pageIndex, sx={{
drawnFieldIndex background: 'white'
) && ( }}
<div renderValue={(value) => renderCounterpartValue(value)}
onPointerDown={handleUserSelectPointerDown} >
className={styles.userSelect} {users
> .filter((u) => u.role === UserRole.signer)
<FormControl fullWidth size="small"> .map((user, index) => {
<InputLabel id="counterparts">Counterpart</InputLabel> const npub = hexToNpub(user.pubkey)
<Select let displayValue = truncate(npub, {
value={getAvailableSigner(drawnField.counterpart)} length: 16
onChange={(event) => { })
drawnField.counterpart = event.target.value
setLastSigner(event.target.value) const metadata = props.metadata[user.pubkey]
refreshPdfFiles()
}} if (metadata) {
labelId="counterparts" displayValue = truncate(
label="Counterparts" metadata.name ||
sx={{ metadata.display_name ||
background: 'white' metadata.username ||
}} npub,
renderValue={(value) => {
renderCounterpartValue(value) length: 16
} }
> )
{signers.map((signer, index) => { }
const npub = hexToNpub(signer.pubkey)
const metadata = props.metadata[signer.pubkey]
const displayValue = getProfileUsername(
npub,
metadata
)
return ( return (
<MenuItem key={index} value={npub}> <MenuItem
key={index}
value={hexToNpub(user.pubkey)}
>
<ListItemIcon> <ListItemIcon>
<AvatarIconButton <AvatarIconButton
src={metadata?.picture} src={metadata?.picture}
hexKey={signer.pubkey} hexKey={user.pubkey}
aria-label={`account of user ${displayValue}`} aria-label={`account of user ${displayValue}`}
color="inherit" color="inherit"
sx={{ sx={{
@ -544,10 +511,9 @@ export const DrawPDFFields = (props: Props) => {
</MenuItem> </MenuItem>
) )
})} })}
</Select> </Select>
</FormControl> </FormControl>
</div> </div>
)}
</div> </div>
) )
})} })}
@ -558,19 +524,28 @@ export const DrawPDFFields = (props: Props) => {
) )
} }
const renderCounterpartValue = (npub: string) => { const renderCounterpartValue = (value: string) => {
let displayValue = _.truncate(npub, { length: 16 }) const user = users.find((u) => u.pubkey === npubToHex(value))
if (user) {
let displayValue = truncate(value, {
length: 16
})
const signer = signers.find((u) => u.pubkey === npubToHex(npub)) const metadata = props.metadata[user.pubkey]
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 ( return (
<div className={styles.counterpartSelectValue}> <>
<AvatarIconButton <AvatarIconButton
src={props.metadata[signer.pubkey]?.picture} src={props.metadata[user.pubkey]?.picture}
hexKey={signer.pubkey || undefined} hexKey={npubToHex(user.pubkey) || undefined}
sx={{ sx={{
padding: 0, padding: 0,
marginRight: '6px', marginRight: '6px',
@ -581,11 +556,19 @@ export const DrawPDFFields = (props: Props) => {
}} }}
/> />
{displayValue} {displayValue}
</div> </>
) )
} }
return displayValue return value
}
if (parsingPdf) {
return <LoadingSpinner variant="small" />
}
if (!sigitFiles.length) {
return ''
} }
return ( return (
@ -606,7 +589,7 @@ export const DrawPDFFields = (props: Props) => {
<ExtensionFileBox extension={file.extension} /> <ExtensionFileBox extension={file.extension} />
)} )}
</div> </div>
{i < sigitFiles.length - 1 && <FileDivider />} {i < selectedFiles.length - 1 && <FileDivider />}
</React.Fragment> </React.Fragment>
) )
})} })}

View File

@ -84,14 +84,3 @@
padding: 5px 0; padding: 5px 0;
} }
} }
.counterpartSelectValue {
display: flex;
}
.counterpartAvatar {
img {
width: 21px;
height: 21px;
}
}

View File

@ -33,8 +33,7 @@ const PdfPageItem = ({
useEffect(() => { useEffect(() => {
if (selectedMark !== null && !!markRefs.current[selectedMark.id]) { if (selectedMark !== null && !!markRefs.current[selectedMark.id]) {
markRefs.current[selectedMark.id]?.scrollIntoView({ markRefs.current[selectedMark.id]?.scrollIntoView({
behavior: 'smooth', behavior: 'smooth'
block: 'center'
}) })
} }
}, [selectedMark]) }, [selectedMark])

View File

@ -5,7 +5,7 @@ import { AvatarIconButton } from '../UserAvatarIconButton'
import { Link } from 'react-router-dom' import { Link } from 'react-router-dom'
import { useProfileMetadata } from '../../hooks/useProfileMetadata' import { useProfileMetadata } from '../../hooks/useProfileMetadata'
import { Tooltip } from '@mui/material' import { Tooltip } from '@mui/material'
import { getProfileUsername } from '../../utils' import { shorten } from '../../utils'
import { TooltipChild } from '../TooltipChild' import { TooltipChild } from '../TooltipChild'
interface UserAvatarProps { interface UserAvatarProps {
@ -22,7 +22,7 @@ export const UserAvatar = ({
isNameVisible = false isNameVisible = false
}: UserAvatarProps) => { }: UserAvatarProps) => {
const profile = useProfileMetadata(pubkey) const profile = useProfileMetadata(pubkey)
const name = getProfileUsername(pubkey, profile) const name = profile?.display_name || profile?.name || shorten(pubkey)
const image = profile?.picture const image = profile?.picture
return ( return (

View File

@ -42,22 +42,15 @@
.sides { .sides {
@media only screen and (min-width: 768px) { @media only screen and (min-width: 768px) {
position: sticky; position: sticky;
top: $body-vertical-padding; top: $header-height + $body-vertical-padding;
} }
> :first-child { > :first-child {
// We want to keep header on smaller devices at all times
max-height: calc( max-height: calc(
100dvh - $header-height - $body-vertical-padding * 2 - $tabs-height 100dvh - $header-height - $body-vertical-padding * 2 - $tabs-height
); );
@media only screen and (min-width: 768px) {
max-height: calc(100dvh - $body-vertical-padding * 2);
}
} }
} }
// Adjust the content scroll on smaller screens
// Make sure only the inner tab is scrolling
.scrollAdjust { .scrollAdjust {
@media only screen and (max-width: 767px) { @media only screen and (max-width: 767px) {
max-height: calc( max-height: calc(

View File

@ -3,5 +3,5 @@
.main { .main {
flex-grow: 1; flex-grow: 1;
padding: $body-vertical-padding 0 $body-vertical-padding 0; padding: $header-height + $body-vertical-padding 0 $body-vertical-padding 0;
} }

View File

@ -39,8 +39,7 @@ import {
signEventForMetaFile, signEventForMetaFile,
updateUsersAppData, updateUsersAppData,
uploadToFileStorage, uploadToFileStorage,
DEFAULT_TOOLBOX, DEFAULT_TOOLBOX
settleAllFullfilfedPromises
} from '../../utils' } from '../../utils'
import { Container } from '../../components/Container' import { Container } from '../../components/Container'
import fileListStyles from '../../components/FileList/style.module.scss' import fileListStyles from '../../components/FileList/style.module.scss'
@ -61,8 +60,7 @@ import {
faTrash, faTrash,
faUpload faUpload
} from '@fortawesome/free-solid-svg-icons' } from '@fortawesome/free-solid-svg-icons'
import { getSigitFile, SigitFile } from '../../utils/file.ts' import { SigitFile } from '../../utils/file.ts'
import _ from 'lodash'
export const CreatePage = () => { export const CreatePage = () => {
const navigate = useNavigate() const navigate = useNavigate()
@ -108,31 +106,9 @@ export const CreatePage = () => {
{} {}
) )
const [drawnFiles, setDrawnFiles] = useState<SigitFile[]>([]) const [drawnFiles, setDrawnFiles] = useState<SigitFile[]>([])
const [parsingPdf, setIsParsing] = useState<boolean>(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<DrawTool>() const [selectedTool, setSelectedTool] = useState<DrawTool>()
const [toolbox] = useState<DrawTool[]>(DEFAULT_TOOLBOX)
/** /**
* Changes the drawing tool * Changes the drawing tool
@ -306,19 +282,6 @@ export const CreatePage = () => {
const handleRemoveUser = (pubkey: string) => { const handleRemoveUser = (pubkey: string) => {
setUsers((prev) => prev.filter((user) => user.pubkey !== pubkey)) 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)
} }
/** /**
@ -338,15 +301,7 @@ export const CreatePage = () => {
const handleSelectFiles = (event: React.ChangeEvent<HTMLInputElement>) => { const handleSelectFiles = (event: React.ChangeEvent<HTMLInputElement>) => {
if (event.target.files) { if (event.target.files) {
// Get the uploaded files setSelectedFiles(Array.from(event.target.files))
const files = Array.from(event.target.files)
// Remove duplicates based on the file.name
setSelectedFiles((p) =>
[...p, ...files].filter(
(file, i, array) => i === array.findIndex((t) => t.name === file.name)
)
)
} }
} }
@ -761,6 +716,10 @@ export const CreatePage = () => {
} }
} }
const onDrawFieldsChange = (sigitFiles: SigitFile[]) => {
setDrawnFiles(sigitFiles)
}
if (authUrl) { if (authUrl) {
return ( return (
<iframe <iframe
@ -874,36 +833,28 @@ export const CreatePage = () => {
</div> </div>
<div className={`${styles.paperGroup} ${styles.toolbox}`}> <div className={`${styles.paperGroup} ${styles.toolbox}`}>
{DEFAULT_TOOLBOX.filter((drawTool) => !drawTool.isHidden).map( {toolbox.map((drawTool: DrawTool, index: number) => {
(drawTool: DrawTool, index: number) => { return (
return ( <div
<div key={index}
key={index} {...(drawTool.active && {
{...(!drawTool.isComingSoon && { onClick: () => handleToolSelect(drawTool)
onClick: () => handleToolSelect(drawTool) })}
})} className={`${styles.toolItem} ${selectedTool?.identifier === drawTool.identifier ? styles.selected : ''} ${!drawTool.active ? styles.comingSoon : ''}
className={`${styles.toolItem} ${selectedTool?.identifier === drawTool.identifier ? styles.selected : ''} ${drawTool.isComingSoon ? styles.comingSoon : ''}
`} `}
> >
<FontAwesomeIcon <FontAwesomeIcon fontSize={'15px'} icon={drawTool.icon} />
fontSize={'15px'} {drawTool.label}
icon={drawTool.icon} {drawTool.active ? (
/> <FontAwesomeIcon fontSize={'15px'} icon={faEllipsis} />
{drawTool.label} ) : (
{!drawTool.isComingSoon ? ( <span className={styles.comingSoonPlaceholder}>
<FontAwesomeIcon Coming soon
fontSize={'15px'} </span>
icon={faEllipsis} )}
/> </div>
) : ( )
<span className={styles.comingSoonPlaceholder}> })}
Coming soon
</span>
)}
</div>
)
}
)}
</div> </div>
<Button onClick={handleCreate} variant="contained"> <Button onClick={handleCreate} variant="contained">
@ -919,17 +870,13 @@ export const CreatePage = () => {
centerIcon={faFile} centerIcon={faFile}
rightIcon={faToolbox} rightIcon={faToolbox}
> >
{parsingPdf ? ( <DrawPDFFields
<LoadingSpinner variant="small" /> metadata={metadata}
) : ( users={users}
<DrawPDFFields selectedFiles={selectedFiles}
users={users} onDrawFieldsChange={onDrawFieldsChange}
metadata={metadata} selectedTool={selectedTool}
selectedTool={selectedTool} />
sigitFiles={drawnFiles}
setSigitFiles={setDrawnFiles}
/>
)}
</StickySideColumns> </StickySideColumns>
</Container> </Container>
</> </>

View File

@ -1,6 +1,7 @@
import ContentCopyIcon from '@mui/icons-material/ContentCopy' import ContentCopyIcon from '@mui/icons-material/ContentCopy'
import EditIcon from '@mui/icons-material/Edit' import EditIcon from '@mui/icons-material/Edit'
import { Box, IconButton, SxProps, Theme, Typography } from '@mui/material' import { Box, IconButton, SxProps, Theme, Typography } from '@mui/material'
import { truncate } from 'lodash'
import { Event, VerifiedEvent, kinds, nip19 } from 'nostr-tools' import { Event, VerifiedEvent, kinds, nip19 } from 'nostr-tools'
import { useEffect, useMemo, useState } from 'react' import { useEffect, useMemo, useState } from 'react'
import { useSelector } from 'react-redux' import { useSelector } from 'react-redux'
@ -13,7 +14,6 @@ import { State } from '../../store/rootReducer'
import { NostrJoiningBlock, ProfileMetadata } from '../../types' import { NostrJoiningBlock, ProfileMetadata } from '../../types'
import { import {
getNostrJoiningBlockNumber, getNostrJoiningBlockNumber,
getProfileUsername,
getRoboHashPicture, getRoboHashPicture,
hexToNpub, hexToNpub,
shorten shorten
@ -42,7 +42,15 @@ export const ProfilePage = () => {
const [isLoading, setIsLoading] = useState(true) const [isLoading, setIsLoading] = useState(true)
const [loadingSpinnerDesc] = useState('Fetching metadata') const [loadingSpinnerDesc] = useState('Fetching metadata')
const profileName = pubkey && getProfileUsername(pubkey, profileMetadata) const profileName =
pubkey &&
profileMetadata &&
truncate(
profileMetadata.display_name || profileMetadata.name || hexToNpub(pubkey),
{
length: 16
}
)
useEffect(() => { useEffect(() => {
if (npub) { if (npub) {

View File

@ -233,7 +233,6 @@ export const RelaysPage = () => {
))} ))}
</Box> </Box>
)} )}
<Footer />
</Container> </Container>
) )
} }
@ -429,6 +428,7 @@ const RelayItem = ({
)} )}
</List> </List>
</Box> </Box>
<Footer />
</> </>
) )
} }

View File

@ -31,10 +31,7 @@ export interface DrawTool {
icon: IconDefinition icon: IconDefinition
defaultValue?: string defaultValue?: string
selected?: boolean selected?: boolean
/** show or hide the toolbox item */ active?: boolean
isHidden?: boolean
/** show or hide "coming soon" message on the toolbox item */
isComingSoon?: boolean
} }
export enum MarkType { export enum MarkType {

View File

@ -1,7 +1,6 @@
export interface ProfileMetadata { export interface ProfileMetadata {
name?: string name?: string
display_name?: string display_name?: string
/** @deprecated use name instead */
username?: string username?: string
picture?: string picture?: string
banner?: string banner?: string

View File

@ -3,26 +3,26 @@ import { hexToNpub } from './nostr.ts'
import { Meta, SignedEventContent } from '../types' import { Meta, SignedEventContent } from '../types'
import { Event } from 'nostr-tools' import { Event } from 'nostr-tools'
import { EMPTY } from './const.ts' import { EMPTY } from './const.ts'
import { DrawTool, MarkType } from '../types/drawing.ts' import { MarkType } from '../types/drawing.ts'
import { import {
faT, faT,
faSignature, faSignature,
faBriefcase, faBriefcase,
faIdCard, faIdCard,
faClock,
fa1,
faCalendarDays,
faCheckDouble,
faCircleDot,
faCreditCard,
faHeading, faHeading,
faClock,
faCalendarDays,
fa1,
faImage, faImage,
faPaperclip,
faPhone,
faSquareCaretDown,
faSquareCheck, faSquareCheck,
faCheckDouble,
faPaperclip,
faCircleDot,
faSquareCaretDown,
faTableCellsLarge,
faStamp, faStamp,
faTableCellsLarge faCreditCard,
faPhone
} from '@fortawesome/free-solid-svg-icons' } from '@fortawesome/free-solid-svg-icons'
/** /**
@ -152,113 +152,114 @@ const findOtherUserMarks = (marks: Mark[], pubkey: string): Mark[] => {
return marks.filter((mark) => mark.npub !== hexToNpub(pubkey)) return marks.filter((mark) => mark.npub !== hexToNpub(pubkey))
} }
export const DEFAULT_TOOLBOX: DrawTool[] = [ export const DEFAULT_TOOLBOX = [
{ {
identifier: MarkType.FULLNAME, identifier: MarkType.TEXT,
icon: faIdCard, icon: faT,
label: 'Full Name', label: 'Text',
isComingSoon: true active: true
},
{
identifier: MarkType.JOBTITLE,
icon: faBriefcase,
label: 'Job Title',
isComingSoon: true
}, },
{ {
identifier: MarkType.SIGNATURE, identifier: MarkType.SIGNATURE,
icon: faSignature, icon: faSignature,
label: 'Signature', label: 'Signature',
isComingSoon: true active: false
}, },
{ {
identifier: MarkType.DATETIME, identifier: MarkType.JOBTITLE,
icon: faClock, icon: faBriefcase,
label: 'Date Time', label: 'Job Title',
isComingSoon: true active: false
}, },
{ {
identifier: MarkType.TEXT, identifier: MarkType.FULLNAME,
icon: faT, icon: faIdCard,
label: 'Text' label: 'Full Name',
}, active: false
{
identifier: MarkType.NUMBER,
icon: fa1,
label: 'Number',
isComingSoon: true
}, },
{ {
identifier: MarkType.INITIALS, identifier: MarkType.INITIALS,
icon: faHeading, icon: faHeading,
label: 'Initials', label: 'Initials',
isHidden: true active: false
},
{
identifier: MarkType.DATETIME,
icon: faClock,
label: 'Date Time',
active: false
}, },
{ {
identifier: MarkType.DATE, identifier: MarkType.DATE,
icon: faCalendarDays, icon: faCalendarDays,
label: 'Date', label: 'Date',
isHidden: true active: false
},
{
identifier: MarkType.NUMBER,
icon: fa1,
label: 'Number',
active: false
}, },
{ {
identifier: MarkType.IMAGES, identifier: MarkType.IMAGES,
icon: faImage, icon: faImage,
label: 'Images', label: 'Images',
isHidden: true active: false
}, },
{ {
identifier: MarkType.CHECKBOX, identifier: MarkType.CHECKBOX,
icon: faSquareCheck, icon: faSquareCheck,
label: 'Checkbox', label: 'Checkbox',
isHidden: true active: false
}, },
{ {
identifier: MarkType.MULTIPLE, identifier: MarkType.MULTIPLE,
icon: faCheckDouble, icon: faCheckDouble,
label: 'Multiple', label: 'Multiple',
isHidden: true active: false
}, },
{ {
identifier: MarkType.FILE, identifier: MarkType.FILE,
icon: faPaperclip, icon: faPaperclip,
label: 'File', label: 'File',
isHidden: true active: false
}, },
{ {
identifier: MarkType.RADIO, identifier: MarkType.RADIO,
icon: faCircleDot, icon: faCircleDot,
label: 'Radio', label: 'Radio',
isHidden: true active: false
}, },
{ {
identifier: MarkType.SELECT, identifier: MarkType.SELECT,
icon: faSquareCaretDown, icon: faSquareCaretDown,
label: 'Select', label: 'Select',
isHidden: true active: false
}, },
{ {
identifier: MarkType.CELLS, identifier: MarkType.CELLS,
icon: faTableCellsLarge, icon: faTableCellsLarge,
label: 'Cells', label: 'Cells',
isHidden: true active: false
}, },
{ {
identifier: MarkType.STAMP, identifier: MarkType.STAMP,
icon: faStamp, icon: faStamp,
label: 'Stamp', label: 'Stamp',
isHidden: true active: false
}, },
{ {
identifier: MarkType.PAYMENT, identifier: MarkType.PAYMENT,
icon: faCreditCard, icon: faCreditCard,
label: 'Payment', label: 'Payment',
isHidden: true active: false
}, },
{ {
identifier: MarkType.PHONE, identifier: MarkType.PHONE,
icon: faPhone, icon: faPhone,
label: 'Phone', label: 'Phone',
isHidden: true active: false
} }
] ]

View File

@ -1,6 +1,6 @@
import { bytesToHex, hexToBytes } from '@noble/hashes/utils' import { bytesToHex, hexToBytes } from '@noble/hashes/utils'
import axios from 'axios' import axios from 'axios'
import _, { truncate } from 'lodash' import _ from 'lodash'
import { import {
Event, Event,
EventTemplate, EventTemplate,
@ -30,7 +30,7 @@ import {
import { AuthState, Keys } from '../store/auth/types' import { AuthState, Keys } from '../store/auth/types'
import { RelaysState } from '../store/relays/types' import { RelaysState } from '../store/relays/types'
import store from '../store/store' import store from '../store/store'
import { Meta, ProfileMetadata, SignedEvent, UserAppData } from '../types' import { Meta, SignedEvent, UserAppData } from '../types'
import { getDefaultRelayMap } from './relays' import { getDefaultRelayMap } from './relays'
import { parseJson, removeLeadingSlash } from './string' import { parseJson, removeLeadingSlash } from './string'
import { timeout } from './utils' import { timeout } from './utils'
@ -974,16 +974,3 @@ export const sendNotification = async (receiver: string, meta: Meta) => {
throw err throw err
}) })
} }
/**
* Show user's name, first available in order: display_name, name, or npub as fallback
* @param npub User identifier, it can be either pubkey or npub1 (we only show npub)
* @param profile User profile
*/
export const getProfileUsername = (
npub: `npub1${string}` | string,
profile?: ProfileMetadata
) =>
truncate(profile?.display_name || profile?.name || hexToNpub(npub), {
length: 16
})