Compare commits
30 Commits
b8ba8d0ab4
...
f162baadbb
Author | SHA1 | Date | |
---|---|---|---|
f162baadbb | |||
3a6c5ae8e3 | |||
55bf90e93c | |||
79f37a842f | |||
ed7acd6cb4 | |||
b22f577cc2 | |||
2becab9f79 | |||
7d3daa8d13 | |||
bff590f532 | |||
2f29ea9f35 | |||
d41d577c29 | |||
1c3d3ca88f | |||
d8adb2c744 | |||
3743a30ef6 | |||
4b04bdf39e | |||
01ca81be2a | |||
64dbd7d479 | |||
50c8f2b2d0 | |||
dfe67b99ad | |||
97c82718cb | |||
5ffedb68d6 | |||
b3155cce0d | |||
e16b8cfe3f | |||
bc23361fb0 | |||
d9779c10bd | |||
6d881ccb45 | |||
3549b6e542 | |||
4c04c12403 | |||
0d52cd7113 | |||
ed0158e817 |
@ -1,9 +1,6 @@
|
|||||||
import { useEffect, useState } from 'react'
|
import { Meta } from '../../types'
|
||||||
import { Meta, ProfileMetadata } from '../../types'
|
|
||||||
import { SigitCardDisplayInfo, SigitStatus } from '../../utils'
|
import { SigitCardDisplayInfo, SigitStatus } from '../../utils'
|
||||||
import { Event, kinds } from 'nostr-tools'
|
|
||||||
import { Link } from 'react-router-dom'
|
import { Link } from 'react-router-dom'
|
||||||
import { MetadataController } from '../../controllers'
|
|
||||||
import { formatTimestamp, hexToNpub, npubToHex, shorten } from '../../utils'
|
import { formatTimestamp, hexToNpub, npubToHex, shorten } from '../../utils'
|
||||||
import { appPublicRoutes, appPrivateRoutes } from '../../routes'
|
import { appPublicRoutes, appPrivateRoutes } from '../../routes'
|
||||||
import { Button, Divider, Tooltip } from '@mui/material'
|
import { Button, Divider, Tooltip } from '@mui/material'
|
||||||
@ -22,6 +19,8 @@ import { UserAvatarGroup } from '../UserAvatarGroup'
|
|||||||
import styles from './style.module.scss'
|
import styles from './style.module.scss'
|
||||||
import { TooltipChild } from '../TooltipChild'
|
import { TooltipChild } from '../TooltipChild'
|
||||||
import { getExtensionIconLabel } from '../getExtensionIconLabel'
|
import { getExtensionIconLabel } from '../getExtensionIconLabel'
|
||||||
|
import { useSigitProfiles } from '../../hooks/useSigitProfiles'
|
||||||
|
import { useSigitMeta } from '../../hooks/useSigitMeta'
|
||||||
|
|
||||||
type SigitProps = {
|
type SigitProps = {
|
||||||
meta: Meta
|
meta: Meta
|
||||||
@ -38,61 +37,12 @@ export const DisplaySigit = ({ meta, parsedMeta }: SigitProps) => {
|
|||||||
fileExtensions
|
fileExtensions
|
||||||
} = parsedMeta
|
} = parsedMeta
|
||||||
|
|
||||||
const [profiles, setProfiles] = useState<{ [key: string]: ProfileMetadata }>(
|
const { signersStatus } = useSigitMeta(meta)
|
||||||
{}
|
|
||||||
)
|
|
||||||
|
|
||||||
useEffect(() => {
|
const profiles = useSigitProfiles([
|
||||||
const hexKeys = new Set<string>([
|
...(submittedBy ? [submittedBy] : []),
|
||||||
...signers.map((signer) => npubToHex(signer)!)
|
...signers
|
||||||
])
|
])
|
||||||
|
|
||||||
if (submittedBy) {
|
|
||||||
hexKeys.add(npubToHex(submittedBy)!)
|
|
||||||
}
|
|
||||||
|
|
||||||
const metadataController = new MetadataController()
|
|
||||||
|
|
||||||
const handleMetadataEvent = (key: string) => (event: Event) => {
|
|
||||||
const metadataContent =
|
|
||||||
metadataController.extractProfileMetadataContent(event)
|
|
||||||
|
|
||||||
if (metadataContent) {
|
|
||||||
setProfiles((prev) => ({
|
|
||||||
...prev,
|
|
||||||
[key]: metadataContent
|
|
||||||
}))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const handleEventListener =
|
|
||||||
(key: string) => (kind: number, event: Event) => {
|
|
||||||
if (kind === kinds.Metadata) {
|
|
||||||
handleMetadataEvent(key)(event)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
hexKeys.forEach((key) => {
|
|
||||||
if (!(key in profiles)) {
|
|
||||||
metadataController.on(key, handleEventListener(key))
|
|
||||||
|
|
||||||
metadataController
|
|
||||||
.findMetadata(key)
|
|
||||||
.then((metadataEvent) => {
|
|
||||||
if (metadataEvent) handleMetadataEvent(key)(metadataEvent)
|
|
||||||
})
|
|
||||||
.catch((err) => {
|
|
||||||
console.error(`error occurred in finding metadata for: ${key}`, err)
|
|
||||||
})
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
return () => {
|
|
||||||
hexKeys.forEach((key) => {
|
|
||||||
metadataController.off(key, handleEventListener(key))
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}, [submittedBy, signers, profiles])
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className={styles.itemWrapper}>
|
<div className={styles.itemWrapper}>
|
||||||
@ -130,7 +80,7 @@ export const DisplaySigit = ({ meta, parsedMeta }: SigitProps) => {
|
|||||||
{submittedBy && signers.length ? (
|
{submittedBy && signers.length ? (
|
||||||
<Divider orientation="vertical" flexItem />
|
<Divider orientation="vertical" flexItem />
|
||||||
) : null}
|
) : null}
|
||||||
<UserAvatarGroup className={styles.signers} max={7}>
|
<UserAvatarGroup max={7}>
|
||||||
{signers.map((signer) => {
|
{signers.map((signer) => {
|
||||||
const pubkey = npubToHex(signer)!
|
const pubkey = npubToHex(signer)!
|
||||||
const profile = profiles[pubkey]
|
const profile = profiles[pubkey]
|
||||||
@ -147,7 +97,7 @@ export const DisplaySigit = ({ meta, parsedMeta }: SigitProps) => {
|
|||||||
>
|
>
|
||||||
<TooltipChild>
|
<TooltipChild>
|
||||||
<DisplaySigner
|
<DisplaySigner
|
||||||
meta={meta}
|
status={signersStatus[signer]}
|
||||||
profile={profile}
|
profile={profile}
|
||||||
pubkey={pubkey}
|
pubkey={pubkey}
|
||||||
/>
|
/>
|
||||||
|
@ -93,26 +93,6 @@
|
|||||||
grid-gap: 10px;
|
grid-gap: 10px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.signers {
|
|
||||||
padding: 0 0 0 10px;
|
|
||||||
|
|
||||||
> * {
|
|
||||||
transition: margin ease 0.2s;
|
|
||||||
margin: 0 0 0 -10px;
|
|
||||||
position: relative;
|
|
||||||
z-index: 1;
|
|
||||||
&:first-child {
|
|
||||||
margin-left: -10px !important;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
> *:hover,
|
|
||||||
> *:focus-within {
|
|
||||||
margin: 0 15px 0 5px;
|
|
||||||
z-index: 2;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
.details {
|
.details {
|
||||||
color: rgba(0, 0, 0, 0.3);
|
color: rgba(0, 0, 0, 0.3);
|
||||||
font-size: 14px;
|
font-size: 14px;
|
||||||
|
@ -1,58 +1,51 @@
|
|||||||
import { Badge } from '@mui/material'
|
import { Badge } from '@mui/material'
|
||||||
import { Event, verifyEvent } from 'nostr-tools'
|
import { ProfileMetadata } from '../../types'
|
||||||
import { useState, useEffect } from 'react'
|
|
||||||
import { Meta, ProfileMetadata } from '../../types'
|
|
||||||
import { hexToNpub, parseJson } from '../../utils'
|
|
||||||
import styles from './style.module.scss'
|
import styles from './style.module.scss'
|
||||||
import { UserAvatar } from '../UserAvatar'
|
import { UserAvatar } from '../UserAvatar'
|
||||||
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'
|
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'
|
||||||
import { faCheck, faExclamation } from '@fortawesome/free-solid-svg-icons'
|
import {
|
||||||
|
faCheck,
|
||||||
enum SignStatus {
|
faEllipsis,
|
||||||
Signed = 'Signed',
|
faExclamation,
|
||||||
Pending = 'Pending',
|
faEye,
|
||||||
Invalid = 'Invalid Sign'
|
faHourglass,
|
||||||
}
|
faQuestion
|
||||||
|
} from '@fortawesome/free-solid-svg-icons'
|
||||||
|
import { SignStatus } from '../../utils'
|
||||||
|
import { Spinner } from '../Spinner'
|
||||||
|
|
||||||
type DisplaySignerProps = {
|
type DisplaySignerProps = {
|
||||||
meta: Meta
|
|
||||||
profile: ProfileMetadata
|
profile: ProfileMetadata
|
||||||
pubkey: string
|
pubkey: string
|
||||||
|
status: SignStatus
|
||||||
}
|
}
|
||||||
|
|
||||||
export const DisplaySigner = ({
|
export const DisplaySigner = ({
|
||||||
meta,
|
status,
|
||||||
profile,
|
profile,
|
||||||
pubkey
|
pubkey
|
||||||
}: DisplaySignerProps) => {
|
}: DisplaySignerProps) => {
|
||||||
const [signStatus, setSignedStatus] = useState<SignStatus>()
|
const getStatusIcon = (status: SignStatus) => {
|
||||||
|
switch (status) {
|
||||||
|
case SignStatus.Signed:
|
||||||
|
return <FontAwesomeIcon icon={faCheck} />
|
||||||
|
case SignStatus.Awaiting:
|
||||||
|
return (
|
||||||
|
<Spinner>
|
||||||
|
<FontAwesomeIcon icon={faHourglass} />
|
||||||
|
</Spinner>
|
||||||
|
)
|
||||||
|
case SignStatus.Pending:
|
||||||
|
return <FontAwesomeIcon icon={faEllipsis} />
|
||||||
|
case SignStatus.Invalid:
|
||||||
|
return <FontAwesomeIcon icon={faExclamation} />
|
||||||
|
case SignStatus.Viewer:
|
||||||
|
return <FontAwesomeIcon icon={faEye} />
|
||||||
|
|
||||||
useEffect(() => {
|
default:
|
||||||
if (!meta) return
|
return <FontAwesomeIcon icon={faQuestion} />
|
||||||
|
|
||||||
const updateSignStatus = async () => {
|
|
||||||
const npub = hexToNpub(pubkey)
|
|
||||||
if (npub in meta.docSignatures) {
|
|
||||||
parseJson<Event>(meta.docSignatures[npub])
|
|
||||||
.then((event) => {
|
|
||||||
const isValidSignature = verifyEvent(event)
|
|
||||||
if (isValidSignature) {
|
|
||||||
setSignedStatus(SignStatus.Signed)
|
|
||||||
} else {
|
|
||||||
setSignedStatus(SignStatus.Invalid)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.catch((err) => {
|
|
||||||
console.log(`err in parsing the docSignatures for ${npub}:>> `, err)
|
|
||||||
setSignedStatus(SignStatus.Invalid)
|
|
||||||
})
|
|
||||||
} else {
|
|
||||||
setSignedStatus(SignStatus.Pending)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
updateSignStatus()
|
|
||||||
}, [meta, pubkey])
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Badge
|
<Badge
|
||||||
@ -60,16 +53,7 @@ export const DisplaySigner = ({
|
|||||||
overlap="circular"
|
overlap="circular"
|
||||||
anchorOrigin={{ vertical: 'top', horizontal: 'right' }}
|
anchorOrigin={{ vertical: 'top', horizontal: 'right' }}
|
||||||
badgeContent={
|
badgeContent={
|
||||||
signStatus !== SignStatus.Pending && (
|
<div className={styles.statusBadge}>{getStatusIcon(status)}</div>
|
||||||
<div className={styles.statusBadge}>
|
|
||||||
{signStatus === SignStatus.Signed && (
|
|
||||||
<FontAwesomeIcon icon={faCheck} />
|
|
||||||
)}
|
|
||||||
{signStatus === SignStatus.Invalid && (
|
|
||||||
<FontAwesomeIcon icon={faExclamation} />
|
|
||||||
)}
|
|
||||||
</div>
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
>
|
>
|
||||||
<UserAvatar pubkey={pubkey} image={profile?.picture} />
|
<UserAvatar pubkey={pubkey} image={profile?.picture} />
|
||||||
|
@ -49,7 +49,7 @@ interface Props {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export const DrawPDFFields = (props: Props) => {
|
export const DrawPDFFields = (props: Props) => {
|
||||||
const { selectedFiles } = props
|
const { selectedFiles, onDrawFieldsChange, users } = props
|
||||||
|
|
||||||
const [pdfFiles, setPdfFiles] = useState<PdfFile[]>([])
|
const [pdfFiles, setPdfFiles] = useState<PdfFile[]>([])
|
||||||
const [parsingPdf, setParsingPdf] = useState<boolean>(false)
|
const [parsingPdf, setParsingPdf] = useState<boolean>(false)
|
||||||
@ -94,6 +94,15 @@ export const DrawPDFFields = (props: Props) => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
/**
|
||||||
|
* Reads the pdf binary files and converts it's pages to images
|
||||||
|
* creates the pdfFiles object and sets to a state
|
||||||
|
*/
|
||||||
|
const parsePdfPages = async () => {
|
||||||
|
const pdfFiles: PdfFile[] = await toPdfFiles(selectedFiles)
|
||||||
|
|
||||||
|
setPdfFiles(pdfFiles)
|
||||||
|
}
|
||||||
if (selectedFiles) {
|
if (selectedFiles) {
|
||||||
setParsingPdf(true)
|
setParsingPdf(true)
|
||||||
|
|
||||||
@ -104,8 +113,8 @@ export const DrawPDFFields = (props: Props) => {
|
|||||||
}, [selectedFiles])
|
}, [selectedFiles])
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (pdfFiles) props.onDrawFieldsChange(pdfFiles)
|
if (pdfFiles) onDrawFieldsChange(pdfFiles)
|
||||||
}, [pdfFiles])
|
}, [onDrawFieldsChange, pdfFiles])
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Drawing events
|
* Drawing events
|
||||||
@ -132,12 +141,16 @@ export const DrawPDFFields = (props: Props) => {
|
|||||||
* @param event Mouse event
|
* @param event Mouse event
|
||||||
* @param page PdfPage where press happened
|
* @param page PdfPage where press happened
|
||||||
*/
|
*/
|
||||||
const onMouseDown = (event: any, page: PdfPage) => {
|
const onMouseDown = (
|
||||||
|
event: React.MouseEvent<HTMLDivElement>,
|
||||||
|
page: PdfPage
|
||||||
|
) => {
|
||||||
// Proceed only if left click
|
// Proceed only if left click
|
||||||
if (event.button !== 0) return
|
if (event.button !== 0) return
|
||||||
|
|
||||||
// Only allow drawing if mouse is not over other drawn element
|
// Only allow drawing if mouse is not over other drawn element
|
||||||
const isOverPdfImageWrapper = event.target.tagName === 'IMG'
|
const target = event.target as HTMLElement
|
||||||
|
const isOverPdfImageWrapper = target.tagName === 'IMG'
|
||||||
|
|
||||||
if (!selectedTool || !isOverPdfImageWrapper) {
|
if (!selectedTool || !isOverPdfImageWrapper) {
|
||||||
return
|
return
|
||||||
@ -185,7 +198,10 @@ export const DrawPDFFields = (props: Props) => {
|
|||||||
* @param event Mouse event
|
* @param event Mouse event
|
||||||
* @param page PdfPage where moving is happening
|
* @param page PdfPage where moving is happening
|
||||||
*/
|
*/
|
||||||
const onMouseMove = (event: any, page: PdfPage) => {
|
const onMouseMove = (
|
||||||
|
event: React.MouseEvent<HTMLDivElement>,
|
||||||
|
page: PdfPage
|
||||||
|
) => {
|
||||||
if (mouseState.clicked && selectedTool) {
|
if (mouseState.clicked && selectedTool) {
|
||||||
const lastElementIndex = page.drawnFields.length - 1
|
const lastElementIndex = page.drawnFields.length - 1
|
||||||
const lastDrawnField = page.drawnFields[lastElementIndex]
|
const lastDrawnField = page.drawnFields[lastElementIndex]
|
||||||
@ -216,7 +232,7 @@ export const DrawPDFFields = (props: Props) => {
|
|||||||
* @param event Mouse event
|
* @param event Mouse event
|
||||||
* @param drawnField Which we are moving
|
* @param drawnField Which we are moving
|
||||||
*/
|
*/
|
||||||
const onDrawnFieldMouseDown = (event: any) => {
|
const onDrawnFieldMouseDown = (event: React.MouseEvent<HTMLDivElement>) => {
|
||||||
event.stopPropagation()
|
event.stopPropagation()
|
||||||
|
|
||||||
// Proceed only if left click
|
// Proceed only if left click
|
||||||
@ -239,11 +255,15 @@ export const DrawPDFFields = (props: Props) => {
|
|||||||
* @param event Mouse event
|
* @param event Mouse event
|
||||||
* @param drawnField which we are moving
|
* @param drawnField which we are moving
|
||||||
*/
|
*/
|
||||||
const onDranwFieldMouseMove = (event: any, drawnField: DrawnField) => {
|
const onDranwFieldMouseMove = (
|
||||||
|
event: React.MouseEvent<HTMLDivElement>,
|
||||||
|
drawnField: DrawnField
|
||||||
|
) => {
|
||||||
|
const target = event.target as HTMLElement | null
|
||||||
if (mouseState.dragging) {
|
if (mouseState.dragging) {
|
||||||
const { mouseX, mouseY, rect } = getMouseCoordinates(
|
const { mouseX, mouseY, rect } = getMouseCoordinates(
|
||||||
event,
|
event,
|
||||||
event.target.parentNode
|
target?.parentNode as HTMLElement
|
||||||
)
|
)
|
||||||
const coordsOffset = mouseState.coordsInWrapper
|
const coordsOffset = mouseState.coordsInWrapper
|
||||||
|
|
||||||
@ -272,7 +292,7 @@ export const DrawPDFFields = (props: Props) => {
|
|||||||
* @param event Mouse event
|
* @param event Mouse event
|
||||||
* @param drawnField which we are resizing
|
* @param drawnField which we are resizing
|
||||||
*/
|
*/
|
||||||
const onResizeHandleMouseDown = (event: any) => {
|
const onResizeHandleMouseDown = (event: React.MouseEvent<HTMLDivElement>) => {
|
||||||
// Proceed only if left click
|
// Proceed only if left click
|
||||||
if (event.button !== 0) return
|
if (event.button !== 0) return
|
||||||
|
|
||||||
@ -288,11 +308,15 @@ export const DrawPDFFields = (props: Props) => {
|
|||||||
* @param event Mouse event
|
* @param event Mouse event
|
||||||
* @param drawnField which we are resizing
|
* @param drawnField which we are resizing
|
||||||
*/
|
*/
|
||||||
const onResizeHandleMouseMove = (event: any, drawnField: DrawnField) => {
|
const onResizeHandleMouseMove = (
|
||||||
|
event: React.MouseEvent<HTMLSpanElement | HTMLDivElement>,
|
||||||
|
drawnField: DrawnField
|
||||||
|
) => {
|
||||||
|
const target = event.target as HTMLElement | null
|
||||||
if (mouseState.resizing) {
|
if (mouseState.resizing) {
|
||||||
const { mouseX, mouseY } = getMouseCoordinates(
|
const { mouseX, mouseY } = getMouseCoordinates(
|
||||||
event,
|
event,
|
||||||
event.target.parentNode.parentNode
|
target?.parentNode?.parentNode as HTMLElement
|
||||||
)
|
)
|
||||||
|
|
||||||
const width = mouseX - drawnField.left
|
const width = mouseX - drawnField.left
|
||||||
@ -313,7 +337,7 @@ export const DrawPDFFields = (props: Props) => {
|
|||||||
* @param drawnFileIndex drawn file index
|
* @param drawnFileIndex drawn file index
|
||||||
*/
|
*/
|
||||||
const onRemoveHandleMouseDown = (
|
const onRemoveHandleMouseDown = (
|
||||||
event: any,
|
event: React.MouseEvent<HTMLDivElement | HTMLSpanElement>,
|
||||||
pdfFileIndex: number,
|
pdfFileIndex: number,
|
||||||
pdfPageIndex: number,
|
pdfPageIndex: number,
|
||||||
drawnFileIndex: number
|
drawnFileIndex: number
|
||||||
@ -331,7 +355,9 @@ export const DrawPDFFields = (props: Props) => {
|
|||||||
* so select can work properly
|
* so select can work properly
|
||||||
* @param event Mouse event
|
* @param event Mouse event
|
||||||
*/
|
*/
|
||||||
const onUserSelectHandleMouseDown = (event: any) => {
|
const onUserSelectHandleMouseDown = (
|
||||||
|
event: React.MouseEvent<HTMLDivElement>
|
||||||
|
) => {
|
||||||
event.stopPropagation()
|
event.stopPropagation()
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -341,8 +367,11 @@ export const DrawPDFFields = (props: Props) => {
|
|||||||
* @param customTarget mouse coordinates relative to this element, if not provided
|
* @param customTarget mouse coordinates relative to this element, if not provided
|
||||||
* event.target will be used
|
* event.target will be used
|
||||||
*/
|
*/
|
||||||
const getMouseCoordinates = (event: any, customTarget?: any) => {
|
const getMouseCoordinates = (
|
||||||
const target = customTarget ? customTarget : event.target
|
event: React.MouseEvent<HTMLDivElement | HTMLSpanElement>,
|
||||||
|
customTarget?: HTMLElement
|
||||||
|
) => {
|
||||||
|
const target = (customTarget ? customTarget : event.target) as HTMLElement
|
||||||
const rect = target.getBoundingClientRect()
|
const rect = target.getBoundingClientRect()
|
||||||
const mouseX = event.clientX - rect.left //x position within the element.
|
const mouseX = event.clientX - rect.left //x position within the element.
|
||||||
const mouseY = event.clientY - rect.top //y position within the element.
|
const mouseY = event.clientY - rect.top //y position within the element.
|
||||||
@ -354,16 +383,6 @@ export const DrawPDFFields = (props: Props) => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Reads the pdf binary files and converts it's pages to images
|
|
||||||
* creates the pdfFiles object and sets to a state
|
|
||||||
*/
|
|
||||||
const parsePdfPages = async () => {
|
|
||||||
const pdfFiles: PdfFile[] = await toPdfFiles(selectedFiles)
|
|
||||||
|
|
||||||
setPdfFiles(pdfFiles)
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @returns if expanded pdf accordion is present
|
* @returns if expanded pdf accordion is present
|
||||||
@ -477,7 +496,7 @@ export const DrawPDFFields = (props: Props) => {
|
|||||||
labelId="counterparts"
|
labelId="counterparts"
|
||||||
label="Counterparts"
|
label="Counterparts"
|
||||||
>
|
>
|
||||||
{props.users.map((user, index) => {
|
{users.map((user, index) => {
|
||||||
let displayValue = truncate(
|
let displayValue = truncate(
|
||||||
hexToNpub(user.pubkey),
|
hexToNpub(user.pubkey),
|
||||||
{
|
{
|
||||||
|
@ -51,6 +51,14 @@
|
|||||||
position: relative;
|
position: relative;
|
||||||
-webkit-user-select: none;
|
-webkit-user-select: none;
|
||||||
user-select: none;
|
user-select: none;
|
||||||
|
margin-bottom: 10px;
|
||||||
|
|
||||||
|
> img {
|
||||||
|
display: block;
|
||||||
|
max-width: 100%;
|
||||||
|
max-height: 100%;
|
||||||
|
object-fit: contain; /* Ensure the image fits within the container */
|
||||||
|
}
|
||||||
|
|
||||||
&.drawing {
|
&.drawing {
|
||||||
cursor: crosshair;
|
cursor: crosshair;
|
||||||
@ -72,6 +80,10 @@
|
|||||||
visibility: hidden;
|
visibility: hidden;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
&.edited {
|
||||||
|
border: 1px dotted #01aaad
|
||||||
|
}
|
||||||
|
|
||||||
.resizeHandle {
|
.resizeHandle {
|
||||||
position: absolute;
|
position: absolute;
|
||||||
right: -5px;
|
right: -5px;
|
||||||
|
50
src/components/FileList/index.tsx
Normal file
50
src/components/FileList/index.tsx
Normal file
@ -0,0 +1,50 @@
|
|||||||
|
import { CurrentUserFile } from '../../types/file.ts'
|
||||||
|
import styles from './style.module.scss'
|
||||||
|
import { Button } from '@mui/material'
|
||||||
|
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'
|
||||||
|
import { faCheck } from '@fortawesome/free-solid-svg-icons'
|
||||||
|
|
||||||
|
interface FileListProps {
|
||||||
|
files: CurrentUserFile[]
|
||||||
|
currentFile: CurrentUserFile
|
||||||
|
setCurrentFile: (file: CurrentUserFile) => void
|
||||||
|
handleDownload: () => void
|
||||||
|
}
|
||||||
|
|
||||||
|
const FileList = ({
|
||||||
|
files,
|
||||||
|
currentFile,
|
||||||
|
setCurrentFile,
|
||||||
|
handleDownload
|
||||||
|
}: FileListProps) => {
|
||||||
|
const isActive = (file: CurrentUserFile) => file.id === currentFile.id
|
||||||
|
return (
|
||||||
|
<div className={styles.wrap}>
|
||||||
|
<div className={styles.container}>
|
||||||
|
<ul className={styles.files}>
|
||||||
|
{files.map((file: CurrentUserFile) => (
|
||||||
|
<li
|
||||||
|
key={file.id}
|
||||||
|
className={`${styles.fileItem} ${isActive(file) && styles.active}`}
|
||||||
|
onClick={() => setCurrentFile(file)}
|
||||||
|
>
|
||||||
|
<div className={styles.fileNumber}>{file.id}</div>
|
||||||
|
<div className={styles.fileInfo}>
|
||||||
|
<div className={styles.fileName}>{file.filename}</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className={styles.fileVisual}>
|
||||||
|
{file.isHashValid && <FontAwesomeIcon icon={faCheck} />}
|
||||||
|
</div>
|
||||||
|
</li>
|
||||||
|
))}
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
|
<Button variant="contained" fullWidth onClick={handleDownload}>
|
||||||
|
Download Files
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
export default FileList
|
123
src/components/FileList/style.module.scss
Normal file
123
src/components/FileList/style.module.scss
Normal file
@ -0,0 +1,123 @@
|
|||||||
|
.container {
|
||||||
|
border-radius: 4px;
|
||||||
|
background: white;
|
||||||
|
padding: 15px;
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
grid-gap: 0px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.filesPageContainer {
|
||||||
|
width: 100%;
|
||||||
|
display: grid;
|
||||||
|
grid-template-columns: 0.75fr 1.5fr 0.75fr;
|
||||||
|
grid-gap: 30px;
|
||||||
|
flex-grow: 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
ul {
|
||||||
|
list-style-type: none; /* Removes bullet points */
|
||||||
|
margin: 0; /* Removes default margin */
|
||||||
|
padding: 0; /* Removes default padding */
|
||||||
|
}
|
||||||
|
|
||||||
|
li {
|
||||||
|
list-style-type: none; /* Removes the bullets */
|
||||||
|
margin: 0; /* Removes any default margin */
|
||||||
|
padding: 0; /* Removes any default padding */
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
.wrap {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
grid-gap: 15px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.files {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
width: 100%;
|
||||||
|
grid-gap: 15px;
|
||||||
|
max-height: 350px;
|
||||||
|
overflow: auto;
|
||||||
|
padding: 0 5px 0 0;
|
||||||
|
margin: 0 -5px 0 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.files::-webkit-scrollbar {
|
||||||
|
width: 10px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.files::-webkit-scrollbar-track {
|
||||||
|
background-color: rgba(0,0,0,0.15);
|
||||||
|
}
|
||||||
|
|
||||||
|
.files::-webkit-scrollbar-thumb {
|
||||||
|
max-width: 10px;
|
||||||
|
border-radius: 2px;
|
||||||
|
background-color: #4c82a3;
|
||||||
|
cursor: grab;
|
||||||
|
}
|
||||||
|
|
||||||
|
.fileItem {
|
||||||
|
transition: ease 0.2s;
|
||||||
|
display: flex;
|
||||||
|
flex-direction: row;
|
||||||
|
grid-gap: 10px;
|
||||||
|
border-radius: 4px;
|
||||||
|
overflow: hidden;
|
||||||
|
background: #ffffff;
|
||||||
|
padding: 5px 10px;
|
||||||
|
align-items: center;
|
||||||
|
color: rgba(0,0,0,0.5);
|
||||||
|
cursor: pointer;
|
||||||
|
flex-grow: 1;
|
||||||
|
font-size: 16px;
|
||||||
|
font-weight: 500;
|
||||||
|
|
||||||
|
|
||||||
|
&.active {
|
||||||
|
background: #4c82a3;
|
||||||
|
color: white;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.fileItem:hover {
|
||||||
|
transition: ease 0.2s;
|
||||||
|
background: #4c82a3;
|
||||||
|
color: white;
|
||||||
|
}
|
||||||
|
|
||||||
|
.fileInfo {
|
||||||
|
flex-grow: 1;
|
||||||
|
font-size: 16px;
|
||||||
|
font-weight: 500;
|
||||||
|
}
|
||||||
|
|
||||||
|
.fileName {
|
||||||
|
display: -webkit-box;
|
||||||
|
-webkit-box-orient: vertical;
|
||||||
|
overflow: hidden;
|
||||||
|
-webkit-line-clamp: 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
.fileNumber {
|
||||||
|
font-size: 14px;
|
||||||
|
font-weight: 500;
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
justify-content: center;
|
||||||
|
align-items: center;
|
||||||
|
width: 10px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.fileVisual {
|
||||||
|
display: flex;
|
||||||
|
flex-shrink: 0;
|
||||||
|
flex-direction: column;
|
||||||
|
justify-content: center;
|
||||||
|
align-items: center;
|
||||||
|
height: 25px;
|
||||||
|
width: 25px;
|
||||||
|
}
|
126
src/components/MarkFormField/index.tsx
Normal file
126
src/components/MarkFormField/index.tsx
Normal file
@ -0,0 +1,126 @@
|
|||||||
|
import { CurrentUserMark } from '../../types/mark.ts'
|
||||||
|
import styles from './style.module.scss'
|
||||||
|
|
||||||
|
import { MARK_TYPE_TRANSLATION, NEXT, SIGN } from '../../utils/const.ts'
|
||||||
|
import {
|
||||||
|
findNextIncompleteCurrentUserMark,
|
||||||
|
isCurrentUserMarksComplete,
|
||||||
|
isCurrentValueLast
|
||||||
|
} from '../../utils'
|
||||||
|
import React, { useState } from 'react'
|
||||||
|
|
||||||
|
interface MarkFormFieldProps {
|
||||||
|
currentUserMarks: CurrentUserMark[]
|
||||||
|
handleCurrentUserMarkChange: (mark: CurrentUserMark) => void
|
||||||
|
handleSelectedMarkValueChange: (
|
||||||
|
event: React.ChangeEvent<HTMLInputElement>
|
||||||
|
) => void
|
||||||
|
handleSubmit: (event: React.FormEvent<HTMLFormElement>) => void
|
||||||
|
selectedMark: CurrentUserMark
|
||||||
|
selectedMarkValue: string
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Responsible for rendering a form field connected to a mark and keeping track of its value.
|
||||||
|
*/
|
||||||
|
const MarkFormField = ({
|
||||||
|
handleSubmit,
|
||||||
|
handleSelectedMarkValueChange,
|
||||||
|
selectedMark,
|
||||||
|
selectedMarkValue,
|
||||||
|
currentUserMarks,
|
||||||
|
handleCurrentUserMarkChange
|
||||||
|
}: MarkFormFieldProps) => {
|
||||||
|
const [displayActions, setDisplayActions] = useState(true)
|
||||||
|
const getSubmitButtonText = () => (isReadyToSign() ? SIGN : NEXT)
|
||||||
|
const isReadyToSign = () =>
|
||||||
|
isCurrentUserMarksComplete(currentUserMarks) ||
|
||||||
|
isCurrentValueLast(currentUserMarks, selectedMark, selectedMarkValue)
|
||||||
|
const isCurrent = (currentMark: CurrentUserMark) =>
|
||||||
|
currentMark.id === selectedMark.id
|
||||||
|
const isDone = (currentMark: CurrentUserMark) =>
|
||||||
|
isCurrent(currentMark) ? !!selectedMarkValue : currentMark.isCompleted
|
||||||
|
const findNext = () => {
|
||||||
|
return (
|
||||||
|
currentUserMarks[selectedMark.id] ||
|
||||||
|
findNextIncompleteCurrentUserMark(currentUserMarks)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
const handleFormSubmit = (event: React.FormEvent<HTMLFormElement>) => {
|
||||||
|
event.preventDefault()
|
||||||
|
console.log('handle form submit runs...')
|
||||||
|
return isReadyToSign()
|
||||||
|
? handleSubmit(event)
|
||||||
|
: handleCurrentUserMarkChange(findNext()!)
|
||||||
|
}
|
||||||
|
const toggleActions = () => setDisplayActions(!displayActions)
|
||||||
|
return (
|
||||||
|
<div className={styles.container}>
|
||||||
|
<div className={styles.trigger}>
|
||||||
|
<button
|
||||||
|
onClick={toggleActions}
|
||||||
|
className={styles.triggerBtn}
|
||||||
|
type="button"
|
||||||
|
>
|
||||||
|
<svg
|
||||||
|
xmlns="http://www.w3.org/2000/svg"
|
||||||
|
viewBox="-64 0 512 512"
|
||||||
|
width="1em"
|
||||||
|
height="1em"
|
||||||
|
fill="currentColor"
|
||||||
|
transform={displayActions ? 'rotate(180)' : 'rotate(0)'}
|
||||||
|
>
|
||||||
|
<path d="M352 352c-8.188 0-16.38-3.125-22.62-9.375L192 205.3l-137.4 137.4c-12.5 12.5-32.75 12.5-45.25 0s-12.5-32.75 0-45.25l160-160c12.5-12.5 32.75-12.5 45.25 0l160 160c12.5 12.5 12.5 32.75 0 45.25C368.4 348.9 360.2 352 352 352z"></path>
|
||||||
|
</svg>
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
<div className={`${styles.actions} ${displayActions && styles.expanded}`}>
|
||||||
|
<div className={styles.actionsWrapper}>
|
||||||
|
<div className={styles.actionsTop}>
|
||||||
|
<div className={styles.actionsTopInfo}>
|
||||||
|
<p className={styles.actionsTopInfoText}>Add your signature</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div className={styles.inputWrapper}>
|
||||||
|
<form onSubmit={(e) => handleFormSubmit(e)}>
|
||||||
|
<input
|
||||||
|
className={styles.input}
|
||||||
|
placeholder={
|
||||||
|
MARK_TYPE_TRANSLATION[selectedMark.mark.type.valueOf()]
|
||||||
|
}
|
||||||
|
onChange={handleSelectedMarkValueChange}
|
||||||
|
value={selectedMarkValue}
|
||||||
|
/>
|
||||||
|
<div className={styles.actionsBottom}>
|
||||||
|
<button type="submit" className={styles.submitButton}>
|
||||||
|
{getSubmitButtonText()}
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
<div className={styles.footerContainer}>
|
||||||
|
<div className={styles.footer}>
|
||||||
|
{currentUserMarks.map((mark, index) => {
|
||||||
|
return (
|
||||||
|
<div className={styles.pagination} key={index}>
|
||||||
|
<button
|
||||||
|
className={`${styles.paginationButton} ${isDone(mark) && styles.paginationButtonDone}`}
|
||||||
|
onClick={() => handleCurrentUserMarkChange(mark)}
|
||||||
|
>
|
||||||
|
{mark.id}
|
||||||
|
</button>
|
||||||
|
{isCurrent(mark) && (
|
||||||
|
<div className={styles.paginationButtonCurrent}></div>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
})}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
export default MarkFormField
|
210
src/components/MarkFormField/style.module.scss
Normal file
210
src/components/MarkFormField/style.module.scss
Normal file
@ -0,0 +1,210 @@
|
|||||||
|
.container {
|
||||||
|
width: 100%;
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
position: fixed;
|
||||||
|
bottom: 0;
|
||||||
|
right: 0;
|
||||||
|
left: 0;
|
||||||
|
align-items: center;
|
||||||
|
z-index: 1000;
|
||||||
|
}
|
||||||
|
|
||||||
|
.actions {
|
||||||
|
background: white;
|
||||||
|
width: 100%;
|
||||||
|
border-radius: 4px;
|
||||||
|
padding: 10px 20px;
|
||||||
|
display: none;
|
||||||
|
flex-direction: column;
|
||||||
|
align-items: center;
|
||||||
|
grid-gap: 15px;
|
||||||
|
box-shadow: 0 -2px 4px 0 rgb(0,0,0,0.1);
|
||||||
|
max-width: 750px;
|
||||||
|
|
||||||
|
&.expanded {
|
||||||
|
display: flex;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.actionsWrapper {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
grid-gap: 20px;
|
||||||
|
flex-grow: 1;
|
||||||
|
width: 100%;
|
||||||
|
}
|
||||||
|
|
||||||
|
.actionsTop {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: row;
|
||||||
|
grid-gap: 10px;
|
||||||
|
align-items: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
.actionsTopInfo {
|
||||||
|
flex-grow: 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
.actionsTopInfoText {
|
||||||
|
font-size: 16px;
|
||||||
|
color: #434343;
|
||||||
|
}
|
||||||
|
|
||||||
|
.actionsTrigger {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
justify-content: center;
|
||||||
|
align-items: center;
|
||||||
|
position: relative;
|
||||||
|
}
|
||||||
|
|
||||||
|
.actionButtons {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: row;
|
||||||
|
grid-gap: 5px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.inputWrapper {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
grid-gap: 10px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.textInput {
|
||||||
|
height: 100px;
|
||||||
|
background: rgba(0,0,0,0.1);
|
||||||
|
border-radius: 4px;
|
||||||
|
border: solid 2px #4c82a3;
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
justify-content: center;
|
||||||
|
align-items: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
.input {
|
||||||
|
border-radius: 4px;
|
||||||
|
border: solid 1px rgba(0,0,0,0.15);
|
||||||
|
padding: 5px 10px;
|
||||||
|
font-size: 16px;
|
||||||
|
width: 100%;
|
||||||
|
background: linear-gradient(rgba(0,0,0,0.00), rgba(0,0,0,0.00) 100%), linear-gradient(white, white);
|
||||||
|
}
|
||||||
|
|
||||||
|
.input:focus {
|
||||||
|
border: solid 1px rgba(0,0,0,0.15);
|
||||||
|
outline: none;
|
||||||
|
background: linear-gradient(rgba(0,0,0,0.05), rgba(0,0,0,0.05) 100%), linear-gradient(white, white);
|
||||||
|
}
|
||||||
|
|
||||||
|
.actionsBottom {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: row;
|
||||||
|
grid-gap: 5px;
|
||||||
|
justify-content: center;
|
||||||
|
align-items: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
button {
|
||||||
|
transition: ease 0.2s;
|
||||||
|
width: auto;
|
||||||
|
border-radius: 4px;
|
||||||
|
outline: unset;
|
||||||
|
border: unset;
|
||||||
|
background: unset;
|
||||||
|
color: #ffffff;
|
||||||
|
background: #4c82a3;
|
||||||
|
font-weight: 500;
|
||||||
|
font-size: 14px;
|
||||||
|
padding: 8px 15px;
|
||||||
|
white-space: nowrap;
|
||||||
|
display: flex;
|
||||||
|
flex-direction: row;
|
||||||
|
grid-gap: 12px;
|
||||||
|
justify-content: center;
|
||||||
|
align-items: center;
|
||||||
|
text-decoration: unset;
|
||||||
|
position: relative;
|
||||||
|
cursor: pointer;
|
||||||
|
}
|
||||||
|
|
||||||
|
button:hover {
|
||||||
|
transition: ease 0.2s;
|
||||||
|
background: #5e8eab;
|
||||||
|
color: white;
|
||||||
|
}
|
||||||
|
|
||||||
|
button:active {
|
||||||
|
transition: ease 0.2s;
|
||||||
|
background: #447592;
|
||||||
|
color: white;
|
||||||
|
}
|
||||||
|
|
||||||
|
.submitButton {
|
||||||
|
width: 100%;
|
||||||
|
max-width: 300px;
|
||||||
|
margin-top: 10px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.footerContainer {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: row;
|
||||||
|
justify-content: center;
|
||||||
|
align-items: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
.footer {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: row;
|
||||||
|
grid-gap: 5px;
|
||||||
|
align-items: start;
|
||||||
|
justify-content: center;
|
||||||
|
width: 100%;
|
||||||
|
}
|
||||||
|
|
||||||
|
.pagination {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
grid-gap: 5px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.paginationButton {
|
||||||
|
font-size: 12px;
|
||||||
|
padding: 5px 10px;
|
||||||
|
border-radius: 3px;
|
||||||
|
background: rgba(0,0,0,0.1);
|
||||||
|
color: rgba(0,0,0,0.5);
|
||||||
|
}
|
||||||
|
|
||||||
|
.paginationButton:hover {
|
||||||
|
background: #447592;
|
||||||
|
color: rgba(255,255,255,0.5);
|
||||||
|
}
|
||||||
|
|
||||||
|
.paginationButtonDone {
|
||||||
|
background: #5e8eab;
|
||||||
|
color: rgb(255,255,255);
|
||||||
|
}
|
||||||
|
|
||||||
|
.paginationButtonCurrent {
|
||||||
|
height: 2px;
|
||||||
|
width: 100%;
|
||||||
|
background: #4c82a3;
|
||||||
|
}
|
||||||
|
|
||||||
|
.trigger {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
justify-content: center;
|
||||||
|
align-items: center;
|
||||||
|
position: relative;
|
||||||
|
}
|
||||||
|
|
||||||
|
.triggerBtn {
|
||||||
|
background: white;
|
||||||
|
color: #434343;
|
||||||
|
padding: 5px 30px;
|
||||||
|
box-shadow: 0px -3px 4px 0 rgb(0,0,0,0.1);
|
||||||
|
position: absolute;
|
||||||
|
top: -25px;
|
||||||
|
}
|
@ -20,14 +20,13 @@ const PdfMarkItem = ({
|
|||||||
}: PdfMarkItemProps) => {
|
}: PdfMarkItemProps) => {
|
||||||
const { location } = userMark.mark
|
const { location } = userMark.mark
|
||||||
const handleClick = () => handleMarkClick(userMark.mark.id)
|
const handleClick = () => handleMarkClick(userMark.mark.id)
|
||||||
|
const isEdited = () => selectedMark?.mark.id === userMark.mark.id
|
||||||
const getMarkValue = () =>
|
const getMarkValue = () =>
|
||||||
selectedMark?.mark.id === userMark.mark.id
|
isEdited() ? selectedMarkValue : userMark.currentValue
|
||||||
? selectedMarkValue
|
|
||||||
: userMark.mark.value
|
|
||||||
return (
|
return (
|
||||||
<div
|
<div
|
||||||
onClick={handleClick}
|
onClick={handleClick}
|
||||||
className={styles.drawingRectangle}
|
className={`${styles.drawingRectangle} ${isEdited() && styles.edited}`}
|
||||||
style={{
|
style={{
|
||||||
left: inPx(location.left),
|
left: inPx(location.left),
|
||||||
top: inPx(location.top),
|
top: inPx(location.top),
|
||||||
|
@ -1,23 +1,30 @@
|
|||||||
import PdfView from './index.tsx'
|
import PdfView from './index.tsx'
|
||||||
import MarkFormField from '../../pages/sign/MarkFormField.tsx'
|
import MarkFormField from '../MarkFormField'
|
||||||
import { PdfFile } from '../../types/drawing.ts'
|
|
||||||
import { CurrentUserMark, Mark } from '../../types/mark.ts'
|
import { CurrentUserMark, Mark } from '../../types/mark.ts'
|
||||||
import React, { useState, useEffect } from 'react'
|
import React, { useState, useEffect } from 'react'
|
||||||
import {
|
import {
|
||||||
findNextCurrentUserMark,
|
findNextIncompleteCurrentUserMark,
|
||||||
isCurrentUserMarksComplete,
|
getUpdatedMark,
|
||||||
updateCurrentUserMarks
|
updateCurrentUserMarks
|
||||||
} from '../../utils'
|
} from '../../utils'
|
||||||
import { EMPTY } from '../../utils/const.ts'
|
import { EMPTY } from '../../utils/const.ts'
|
||||||
import { Container } from '../Container'
|
import { Container } from '../Container'
|
||||||
import styles from '../../pages/sign/style.module.scss'
|
import signPageStyles from '../../pages/sign/style.module.scss'
|
||||||
|
import styles from './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'
|
||||||
|
|
||||||
interface PdfMarkingProps {
|
interface PdfMarkingProps {
|
||||||
files: { pdfFile: PdfFile; filename: string; hash: string | null }[]
|
files: CurrentUserFile[]
|
||||||
currentUserMarks: CurrentUserMark[]
|
currentUserMarks: CurrentUserMark[]
|
||||||
setIsReadyToSign: (isReadyToSign: boolean) => void
|
setIsReadyToSign: (isReadyToSign: boolean) => void
|
||||||
setCurrentUserMarks: (currentUserMarks: CurrentUserMark[]) => void
|
setCurrentUserMarks: (currentUserMarks: CurrentUserMark[]) => void
|
||||||
setUpdatedMarks: (markToUpdate: Mark) => void
|
setUpdatedMarks: (markToUpdate: Mark) => void
|
||||||
|
handleDownload: () => void
|
||||||
|
meta: Meta | null
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -32,14 +39,28 @@ const PdfMarking = (props: PdfMarkingProps) => {
|
|||||||
currentUserMarks,
|
currentUserMarks,
|
||||||
setIsReadyToSign,
|
setIsReadyToSign,
|
||||||
setCurrentUserMarks,
|
setCurrentUserMarks,
|
||||||
setUpdatedMarks
|
setUpdatedMarks,
|
||||||
|
handleDownload,
|
||||||
|
meta
|
||||||
} = props
|
} = props
|
||||||
const [selectedMark, setSelectedMark] = useState<CurrentUserMark | null>(null)
|
const [selectedMark, setSelectedMark] = useState<CurrentUserMark | null>(null)
|
||||||
const [selectedMarkValue, setSelectedMarkValue] = useState<string>('')
|
const [selectedMarkValue, setSelectedMarkValue] = useState<string>('')
|
||||||
|
const [currentFile, setCurrentFile] = useState<CurrentUserFile | null>(null)
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
setSelectedMark(findNextCurrentUserMark(currentUserMarks) || null)
|
if (selectedMark === null && currentUserMarks.length > 0) {
|
||||||
}, [currentUserMarks])
|
setSelectedMark(
|
||||||
|
findNextIncompleteCurrentUserMark(currentUserMarks) ||
|
||||||
|
currentUserMarks[0]
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}, [currentUserMarks, selectedMark])
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (currentFile === null && files.length > 0) {
|
||||||
|
setCurrentFile(files[0])
|
||||||
|
}
|
||||||
|
}, [files, currentFile])
|
||||||
|
|
||||||
const handleMarkClick = (id: number) => {
|
const handleMarkClick = (id: number) => {
|
||||||
const nextMark = currentUserMarks.find((mark) => mark.mark.id === id)
|
const nextMark = currentUserMarks.find((mark) => mark.mark.id === id)
|
||||||
@ -47,18 +68,30 @@ const PdfMarking = (props: PdfMarkingProps) => {
|
|||||||
setSelectedMarkValue(nextMark?.mark.value ?? EMPTY)
|
setSelectedMarkValue(nextMark?.mark.value ?? EMPTY)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const handleCurrentUserMarkChange = (mark: CurrentUserMark) => {
|
||||||
|
if (!selectedMark) return
|
||||||
|
const updatedSelectedMark: CurrentUserMark = getUpdatedMark(
|
||||||
|
selectedMark,
|
||||||
|
selectedMarkValue
|
||||||
|
)
|
||||||
|
|
||||||
|
const updatedCurrentUserMarks = updateCurrentUserMarks(
|
||||||
|
currentUserMarks,
|
||||||
|
updatedSelectedMark
|
||||||
|
)
|
||||||
|
setCurrentUserMarks(updatedCurrentUserMarks)
|
||||||
|
setSelectedMarkValue(mark.currentValue ?? EMPTY)
|
||||||
|
setSelectedMark(mark)
|
||||||
|
}
|
||||||
|
|
||||||
const handleSubmit = (event: React.FormEvent<HTMLFormElement>) => {
|
const handleSubmit = (event: React.FormEvent<HTMLFormElement>) => {
|
||||||
event.preventDefault()
|
event.preventDefault()
|
||||||
if (!selectedMarkValue || !selectedMark) return
|
if (!selectedMarkValue || !selectedMark) return
|
||||||
|
|
||||||
const updatedMark: CurrentUserMark = {
|
const updatedMark: CurrentUserMark = getUpdatedMark(
|
||||||
...selectedMark,
|
selectedMark,
|
||||||
mark: {
|
selectedMarkValue
|
||||||
...selectedMark.mark,
|
)
|
||||||
value: selectedMarkValue
|
|
||||||
},
|
|
||||||
isCompleted: true
|
|
||||||
}
|
|
||||||
|
|
||||||
setSelectedMarkValue(EMPTY)
|
setSelectedMarkValue(EMPTY)
|
||||||
const updatedCurrentUserMarks = updateCurrentUserMarks(
|
const updatedCurrentUserMarks = updateCurrentUserMarks(
|
||||||
@ -66,33 +99,62 @@ const PdfMarking = (props: PdfMarkingProps) => {
|
|||||||
updatedMark
|
updatedMark
|
||||||
)
|
)
|
||||||
setCurrentUserMarks(updatedCurrentUserMarks)
|
setCurrentUserMarks(updatedCurrentUserMarks)
|
||||||
setSelectedMark(findNextCurrentUserMark(updatedCurrentUserMarks) || null)
|
setSelectedMark(null)
|
||||||
console.log(isCurrentUserMarksComplete(updatedCurrentUserMarks))
|
setIsReadyToSign(true)
|
||||||
setIsReadyToSign(isCurrentUserMarksComplete(updatedCurrentUserMarks))
|
|
||||||
setUpdatedMarks(updatedMark.mark)
|
setUpdatedMarks(updatedMark.mark)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// const updateCurrentUserMarkValues = () => {
|
||||||
|
// const updatedMark: CurrentUserMark = getUpdatedMark(selectedMark!, selectedMarkValue)
|
||||||
|
// const updatedCurrentUserMarks = updateCurrentUserMarks(currentUserMarks, updatedMark)
|
||||||
|
// setSelectedMarkValue(EMPTY)
|
||||||
|
// setCurrentUserMarks(updatedCurrentUserMarks)
|
||||||
|
// }
|
||||||
|
|
||||||
const handleChange = (event: React.ChangeEvent<HTMLInputElement>) =>
|
const handleChange = (event: React.ChangeEvent<HTMLInputElement>) =>
|
||||||
setSelectedMarkValue(event.target.value)
|
setSelectedMarkValue(event.target.value)
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<Container className={styles.container}>
|
<Container className={signPageStyles.container}>
|
||||||
{currentUserMarks?.length > 0 && (
|
<StickySideColumns
|
||||||
<PdfView
|
left={
|
||||||
files={files}
|
<div>
|
||||||
handleMarkClick={handleMarkClick}
|
{currentFile !== null && (
|
||||||
selectedMarkValue={selectedMarkValue}
|
<FileList
|
||||||
selectedMark={selectedMark}
|
files={files}
|
||||||
currentUserMarks={currentUserMarks}
|
currentFile={currentFile}
|
||||||
/>
|
setCurrentFile={setCurrentFile}
|
||||||
)}
|
handleDownload={handleDownload}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
}
|
||||||
|
right={meta !== null && <UsersDetails meta={meta} />}
|
||||||
|
>
|
||||||
|
<div className={styles.container}>
|
||||||
|
{currentUserMarks?.length > 0 && (
|
||||||
|
<div className={styles.pdfView}>
|
||||||
|
<PdfView
|
||||||
|
currentFile={currentFile}
|
||||||
|
files={files}
|
||||||
|
handleMarkClick={handleMarkClick}
|
||||||
|
selectedMarkValue={selectedMarkValue}
|
||||||
|
selectedMark={selectedMark}
|
||||||
|
currentUserMarks={currentUserMarks}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
</StickySideColumns>
|
||||||
{selectedMark !== null && (
|
{selectedMark !== null && (
|
||||||
<MarkFormField
|
<MarkFormField
|
||||||
handleSubmit={handleSubmit}
|
handleSubmit={handleSubmit}
|
||||||
handleChange={handleChange}
|
handleSelectedMarkValueChange={handleChange}
|
||||||
selectedMark={selectedMark}
|
selectedMark={selectedMark}
|
||||||
selectedMarkValue={selectedMarkValue}
|
selectedMarkValue={selectedMarkValue}
|
||||||
|
currentUserMarks={currentUserMarks}
|
||||||
|
handleCurrentUserMarkChange={handleCurrentUserMarkChange}
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
</Container>
|
</Container>
|
||||||
|
@ -2,6 +2,7 @@ import styles from '../DrawPDFFields/style.module.scss'
|
|||||||
import { PdfPage } from '../../types/drawing.ts'
|
import { PdfPage } from '../../types/drawing.ts'
|
||||||
import { CurrentUserMark } from '../../types/mark.ts'
|
import { CurrentUserMark } from '../../types/mark.ts'
|
||||||
import PdfMarkItem from './PdfMarkItem.tsx'
|
import PdfMarkItem from './PdfMarkItem.tsx'
|
||||||
|
import { useEffect, useRef } from 'react'
|
||||||
interface PdfPageProps {
|
interface PdfPageProps {
|
||||||
page: PdfPage
|
page: PdfPage
|
||||||
currentUserMarks: CurrentUserMark[]
|
currentUserMarks: CurrentUserMark[]
|
||||||
@ -20,24 +21,33 @@ const PdfPageItem = ({
|
|||||||
selectedMarkValue,
|
selectedMarkValue,
|
||||||
selectedMark
|
selectedMark
|
||||||
}: PdfPageProps) => {
|
}: PdfPageProps) => {
|
||||||
|
useEffect(() => {
|
||||||
|
if (selectedMark !== null && !!markRefs.current[selectedMark.id]) {
|
||||||
|
markRefs.current[selectedMark.id]?.scrollIntoView({
|
||||||
|
behavior: 'smooth',
|
||||||
|
block: 'end'
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}, [selectedMark])
|
||||||
|
const markRefs = useRef<(HTMLDivElement | null)[]>([])
|
||||||
return (
|
return (
|
||||||
<div
|
<div
|
||||||
className={styles.pdfImageWrapper}
|
className={styles.pdfImageWrapper}
|
||||||
style={{
|
style={{
|
||||||
border: '1px solid #c4c4c4',
|
border: '1px solid #c4c4c4'
|
||||||
marginBottom: '10px',
|
|
||||||
marginTop: '10px'
|
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<img draggable="false" src={page.image} style={{ width: '100%' }} />
|
<img draggable="false" src={page.image} style={{ width: '100%' }} />
|
||||||
{currentUserMarks.map((m, i) => (
|
{currentUserMarks.map((m, i) => (
|
||||||
<PdfMarkItem
|
<div key={i} ref={(el) => (markRefs.current[m.id] = el)}>
|
||||||
key={i}
|
<PdfMarkItem
|
||||||
handleMarkClick={handleMarkClick}
|
key={i}
|
||||||
selectedMarkValue={selectedMarkValue}
|
handleMarkClick={handleMarkClick}
|
||||||
userMark={m}
|
selectedMarkValue={selectedMarkValue}
|
||||||
selectedMark={selectedMark}
|
userMark={m}
|
||||||
/>
|
selectedMark={selectedMark}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
))}
|
))}
|
||||||
</div>
|
</div>
|
||||||
)
|
)
|
||||||
|
@ -1,14 +1,16 @@
|
|||||||
import { PdfFile } from '../../types/drawing.ts'
|
import { Divider } from '@mui/material'
|
||||||
import { Box } from '@mui/material'
|
|
||||||
import PdfItem from './PdfItem.tsx'
|
import PdfItem from './PdfItem.tsx'
|
||||||
import { CurrentUserMark } from '../../types/mark.ts'
|
import { CurrentUserMark } from '../../types/mark.ts'
|
||||||
|
import { CurrentUserFile } from '../../types/file.ts'
|
||||||
|
import { useEffect, useRef } from 'react'
|
||||||
|
|
||||||
interface PdfViewProps {
|
interface PdfViewProps {
|
||||||
files: { pdfFile: PdfFile; filename: string; hash: string | null }[]
|
files: CurrentUserFile[]
|
||||||
currentUserMarks: CurrentUserMark[]
|
currentUserMarks: CurrentUserMark[]
|
||||||
handleMarkClick: (id: number) => void
|
handleMarkClick: (id: number) => void
|
||||||
selectedMarkValue: string
|
selectedMarkValue: string
|
||||||
selectedMark: CurrentUserMark | null
|
selectedMark: CurrentUserMark | null
|
||||||
|
currentFile: CurrentUserFile | null
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -19,8 +21,18 @@ const PdfView = ({
|
|||||||
currentUserMarks,
|
currentUserMarks,
|
||||||
handleMarkClick,
|
handleMarkClick,
|
||||||
selectedMarkValue,
|
selectedMarkValue,
|
||||||
selectedMark
|
selectedMark,
|
||||||
|
currentFile
|
||||||
}: PdfViewProps) => {
|
}: PdfViewProps) => {
|
||||||
|
const pdfRefs = useRef<(HTMLDivElement | null)[]>([])
|
||||||
|
useEffect(() => {
|
||||||
|
if (currentFile !== null && !!pdfRefs.current[currentFile.id]) {
|
||||||
|
pdfRefs.current[currentFile.id]?.scrollIntoView({
|
||||||
|
behavior: 'smooth',
|
||||||
|
block: 'end'
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}, [currentFile])
|
||||||
const filterByFile = (
|
const filterByFile = (
|
||||||
currentUserMarks: CurrentUserMark[],
|
currentUserMarks: CurrentUserMark[],
|
||||||
hash: string
|
hash: string
|
||||||
@ -29,22 +41,31 @@ const PdfView = ({
|
|||||||
(currentUserMark) => currentUserMark.mark.pdfFileHash === hash
|
(currentUserMark) => currentUserMark.mark.pdfFileHash === hash
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
const isNotLastPdfFile = (index: number, files: CurrentUserFile[]): boolean =>
|
||||||
|
index !== files.length - 1
|
||||||
return (
|
return (
|
||||||
<Box sx={{ width: '100%' }}>
|
<>
|
||||||
{files.map(({ pdfFile, hash }, i) => {
|
{files.map((currentUserFile, index, arr) => {
|
||||||
|
const { hash, pdfFile, id } = currentUserFile
|
||||||
if (!hash) return
|
if (!hash) return
|
||||||
return (
|
return (
|
||||||
<PdfItem
|
<div
|
||||||
pdfFile={pdfFile}
|
id={pdfFile.file.name}
|
||||||
key={i}
|
ref={(el) => (pdfRefs.current[id] = el)}
|
||||||
currentUserMarks={filterByFile(currentUserMarks, hash)}
|
key={index}
|
||||||
selectedMark={selectedMark}
|
>
|
||||||
handleMarkClick={handleMarkClick}
|
<PdfItem
|
||||||
selectedMarkValue={selectedMarkValue}
|
pdfFile={pdfFile}
|
||||||
/>
|
currentUserMarks={filterByFile(currentUserMarks, hash)}
|
||||||
|
selectedMark={selectedMark}
|
||||||
|
handleMarkClick={handleMarkClick}
|
||||||
|
selectedMarkValue={selectedMarkValue}
|
||||||
|
/>
|
||||||
|
{isNotLastPdfFile(index, arr) && <Divider>File Separator</Divider>}
|
||||||
|
</div>
|
||||||
)
|
)
|
||||||
})}
|
})}
|
||||||
</Box>
|
</>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -13,4 +13,19 @@
|
|||||||
max-width: 100%;
|
max-width: 100%;
|
||||||
max-height: 100%;
|
max-height: 100%;
|
||||||
object-fit: contain; /* Ensure the image fits within the container */
|
object-fit: contain; /* Ensure the image fits within the container */
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.container {
|
||||||
|
display: flex;
|
||||||
|
width: 100%;
|
||||||
|
flex-direction: column;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
.pdfView {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
width: 100%;
|
||||||
|
height: 100%;
|
||||||
|
gap: 10px;
|
||||||
|
}
|
||||||
|
6
src/components/Spinner/index.tsx
Normal file
6
src/components/Spinner/index.tsx
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
import { PropsWithChildren } from 'react'
|
||||||
|
import styles from './style.module.scss'
|
||||||
|
|
||||||
|
export const Spinner = ({ children }: PropsWithChildren) => (
|
||||||
|
<div className={styles.spin}>{children}</div>
|
||||||
|
)
|
12
src/components/Spinner/style.module.scss
Normal file
12
src/components/Spinner/style.module.scss
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
.spin {
|
||||||
|
animation: spin 5s linear infinite;
|
||||||
|
}
|
||||||
|
|
||||||
|
@keyframes spin {
|
||||||
|
0% {
|
||||||
|
transform: rotate(0deg);
|
||||||
|
}
|
||||||
|
100% {
|
||||||
|
transform: rotate(360deg);
|
||||||
|
}
|
||||||
|
}
|
@ -28,7 +28,7 @@ export const UserAvatarGroup = ({
|
|||||||
|
|
||||||
const childrenArray = Children.toArray(children)
|
const childrenArray = Children.toArray(children)
|
||||||
return (
|
return (
|
||||||
<div {...rest}>
|
<div className={styles.container} {...rest}>
|
||||||
{surplus > 1
|
{surplus > 1
|
||||||
? childrenArray.slice(0, surplus * -1).map((c) => c)
|
? childrenArray.slice(0, surplus * -1).map((c) => c)
|
||||||
: children}
|
: children}
|
||||||
|
@ -1,5 +1,25 @@
|
|||||||
@import '../../styles/colors.scss';
|
@import '../../styles/colors.scss';
|
||||||
|
|
||||||
|
.container {
|
||||||
|
padding: 0 0 0 10px;
|
||||||
|
|
||||||
|
> * {
|
||||||
|
transition: margin ease 0.2s;
|
||||||
|
margin: 0 0 0 -10px;
|
||||||
|
position: relative;
|
||||||
|
z-index: 1;
|
||||||
|
&:first-child {
|
||||||
|
margin-left: -10px !important;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
> *:hover,
|
||||||
|
> *:focus-within {
|
||||||
|
margin: 0 15px 0 5px;
|
||||||
|
z-index: 2;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
.icon {
|
.icon {
|
||||||
width: 40px;
|
width: 40px;
|
||||||
height: 40px;
|
height: 40px;
|
||||||
|
217
src/components/UsersDetails.tsx/index.tsx
Normal file
217
src/components/UsersDetails.tsx/index.tsx
Normal file
@ -0,0 +1,217 @@
|
|||||||
|
import { Divider, Tooltip } from '@mui/material'
|
||||||
|
import { useSigitProfiles } from '../../hooks/useSigitProfiles'
|
||||||
|
import {
|
||||||
|
extractFileExtensions,
|
||||||
|
formatTimestamp,
|
||||||
|
fromUnixTimestamp,
|
||||||
|
hexToNpub,
|
||||||
|
npubToHex,
|
||||||
|
shorten,
|
||||||
|
SignStatus
|
||||||
|
} from '../../utils'
|
||||||
|
import { UserAvatar } from '../UserAvatar'
|
||||||
|
import { useSigitMeta } from '../../hooks/useSigitMeta'
|
||||||
|
import { UserAvatarGroup } from '../UserAvatarGroup'
|
||||||
|
|
||||||
|
import styles from './style.module.scss'
|
||||||
|
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'
|
||||||
|
import {
|
||||||
|
faCalendar,
|
||||||
|
faCalendarCheck,
|
||||||
|
faCalendarPlus,
|
||||||
|
faEye,
|
||||||
|
faFile,
|
||||||
|
faFileCircleExclamation
|
||||||
|
} from '@fortawesome/free-solid-svg-icons'
|
||||||
|
import { getExtensionIconLabel } from '../getExtensionIconLabel'
|
||||||
|
import { useSelector } from 'react-redux'
|
||||||
|
import { State } from '../../store/rootReducer'
|
||||||
|
import { TooltipChild } from '../TooltipChild'
|
||||||
|
import { DisplaySigner } from '../DisplaySigner'
|
||||||
|
import { Meta } from '../../types'
|
||||||
|
|
||||||
|
interface UsersDetailsProps {
|
||||||
|
meta: Meta
|
||||||
|
}
|
||||||
|
|
||||||
|
export const UsersDetails = ({ meta }: UsersDetailsProps) => {
|
||||||
|
const {
|
||||||
|
submittedBy,
|
||||||
|
signers,
|
||||||
|
viewers,
|
||||||
|
fileHashes,
|
||||||
|
signersStatus,
|
||||||
|
createdAt,
|
||||||
|
completedAt,
|
||||||
|
parsedSignatureEvents,
|
||||||
|
signedStatus
|
||||||
|
} = useSigitMeta(meta)
|
||||||
|
const { usersPubkey } = useSelector((state: State) => state.auth)
|
||||||
|
const profiles = useSigitProfiles([
|
||||||
|
...(submittedBy ? [submittedBy] : []),
|
||||||
|
...signers,
|
||||||
|
...viewers
|
||||||
|
])
|
||||||
|
const userCanSign =
|
||||||
|
typeof usersPubkey !== 'undefined' &&
|
||||||
|
signers.includes(hexToNpub(usersPubkey))
|
||||||
|
|
||||||
|
const ext = extractFileExtensions(Object.keys(fileHashes))
|
||||||
|
|
||||||
|
return submittedBy ? (
|
||||||
|
<div className={styles.container}>
|
||||||
|
<div className={styles.section}>
|
||||||
|
<p>Signers</p>
|
||||||
|
<div className={styles.users}>
|
||||||
|
{submittedBy &&
|
||||||
|
(function () {
|
||||||
|
const profile = profiles[submittedBy]
|
||||||
|
return (
|
||||||
|
<Tooltip
|
||||||
|
title={
|
||||||
|
profile?.display_name ||
|
||||||
|
profile?.name ||
|
||||||
|
shorten(hexToNpub(submittedBy))
|
||||||
|
}
|
||||||
|
placement="top"
|
||||||
|
arrow
|
||||||
|
disableInteractive
|
||||||
|
>
|
||||||
|
<TooltipChild>
|
||||||
|
<UserAvatar pubkey={submittedBy} image={profile?.picture} />
|
||||||
|
</TooltipChild>
|
||||||
|
</Tooltip>
|
||||||
|
)
|
||||||
|
})()}
|
||||||
|
|
||||||
|
{submittedBy && signers.length ? (
|
||||||
|
<Divider orientation="vertical" flexItem />
|
||||||
|
) : null}
|
||||||
|
|
||||||
|
<UserAvatarGroup max={20}>
|
||||||
|
{signers.map((signer) => {
|
||||||
|
const pubkey = npubToHex(signer)!
|
||||||
|
const profile = profiles[pubkey]
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Tooltip
|
||||||
|
key={signer}
|
||||||
|
title={
|
||||||
|
profile?.display_name || profile?.name || shorten(pubkey)
|
||||||
|
}
|
||||||
|
placement="top"
|
||||||
|
arrow
|
||||||
|
disableInteractive
|
||||||
|
>
|
||||||
|
<TooltipChild>
|
||||||
|
<DisplaySigner
|
||||||
|
status={signersStatus[signer]}
|
||||||
|
profile={profile}
|
||||||
|
pubkey={pubkey}
|
||||||
|
/>
|
||||||
|
</TooltipChild>
|
||||||
|
</Tooltip>
|
||||||
|
)
|
||||||
|
})}
|
||||||
|
{viewers.map((signer) => {
|
||||||
|
const pubkey = npubToHex(signer)!
|
||||||
|
const profile = profiles[pubkey]
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Tooltip
|
||||||
|
key={signer}
|
||||||
|
title={
|
||||||
|
profile?.display_name || profile?.name || shorten(pubkey)
|
||||||
|
}
|
||||||
|
placement="top"
|
||||||
|
arrow
|
||||||
|
disableInteractive
|
||||||
|
>
|
||||||
|
<TooltipChild>
|
||||||
|
<DisplaySigner
|
||||||
|
status={SignStatus.Viewer}
|
||||||
|
profile={profile}
|
||||||
|
pubkey={pubkey}
|
||||||
|
/>
|
||||||
|
</TooltipChild>
|
||||||
|
</Tooltip>
|
||||||
|
)
|
||||||
|
})}
|
||||||
|
</UserAvatarGroup>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div className={styles.section}>
|
||||||
|
<p>Details</p>
|
||||||
|
|
||||||
|
<Tooltip
|
||||||
|
title={'Publication date'}
|
||||||
|
placement="top"
|
||||||
|
arrow
|
||||||
|
disableInteractive
|
||||||
|
>
|
||||||
|
<span className={styles.detailsItem}>
|
||||||
|
<FontAwesomeIcon icon={faCalendarPlus} />{' '}
|
||||||
|
{createdAt ? formatTimestamp(createdAt) : <>—</>}
|
||||||
|
</span>
|
||||||
|
</Tooltip>
|
||||||
|
|
||||||
|
<Tooltip
|
||||||
|
title={'Completion date'}
|
||||||
|
placement="top"
|
||||||
|
arrow
|
||||||
|
disableInteractive
|
||||||
|
>
|
||||||
|
<span className={styles.detailsItem}>
|
||||||
|
<FontAwesomeIcon icon={faCalendarCheck} />{' '}
|
||||||
|
{completedAt ? formatTimestamp(completedAt) : <>—</>}
|
||||||
|
</span>
|
||||||
|
</Tooltip>
|
||||||
|
|
||||||
|
{/* User signed date */}
|
||||||
|
{userCanSign ? (
|
||||||
|
<Tooltip
|
||||||
|
title={'Your signature date'}
|
||||||
|
placement="top"
|
||||||
|
arrow
|
||||||
|
disableInteractive
|
||||||
|
>
|
||||||
|
<span className={styles.detailsItem}>
|
||||||
|
<FontAwesomeIcon icon={faCalendar} />{' '}
|
||||||
|
{hexToNpub(usersPubkey) in parsedSignatureEvents ? (
|
||||||
|
parsedSignatureEvents[hexToNpub(usersPubkey)].created_at ? (
|
||||||
|
formatTimestamp(
|
||||||
|
fromUnixTimestamp(
|
||||||
|
parsedSignatureEvents[hexToNpub(usersPubkey)].created_at
|
||||||
|
)
|
||||||
|
)
|
||||||
|
) : (
|
||||||
|
<>—</>
|
||||||
|
)
|
||||||
|
) : (
|
||||||
|
<>—</>
|
||||||
|
)}
|
||||||
|
</span>
|
||||||
|
</Tooltip>
|
||||||
|
) : null}
|
||||||
|
<span className={styles.detailsItem}>
|
||||||
|
<FontAwesomeIcon icon={faEye} /> {signedStatus}
|
||||||
|
</span>
|
||||||
|
{ext.length > 0 ? (
|
||||||
|
<span className={styles.detailsItem}>
|
||||||
|
{ext.length > 1 ? (
|
||||||
|
<>
|
||||||
|
<FontAwesomeIcon icon={faFile} /> Multiple File Types
|
||||||
|
</>
|
||||||
|
) : (
|
||||||
|
getExtensionIconLabel(ext[0])
|
||||||
|
)}
|
||||||
|
</span>
|
||||||
|
) : (
|
||||||
|
<>
|
||||||
|
<FontAwesomeIcon icon={faFileCircleExclamation} /> —
|
||||||
|
</>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
) : undefined
|
||||||
|
}
|
46
src/components/UsersDetails.tsx/style.module.scss
Normal file
46
src/components/UsersDetails.tsx/style.module.scss
Normal file
@ -0,0 +1,46 @@
|
|||||||
|
@import '../../styles/colors.scss';
|
||||||
|
|
||||||
|
.container {
|
||||||
|
border-radius: 4px;
|
||||||
|
background: $overlay-background-color;
|
||||||
|
padding: 15px;
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
grid-gap: 25px;
|
||||||
|
|
||||||
|
font-size: 14px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.section {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
grid-gap: 10px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.users {
|
||||||
|
display: flex;
|
||||||
|
grid-gap: 10px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.detailsItem {
|
||||||
|
transition: ease 0.2s;
|
||||||
|
color: rgba(0, 0, 0, 0.5);
|
||||||
|
font-size: 14px;
|
||||||
|
align-items: center;
|
||||||
|
border-radius: 4px;
|
||||||
|
padding: 5px;
|
||||||
|
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: start;
|
||||||
|
|
||||||
|
> :first-child {
|
||||||
|
padding: 5px;
|
||||||
|
margin-right: 10px;
|
||||||
|
}
|
||||||
|
|
||||||
|
&:hover {
|
||||||
|
background: $primary-main;
|
||||||
|
color: white;
|
||||||
|
}
|
||||||
|
}
|
@ -1,9 +1,10 @@
|
|||||||
import { useEffect, useState } from 'react'
|
import { useEffect, useState } from 'react'
|
||||||
import { CreateSignatureEventContent, Meta } from '../types'
|
import { CreateSignatureEventContent, Meta, SignedEventContent } from '../types'
|
||||||
import { Mark } from '../types/mark'
|
import { Mark } from '../types/mark'
|
||||||
import {
|
import {
|
||||||
fromUnixTimestamp,
|
fromUnixTimestamp,
|
||||||
parseCreateSignatureEvent,
|
hexToNpub,
|
||||||
|
parseNostrEvent,
|
||||||
parseCreateSignatureEventContent,
|
parseCreateSignatureEventContent,
|
||||||
SigitMetaParseError,
|
SigitMetaParseError,
|
||||||
SigitStatus,
|
SigitStatus,
|
||||||
@ -12,11 +13,36 @@ import {
|
|||||||
import { toast } from 'react-toastify'
|
import { toast } from 'react-toastify'
|
||||||
import { verifyEvent } from 'nostr-tools'
|
import { verifyEvent } from 'nostr-tools'
|
||||||
import { Event } from 'nostr-tools'
|
import { Event } from 'nostr-tools'
|
||||||
|
import store from '../store/store'
|
||||||
|
import { AuthState } from '../store/auth/types'
|
||||||
|
import { NostrController } from '../controllers'
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Flattened interface that combines properties `Meta`, `CreateSignatureEventContent`,
|
||||||
|
* and `Event` (event's fields are made optional and pubkey and created_at replaced with our versions)
|
||||||
|
*/
|
||||||
|
export interface FlatMeta
|
||||||
|
extends Meta,
|
||||||
|
CreateSignatureEventContent,
|
||||||
|
Partial<Omit<Event, 'pubkey' | 'created_at'>> {
|
||||||
|
// Remove pubkey and use submittedBy as `npub1${string}`
|
||||||
|
submittedBy?: `npub1${string}`
|
||||||
|
|
||||||
|
// Remove created_at and replace with createdAt
|
||||||
|
createdAt?: number
|
||||||
|
|
||||||
interface FlatMeta extends Meta, CreateSignatureEventContent, Partial<Event> {
|
|
||||||
// Validated create signature event
|
// Validated create signature event
|
||||||
isValid: boolean
|
isValid: boolean
|
||||||
|
|
||||||
|
// Decryption
|
||||||
|
encryptionKey: string | null
|
||||||
|
|
||||||
|
// Parsed Document Signatures
|
||||||
|
parsedSignatureEvents: { [signer: `npub1${string}`]: Event }
|
||||||
|
|
||||||
|
// Calculated completion time
|
||||||
|
completedAt?: number
|
||||||
|
|
||||||
// Calculated status fields
|
// Calculated status fields
|
||||||
signedStatus: SigitStatus
|
signedStatus: SigitStatus
|
||||||
signersStatus: {
|
signersStatus: {
|
||||||
@ -33,8 +59,8 @@ export const useSigitMeta = (meta: Meta): FlatMeta => {
|
|||||||
const [isValid, setIsValid] = useState(false)
|
const [isValid, setIsValid] = useState(false)
|
||||||
const [kind, setKind] = useState<number>()
|
const [kind, setKind] = useState<number>()
|
||||||
const [tags, setTags] = useState<string[][]>()
|
const [tags, setTags] = useState<string[][]>()
|
||||||
const [created_at, setCreatedAt] = useState<number>()
|
const [createdAt, setCreatedAt] = useState<number>()
|
||||||
const [pubkey, setPubkey] = useState<string>() // submittedBy, pubkey from nostr event
|
const [submittedBy, setSubmittedBy] = useState<`npub1${string}`>() // submittedBy, pubkey from nostr event
|
||||||
const [id, setId] = useState<string>()
|
const [id, setId] = useState<string>()
|
||||||
const [sig, setSig] = useState<string>()
|
const [sig, setSig] = useState<string>()
|
||||||
|
|
||||||
@ -47,6 +73,12 @@ export const useSigitMeta = (meta: Meta): FlatMeta => {
|
|||||||
const [title, setTitle] = useState<string>('')
|
const [title, setTitle] = useState<string>('')
|
||||||
const [zipUrl, setZipUrl] = useState<string>('')
|
const [zipUrl, setZipUrl] = useState<string>('')
|
||||||
|
|
||||||
|
const [parsedSignatureEvents, setParsedSignatureEvents] = useState<{
|
||||||
|
[signer: `npub1${string}`]: Event
|
||||||
|
}>({})
|
||||||
|
|
||||||
|
const [completedAt, setCompletedAt] = useState<number>()
|
||||||
|
|
||||||
const [signedStatus, setSignedStatus] = useState<SigitStatus>(
|
const [signedStatus, setSignedStatus] = useState<SigitStatus>(
|
||||||
SigitStatus.Partial
|
SigitStatus.Partial
|
||||||
)
|
)
|
||||||
@ -54,13 +86,13 @@ export const useSigitMeta = (meta: Meta): FlatMeta => {
|
|||||||
[signer: `npub1${string}`]: SignStatus
|
[signer: `npub1${string}`]: SignStatus
|
||||||
}>({})
|
}>({})
|
||||||
|
|
||||||
|
const [encryptionKey, setEncryptionKey] = useState<string | null>(null)
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!meta) return
|
if (!meta) return
|
||||||
;(async function () {
|
;(async function () {
|
||||||
try {
|
try {
|
||||||
const createSignatureEvent = await parseCreateSignatureEvent(
|
const createSignatureEvent = await parseNostrEvent(meta.createSignature)
|
||||||
meta.createSignature
|
|
||||||
)
|
|
||||||
|
|
||||||
const { kind, tags, created_at, pubkey, id, sig, content } =
|
const { kind, tags, created_at, pubkey, id, sig, content } =
|
||||||
createSignatureEvent
|
createSignatureEvent
|
||||||
@ -70,7 +102,7 @@ export const useSigitMeta = (meta: Meta): FlatMeta => {
|
|||||||
setTags(tags)
|
setTags(tags)
|
||||||
// created_at in nostr events are stored in seconds
|
// created_at in nostr events are stored in seconds
|
||||||
setCreatedAt(fromUnixTimestamp(created_at))
|
setCreatedAt(fromUnixTimestamp(created_at))
|
||||||
setPubkey(pubkey)
|
setSubmittedBy(pubkey as `npub1${string}`)
|
||||||
setId(id)
|
setId(id)
|
||||||
setSig(sig)
|
setSig(sig)
|
||||||
|
|
||||||
@ -84,30 +116,102 @@ export const useSigitMeta = (meta: Meta): FlatMeta => {
|
|||||||
setMarkConfig(markConfig)
|
setMarkConfig(markConfig)
|
||||||
setZipUrl(zipUrl)
|
setZipUrl(zipUrl)
|
||||||
|
|
||||||
// Parse each signature event and set signer status
|
if (meta.keys) {
|
||||||
for (const npub in meta.docSignatures) {
|
const { sender, keys } = meta.keys
|
||||||
try {
|
// Retrieve the user's public key from the state
|
||||||
const event = await parseCreateSignatureEvent(
|
const usersPubkey = (store.getState().auth as AuthState).usersPubkey!
|
||||||
meta.docSignatures[npub as `npub1${string}`]
|
const usersNpub = hexToNpub(usersPubkey)
|
||||||
)
|
|
||||||
const isValidSignature = verifyEvent(event)
|
// Check if the user's public key is in the keys object
|
||||||
setSignersStatus((prev) => {
|
if (usersNpub in keys) {
|
||||||
return {
|
// Instantiate the NostrController to decrypt the encryption key
|
||||||
...prev,
|
const nostrController = NostrController.getInstance()
|
||||||
[npub]: isValidSignature
|
const decrypted = await nostrController
|
||||||
? SignStatus.Signed
|
.nip04Decrypt(sender, keys[usersNpub])
|
||||||
: SignStatus.Invalid
|
.catch((err) => {
|
||||||
}
|
console.log(
|
||||||
})
|
'An error occurred in decrypting encryption key',
|
||||||
} catch (error) {
|
err
|
||||||
setSignersStatus((prev) => {
|
)
|
||||||
return {
|
return null
|
||||||
...prev,
|
})
|
||||||
[npub]: SignStatus.Invalid
|
|
||||||
}
|
setEncryptionKey(decrypted)
|
||||||
})
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Temp. map to hold events and signers
|
||||||
|
const parsedSignatureEventsMap = new Map<`npub1${string}`, Event>()
|
||||||
|
const signerStatusMap = new Map<`npub1${string}`, SignStatus>()
|
||||||
|
|
||||||
|
const getPrevSignerSig = (npub: `npub1${string}`) => {
|
||||||
|
if (signers[0] === npub) {
|
||||||
|
return sig
|
||||||
|
}
|
||||||
|
|
||||||
|
// find the index of signer
|
||||||
|
const currentSignerIndex = signers.findIndex(
|
||||||
|
(signer) => signer === npub
|
||||||
|
)
|
||||||
|
// return if could not found user in signer's list
|
||||||
|
if (currentSignerIndex === -1) return
|
||||||
|
// find prev signer
|
||||||
|
const prevSigner = signers[currentSignerIndex - 1]
|
||||||
|
|
||||||
|
// get the signature of prev signer
|
||||||
|
return parsedSignatureEventsMap.get(prevSigner)?.sig
|
||||||
|
}
|
||||||
|
|
||||||
|
for (const npub in meta.docSignatures) {
|
||||||
|
try {
|
||||||
|
// Parse each signature event
|
||||||
|
const event = await parseNostrEvent(
|
||||||
|
meta.docSignatures[npub as `npub1${string}`]
|
||||||
|
)
|
||||||
|
|
||||||
|
// Save events to a map, to save all at once outside loop
|
||||||
|
// We need the object to find completedAt
|
||||||
|
// Avoided using parsedSignatureEvents due to useEffect deps
|
||||||
|
parsedSignatureEventsMap.set(npub as `npub1${string}`, event)
|
||||||
|
} catch (error) {
|
||||||
|
signerStatusMap.set(npub as `npub1${string}`, SignStatus.Invalid)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
parsedSignatureEventsMap.forEach((event, npub) => {
|
||||||
|
const isValidSignature = verifyEvent(event)
|
||||||
|
if (isValidSignature) {
|
||||||
|
// get the signature of prev signer from the content of current signers signedEvent
|
||||||
|
const prevSignersSig = getPrevSignerSig(npub)
|
||||||
|
|
||||||
|
try {
|
||||||
|
const obj: SignedEventContent = JSON.parse(event.content)
|
||||||
|
if (
|
||||||
|
obj.prevSig &&
|
||||||
|
prevSignersSig &&
|
||||||
|
obj.prevSig === prevSignersSig
|
||||||
|
) {
|
||||||
|
signerStatusMap.set(npub as `npub1${string}`, SignStatus.Signed)
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
signerStatusMap.set(npub as `npub1${string}`, SignStatus.Invalid)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
signers
|
||||||
|
.filter((s) => !parsedSignatureEventsMap.has(s))
|
||||||
|
.forEach((s) => signerStatusMap.set(s, SignStatus.Pending))
|
||||||
|
|
||||||
|
// Get the first signer that hasn't signed
|
||||||
|
const nextSigner = signers.find((s) => !parsedSignatureEventsMap.has(s))
|
||||||
|
if (nextSigner) {
|
||||||
|
signerStatusMap.set(nextSigner, SignStatus.Awaiting)
|
||||||
|
}
|
||||||
|
|
||||||
|
setSignersStatus(Object.fromEntries(signerStatusMap))
|
||||||
|
setParsedSignatureEvents(Object.fromEntries(parsedSignatureEventsMap))
|
||||||
|
|
||||||
const signedBy = Object.keys(meta.docSignatures) as `npub1${string}`[]
|
const signedBy = Object.keys(meta.docSignatures) as `npub1${string}`[]
|
||||||
const isCompletelySigned = signers.every((signer) =>
|
const isCompletelySigned = signers.every((signer) =>
|
||||||
signedBy.includes(signer)
|
signedBy.includes(signer)
|
||||||
@ -115,6 +219,20 @@ export const useSigitMeta = (meta: Meta): FlatMeta => {
|
|||||||
setSignedStatus(
|
setSignedStatus(
|
||||||
isCompletelySigned ? SigitStatus.Complete : SigitStatus.Partial
|
isCompletelySigned ? SigitStatus.Complete : SigitStatus.Partial
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// Check if all signers signed
|
||||||
|
if (isCompletelySigned) {
|
||||||
|
setCompletedAt(
|
||||||
|
fromUnixTimestamp(
|
||||||
|
signedBy.reduce((p, c) => {
|
||||||
|
return Math.max(
|
||||||
|
p,
|
||||||
|
parsedSignatureEventsMap.get(c)?.created_at || 0
|
||||||
|
)
|
||||||
|
}, 0)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
if (error instanceof SigitMetaParseError) {
|
if (error instanceof SigitMetaParseError) {
|
||||||
toast.error(error.message)
|
toast.error(error.message)
|
||||||
@ -125,15 +243,15 @@ export const useSigitMeta = (meta: Meta): FlatMeta => {
|
|||||||
}, [meta])
|
}, [meta])
|
||||||
|
|
||||||
return {
|
return {
|
||||||
modifiedAt: meta.modifiedAt,
|
modifiedAt: meta?.modifiedAt,
|
||||||
createSignature: meta.createSignature,
|
createSignature: meta?.createSignature,
|
||||||
docSignatures: meta.docSignatures,
|
docSignatures: meta?.docSignatures,
|
||||||
keys: meta.keys,
|
keys: meta?.keys,
|
||||||
isValid,
|
isValid,
|
||||||
kind,
|
kind,
|
||||||
tags,
|
tags,
|
||||||
created_at,
|
createdAt,
|
||||||
pubkey,
|
submittedBy,
|
||||||
id,
|
id,
|
||||||
sig,
|
sig,
|
||||||
signers,
|
signers,
|
||||||
@ -142,7 +260,10 @@ export const useSigitMeta = (meta: Meta): FlatMeta => {
|
|||||||
markConfig,
|
markConfig,
|
||||||
title,
|
title,
|
||||||
zipUrl,
|
zipUrl,
|
||||||
|
parsedSignatureEvents,
|
||||||
|
completedAt,
|
||||||
signedStatus,
|
signedStatus,
|
||||||
signersStatus
|
signersStatus,
|
||||||
|
encryptionKey
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
70
src/hooks/useSigitProfiles.tsx
Normal file
70
src/hooks/useSigitProfiles.tsx
Normal file
@ -0,0 +1,70 @@
|
|||||||
|
import { useEffect, useState } from 'react'
|
||||||
|
import { ProfileMetadata } from '../types'
|
||||||
|
import { MetadataController } from '../controllers'
|
||||||
|
import { npubToHex } from '../utils'
|
||||||
|
import { Event, kinds } from 'nostr-tools'
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Extracts profiles from metadata events
|
||||||
|
* @param pubkeys Array of npubs to check
|
||||||
|
* @returns ProfileMetadata
|
||||||
|
*/
|
||||||
|
export const useSigitProfiles = (
|
||||||
|
pubkeys: `npub1${string}`[]
|
||||||
|
): { [key: string]: ProfileMetadata } => {
|
||||||
|
const [profileMetadata, setProfileMetadata] = useState<{
|
||||||
|
[key: string]: ProfileMetadata
|
||||||
|
}>({})
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (pubkeys.length) {
|
||||||
|
const metadataController = new MetadataController()
|
||||||
|
|
||||||
|
// Remove duplicate keys
|
||||||
|
const users = new Set<string>([...pubkeys])
|
||||||
|
|
||||||
|
const handleMetadataEvent = (key: string) => (event: Event) => {
|
||||||
|
const metadataContent =
|
||||||
|
metadataController.extractProfileMetadataContent(event)
|
||||||
|
|
||||||
|
if (metadataContent) {
|
||||||
|
setProfileMetadata((prev) => ({
|
||||||
|
...prev,
|
||||||
|
[key]: metadataContent
|
||||||
|
}))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
users.forEach((user) => {
|
||||||
|
const hexKey = npubToHex(user)
|
||||||
|
if (hexKey && !(hexKey in profileMetadata)) {
|
||||||
|
metadataController.on(hexKey, (kind: number, event: Event) => {
|
||||||
|
if (kind === kinds.Metadata) {
|
||||||
|
handleMetadataEvent(hexKey)(event)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
metadataController
|
||||||
|
.findMetadata(hexKey)
|
||||||
|
.then((metadataEvent) => {
|
||||||
|
if (metadataEvent) handleMetadataEvent(hexKey)(metadataEvent)
|
||||||
|
})
|
||||||
|
.catch((err) => {
|
||||||
|
console.error(
|
||||||
|
`error occurred in finding metadata for: ${user}`,
|
||||||
|
err
|
||||||
|
)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
return () => {
|
||||||
|
users.forEach((key) => {
|
||||||
|
metadataController.off(key, handleMetadataEvent(key))
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}, [pubkeys, profileMetadata])
|
||||||
|
|
||||||
|
return profileMetadata
|
||||||
|
}
|
29
src/layouts/StickySideColumns.module.scss
Normal file
29
src/layouts/StickySideColumns.module.scss
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
@import '../styles/colors.scss';
|
||||||
|
@import '../styles/sizes.scss';
|
||||||
|
|
||||||
|
.container {
|
||||||
|
display: grid;
|
||||||
|
grid-template-columns: 0.75fr 1.5fr 0.75fr;
|
||||||
|
grid-gap: 30px;
|
||||||
|
flex-grow: 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
.sidesWrap {
|
||||||
|
position: relative;
|
||||||
|
}
|
||||||
|
|
||||||
|
.sides {
|
||||||
|
position: sticky;
|
||||||
|
top: $header-height + $body-vertical-padding;
|
||||||
|
}
|
||||||
|
|
||||||
|
.files {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
grid-gap: 15px;
|
||||||
|
}
|
||||||
|
.content {
|
||||||
|
max-width: 550px;
|
||||||
|
width: 550px;
|
||||||
|
margin: 0 auto;
|
||||||
|
}
|
26
src/layouts/StickySideColumns.tsx
Normal file
26
src/layouts/StickySideColumns.tsx
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
import { PropsWithChildren, ReactNode } from 'react'
|
||||||
|
|
||||||
|
import styles from './StickySideColumns.module.scss'
|
||||||
|
|
||||||
|
interface StickySideColumnsProps {
|
||||||
|
left?: ReactNode
|
||||||
|
right?: ReactNode
|
||||||
|
}
|
||||||
|
|
||||||
|
export const StickySideColumns = ({
|
||||||
|
left,
|
||||||
|
right,
|
||||||
|
children
|
||||||
|
}: PropsWithChildren<StickySideColumnsProps>) => {
|
||||||
|
return (
|
||||||
|
<div className={styles.container}>
|
||||||
|
<div className={`${styles.sidesWrap} ${styles.files}`}>
|
||||||
|
<div className={styles.sides}>{left}</div>
|
||||||
|
</div>
|
||||||
|
<div className={styles.content}>{children}</div>
|
||||||
|
<div className={styles.sidesWrap}>
|
||||||
|
<div className={styles.sides}>{right}</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
@ -359,7 +359,8 @@ export const CreatePage = () => {
|
|||||||
width: drawnField.width
|
width: drawnField.width
|
||||||
},
|
},
|
||||||
npub: drawnField.counterpart,
|
npub: drawnField.counterpart,
|
||||||
pdfFileHash: fileHash
|
pdfFileHash: fileHash,
|
||||||
|
fileName: drawnPdf.file.name
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
@ -672,6 +673,7 @@ export const CreatePage = () => {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
setLoadingSpinnerDesc('Encrypting zip file')
|
||||||
const encryptedArrayBuffer = await encryptZipFile(
|
const encryptedArrayBuffer = await encryptZipFile(
|
||||||
arrayBuffer,
|
arrayBuffer,
|
||||||
encryptionKey
|
encryptionKey
|
||||||
|
@ -1,37 +0,0 @@
|
|||||||
import { CurrentUserMark } from '../../types/mark.ts'
|
|
||||||
import styles from './style.module.scss'
|
|
||||||
import { Box, Button, TextField } from '@mui/material'
|
|
||||||
|
|
||||||
import { MARK_TYPE_TRANSLATION } from '../../utils/const.ts'
|
|
||||||
|
|
||||||
interface MarkFormFieldProps {
|
|
||||||
handleSubmit: (event: any) => void
|
|
||||||
handleChange: (event: any) => void
|
|
||||||
selectedMark: CurrentUserMark
|
|
||||||
selectedMarkValue: string
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Responsible for rendering a form field connected to a mark and keeping track of its value.
|
|
||||||
*/
|
|
||||||
const MarkFormField = (props: MarkFormFieldProps) => {
|
|
||||||
const { handleSubmit, handleChange, selectedMark, selectedMarkValue } = props
|
|
||||||
const getSubmitButton = () => (selectedMark.isLast ? 'Complete' : 'Next')
|
|
||||||
return (
|
|
||||||
<div className={styles.fixedBottomForm}>
|
|
||||||
<Box component="form" onSubmit={handleSubmit}>
|
|
||||||
<TextField
|
|
||||||
id="mark-value"
|
|
||||||
label={MARK_TYPE_TRANSLATION[selectedMark.mark.type.valueOf()]}
|
|
||||||
value={selectedMarkValue}
|
|
||||||
onChange={handleChange}
|
|
||||||
/>
|
|
||||||
<Button type="submit" variant="contained">
|
|
||||||
{getSubmitButton()}
|
|
||||||
</Button>
|
|
||||||
</Box>
|
|
||||||
</div>
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
export default MarkFormField
|
|
@ -21,7 +21,7 @@ import {
|
|||||||
extractZipUrlAndEncryptionKey,
|
extractZipUrlAndEncryptionKey,
|
||||||
generateEncryptionKey,
|
generateEncryptionKey,
|
||||||
generateKeysFile,
|
generateKeysFile,
|
||||||
getFilesWithHashes,
|
getCurrentUserFiles,
|
||||||
getHash,
|
getHash,
|
||||||
hexToNpub,
|
hexToNpub,
|
||||||
isOnline,
|
isOnline,
|
||||||
@ -48,6 +48,8 @@ import {
|
|||||||
updateMarks
|
updateMarks
|
||||||
} from '../../utils'
|
} from '../../utils'
|
||||||
import PdfMarking from '../../components/PDFView/PdfMarking.tsx'
|
import PdfMarking from '../../components/PDFView/PdfMarking.tsx'
|
||||||
|
import { getZipWithFiles } from '../../utils/file.ts'
|
||||||
|
import { ARRAY_BUFFER, DEFLATE } from '../../utils/const.ts'
|
||||||
enum SignedStatus {
|
enum SignedStatus {
|
||||||
Fully_Signed,
|
Fully_Signed,
|
||||||
User_Is_Next_Signer,
|
User_Is_Next_Signer,
|
||||||
@ -219,6 +221,27 @@ export const SignPage = () => {
|
|||||||
}
|
}
|
||||||
}, [meta, usersPubkey])
|
}, [meta, usersPubkey])
|
||||||
|
|
||||||
|
const handleDownload = async () => {
|
||||||
|
if (Object.entries(files).length === 0 || !meta || !usersPubkey) return
|
||||||
|
setLoadingSpinnerDesc('Generating file')
|
||||||
|
try {
|
||||||
|
const zip = await getZipWithFiles(meta, files)
|
||||||
|
const arrayBuffer = await zip.generateAsync({
|
||||||
|
type: ARRAY_BUFFER,
|
||||||
|
compression: DEFLATE,
|
||||||
|
compressionOptions: {
|
||||||
|
level: 6
|
||||||
|
}
|
||||||
|
})
|
||||||
|
if (!arrayBuffer) return
|
||||||
|
const blob = new Blob([arrayBuffer])
|
||||||
|
saveAs(blob, `exported-${unixNow()}.sigit.zip`)
|
||||||
|
} catch (error: any) {
|
||||||
|
console.log('error in zip:>> ', error)
|
||||||
|
toast.error(error.message || 'Error occurred in generating zip file')
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const decrypt = useCallback(
|
const decrypt = useCallback(
|
||||||
async (file: File) => {
|
async (file: File) => {
|
||||||
setLoadingSpinnerDesc('Decrypting file')
|
setLoadingSpinnerDesc('Decrypting file')
|
||||||
@ -929,11 +952,13 @@ export const SignPage = () => {
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<PdfMarking
|
<PdfMarking
|
||||||
files={getFilesWithHashes(files, currentFileHashes)}
|
files={getCurrentUserFiles(files, currentFileHashes, creatorFileHashes)}
|
||||||
currentUserMarks={currentUserMarks}
|
currentUserMarks={currentUserMarks}
|
||||||
setIsReadyToSign={setIsReadyToSign}
|
setIsReadyToSign={setIsReadyToSign}
|
||||||
setCurrentUserMarks={setCurrentUserMarks}
|
setCurrentUserMarks={setCurrentUserMarks}
|
||||||
setUpdatedMarks={setUpdatedMarks}
|
setUpdatedMarks={setUpdatedMarks}
|
||||||
|
handleDownload={handleDownload}
|
||||||
|
meta={meta}
|
||||||
/>
|
/>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
@ -2,8 +2,8 @@
|
|||||||
|
|
||||||
.container {
|
.container {
|
||||||
color: $text-color;
|
color: $text-color;
|
||||||
width: 550px;
|
//width: 550px;
|
||||||
max-width: 550px;
|
//max-width: 550px;
|
||||||
|
|
||||||
.inputBlock {
|
.inputBlock {
|
||||||
position: relative;
|
position: relative;
|
||||||
|
@ -1,39 +1,22 @@
|
|||||||
import {
|
import { Box, Button, Tooltip, Typography, useTheme } from '@mui/material'
|
||||||
Box,
|
|
||||||
Button,
|
|
||||||
List,
|
|
||||||
ListItem,
|
|
||||||
ListSubheader,
|
|
||||||
Tooltip,
|
|
||||||
Typography,
|
|
||||||
useTheme
|
|
||||||
} from '@mui/material'
|
|
||||||
import JSZip from 'jszip'
|
import JSZip from 'jszip'
|
||||||
import { MuiFileInput } from 'mui-file-input'
|
import { MuiFileInput } from 'mui-file-input'
|
||||||
import { Event, kinds, verifyEvent } from 'nostr-tools'
|
import { Event, verifyEvent } from 'nostr-tools'
|
||||||
import { useEffect, useState } from 'react'
|
import { useEffect, useState } from 'react'
|
||||||
import { toast } from 'react-toastify'
|
import { toast } from 'react-toastify'
|
||||||
import { LoadingSpinner } from '../../components/LoadingSpinner'
|
import { LoadingSpinner } from '../../components/LoadingSpinner'
|
||||||
import { UserAvatar } from '../../components/UserAvatar'
|
import { NostrController } from '../../controllers'
|
||||||
import { MetadataController, NostrController } from '../../controllers'
|
import { CreateSignatureEventContent, Meta } from '../../types'
|
||||||
import {
|
|
||||||
CreateSignatureEventContent,
|
|
||||||
Meta,
|
|
||||||
ProfileMetadata,
|
|
||||||
SignedEventContent
|
|
||||||
} from '../../types'
|
|
||||||
import {
|
import {
|
||||||
decryptArrayBuffer,
|
decryptArrayBuffer,
|
||||||
extractMarksFromSignedMeta,
|
extractMarksFromSignedMeta,
|
||||||
extractZipUrlAndEncryptionKey,
|
|
||||||
getHash,
|
getHash,
|
||||||
hexToNpub,
|
hexToNpub,
|
||||||
unixNow,
|
unixNow,
|
||||||
npubToHex,
|
|
||||||
parseJson,
|
parseJson,
|
||||||
readContentOfZipEntry,
|
readContentOfZipEntry,
|
||||||
shorten,
|
signEventForMetaFile,
|
||||||
signEventForMetaFile
|
shorten
|
||||||
} from '../../utils'
|
} from '../../utils'
|
||||||
import styles from './style.module.scss'
|
import styles from './style.module.scss'
|
||||||
import { Cancel, CheckCircle } from '@mui/icons-material'
|
import { Cancel, CheckCircle } from '@mui/icons-material'
|
||||||
@ -51,6 +34,12 @@ import { useSelector } from 'react-redux'
|
|||||||
import { getLastSignersSig } from '../../utils/sign.ts'
|
import { getLastSignersSig } from '../../utils/sign.ts'
|
||||||
import { saveAs } from 'file-saver'
|
import { saveAs } from 'file-saver'
|
||||||
import { Container } from '../../components/Container'
|
import { Container } from '../../components/Container'
|
||||||
|
import { useSigitMeta } from '../../hooks/useSigitMeta.tsx'
|
||||||
|
import { StickySideColumns } from '../../layouts/StickySideColumns.tsx'
|
||||||
|
import { UsersDetails } from '../../components/UsersDetails.tsx/index.tsx'
|
||||||
|
import { UserAvatar } from '../../components/UserAvatar/index.tsx'
|
||||||
|
import { useSigitProfiles } from '../../hooks/useSigitProfiles.tsx'
|
||||||
|
import { TooltipChild } from '../../components/TooltipChild.tsx'
|
||||||
|
|
||||||
export const VerifyPage = () => {
|
export const VerifyPage = () => {
|
||||||
const theme = useTheme()
|
const theme = useTheme()
|
||||||
@ -63,52 +52,36 @@ export const VerifyPage = () => {
|
|||||||
* uploadedZip will be received from home page when a user uploads a sigit zip wrapper that contains meta.json
|
* uploadedZip will be received from home page when a user uploads a sigit zip wrapper that contains meta.json
|
||||||
* meta will be received in navigation from create & home page in online mode
|
* meta will be received in navigation from create & home page in online mode
|
||||||
*/
|
*/
|
||||||
const { uploadedZip, meta: metaInNavState } = location.state || {}
|
const { uploadedZip, meta } = location.state || {}
|
||||||
|
|
||||||
|
const { submittedBy, zipUrl, encryptionKey, signers, viewers, fileHashes } =
|
||||||
|
useSigitMeta(meta)
|
||||||
|
|
||||||
|
const profiles = useSigitProfiles([
|
||||||
|
...(submittedBy ? [submittedBy] : []),
|
||||||
|
...signers,
|
||||||
|
...viewers
|
||||||
|
])
|
||||||
|
|
||||||
const [isLoading, setIsLoading] = useState(false)
|
const [isLoading, setIsLoading] = useState(false)
|
||||||
const [loadingSpinnerDesc, setLoadingSpinnerDesc] = useState('')
|
const [loadingSpinnerDesc, setLoadingSpinnerDesc] = useState('')
|
||||||
|
|
||||||
const [selectedFile, setSelectedFile] = useState<File | null>(null)
|
const [selectedFile, setSelectedFile] = useState<File | null>(null)
|
||||||
const [meta, setMeta] = useState<Meta | null>(null)
|
|
||||||
|
|
||||||
const [submittedBy, setSubmittedBy] = useState<string>()
|
|
||||||
|
|
||||||
const [signers, setSigners] = useState<`npub1${string}`[]>([])
|
|
||||||
const [viewers, setViewers] = useState<`npub1${string}`[]>([])
|
|
||||||
const [creatorFileHashes, setCreatorFileHashes] = useState<{
|
|
||||||
[key: string]: string
|
|
||||||
}>({})
|
|
||||||
const [currentFileHashes, setCurrentFileHashes] = useState<{
|
const [currentFileHashes, setCurrentFileHashes] = useState<{
|
||||||
[key: string]: string | null
|
[key: string]: string | null
|
||||||
}>({})
|
}>(fileHashes)
|
||||||
const [files, setFiles] = useState<{ [filename: string]: PdfFile }>({})
|
const [files, setFiles] = useState<{ [filename: string]: PdfFile }>({})
|
||||||
|
|
||||||
const [metadata, setMetadata] = useState<{ [key: string]: ProfileMetadata }>(
|
|
||||||
{}
|
|
||||||
)
|
|
||||||
const usersPubkey = useSelector((state: State) => state.auth.usersPubkey)
|
const usersPubkey = useSelector((state: State) => state.auth.usersPubkey)
|
||||||
const nostrController = NostrController.getInstance()
|
const nostrController = NostrController.getInstance()
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (uploadedZip) {
|
if (uploadedZip) {
|
||||||
setSelectedFile(uploadedZip)
|
setSelectedFile(uploadedZip)
|
||||||
} else if (metaInNavState) {
|
} else if (meta && encryptionKey) {
|
||||||
const processSigit = async () => {
|
const processSigit = async () => {
|
||||||
setIsLoading(true)
|
setIsLoading(true)
|
||||||
setLoadingSpinnerDesc('Extracting zipUrl and encryption key from meta')
|
|
||||||
|
|
||||||
const res = await extractZipUrlAndEncryptionKey(metaInNavState)
|
|
||||||
if (!res) {
|
|
||||||
setIsLoading(false)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
const {
|
|
||||||
zipUrl,
|
|
||||||
encryptionKey,
|
|
||||||
createSignatureEvent,
|
|
||||||
createSignatureContent
|
|
||||||
} = res
|
|
||||||
|
|
||||||
setLoadingSpinnerDesc('Fetching file from file server')
|
setLoadingSpinnerDesc('Fetching file from file server')
|
||||||
axios
|
axios
|
||||||
@ -175,12 +148,6 @@ export const VerifyPage = () => {
|
|||||||
setCurrentFileHashes(fileHashes)
|
setCurrentFileHashes(fileHashes)
|
||||||
setFiles(files)
|
setFiles(files)
|
||||||
|
|
||||||
setSigners(createSignatureContent.signers)
|
|
||||||
setViewers(createSignatureContent.viewers)
|
|
||||||
setCreatorFileHashes(createSignatureContent.fileHashes)
|
|
||||||
setSubmittedBy(createSignatureEvent.pubkey)
|
|
||||||
|
|
||||||
setMeta(metaInNavState)
|
|
||||||
setIsLoading(false)
|
setIsLoading(false)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
@ -197,49 +164,7 @@ export const VerifyPage = () => {
|
|||||||
|
|
||||||
processSigit()
|
processSigit()
|
||||||
}
|
}
|
||||||
}, [uploadedZip, metaInNavState])
|
}, [encryptionKey, meta, uploadedZip, zipUrl])
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
if (submittedBy) {
|
|
||||||
const metadataController = new MetadataController()
|
|
||||||
|
|
||||||
const users = [submittedBy, ...signers, ...viewers]
|
|
||||||
|
|
||||||
users.forEach((user) => {
|
|
||||||
const pubkey = npubToHex(user)!
|
|
||||||
|
|
||||||
if (!(pubkey in metadata)) {
|
|
||||||
const handleMetadataEvent = (event: Event) => {
|
|
||||||
const metadataContent =
|
|
||||||
metadataController.extractProfileMetadataContent(event)
|
|
||||||
if (metadataContent)
|
|
||||||
setMetadata((prev) => ({
|
|
||||||
...prev,
|
|
||||||
[pubkey]: metadataContent
|
|
||||||
}))
|
|
||||||
}
|
|
||||||
|
|
||||||
metadataController.on(pubkey, (kind: number, event: Event) => {
|
|
||||||
if (kind === kinds.Metadata) {
|
|
||||||
handleMetadataEvent(event)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
metadataController
|
|
||||||
.findMetadata(pubkey)
|
|
||||||
.then((metadataEvent) => {
|
|
||||||
if (metadataEvent) handleMetadataEvent(metadataEvent)
|
|
||||||
})
|
|
||||||
.catch((err) => {
|
|
||||||
console.error(
|
|
||||||
`error occurred in finding metadata for: ${user}`,
|
|
||||||
err
|
|
||||||
)
|
|
||||||
})
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}, [submittedBy, signers, viewers, metadata])
|
|
||||||
|
|
||||||
const handleVerify = async () => {
|
const handleVerify = async () => {
|
||||||
if (!selectedFile) return
|
if (!selectedFile) return
|
||||||
@ -345,44 +270,9 @@ export const VerifyPage = () => {
|
|||||||
|
|
||||||
if (!createSignatureContent) return
|
if (!createSignatureContent) return
|
||||||
|
|
||||||
setSigners(createSignatureContent.signers)
|
|
||||||
setViewers(createSignatureContent.viewers)
|
|
||||||
setCreatorFileHashes(createSignatureContent.fileHashes)
|
|
||||||
setSubmittedBy(createSignatureEvent.pubkey)
|
|
||||||
|
|
||||||
setMeta(parsedMetaJson)
|
|
||||||
setIsLoading(false)
|
setIsLoading(false)
|
||||||
}
|
}
|
||||||
|
|
||||||
const getPrevSignersSig = (npub: string) => {
|
|
||||||
if (!meta) return null
|
|
||||||
|
|
||||||
// if user is first signer then use creator's signature
|
|
||||||
if (signers[0] === npub) {
|
|
||||||
try {
|
|
||||||
const createSignatureEvent: Event = JSON.parse(meta.createSignature)
|
|
||||||
return createSignatureEvent.sig
|
|
||||||
} catch (error) {
|
|
||||||
return null
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// find the index of signer
|
|
||||||
const currentSignerIndex = signers.findIndex((signer) => signer === npub)
|
|
||||||
// return null if could not found user in signer's list
|
|
||||||
if (currentSignerIndex === -1) return null
|
|
||||||
// find prev signer
|
|
||||||
const prevSigner = signers[currentSignerIndex - 1]
|
|
||||||
|
|
||||||
// get the signature of prev signer
|
|
||||||
try {
|
|
||||||
const prevSignersEvent: Event = JSON.parse(meta.docSignatures[prevSigner])
|
|
||||||
return prevSignersEvent.sig
|
|
||||||
} catch (error) {
|
|
||||||
return null
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const handleExport = async () => {
|
const handleExport = async () => {
|
||||||
if (Object.entries(files).length === 0 || !meta || !usersPubkey) return
|
if (Object.entries(files).length === 0 || !meta || !usersPubkey) return
|
||||||
|
|
||||||
@ -398,8 +288,6 @@ export const VerifyPage = () => {
|
|||||||
setIsLoading(true)
|
setIsLoading(true)
|
||||||
setLoadingSpinnerDesc('Signing nostr event')
|
setLoadingSpinnerDesc('Signing nostr event')
|
||||||
|
|
||||||
if (!meta) return
|
|
||||||
|
|
||||||
const prevSig = getLastSignersSig(meta, signers)
|
const prevSig = getLastSignersSig(meta, signers)
|
||||||
if (!prevSig) return
|
if (!prevSig) return
|
||||||
|
|
||||||
@ -424,7 +312,7 @@ export const VerifyPage = () => {
|
|||||||
for (const [fileName, pdf] of Object.entries(files)) {
|
for (const [fileName, pdf] of Object.entries(files)) {
|
||||||
const pages = await addMarks(pdf.file, marksByPage)
|
const pages = await addMarks(pdf.file, marksByPage)
|
||||||
const blob = await convertToPdfBlob(pages)
|
const blob = await convertToPdfBlob(pages)
|
||||||
zip.file(`/files/${fileName}`, blob)
|
zip.file(`files/${fileName}`, blob)
|
||||||
}
|
}
|
||||||
|
|
||||||
const arrayBuffer = await zip
|
const arrayBuffer = await zip
|
||||||
@ -450,76 +338,6 @@ export const VerifyPage = () => {
|
|||||||
setIsLoading(false)
|
setIsLoading(false)
|
||||||
}
|
}
|
||||||
|
|
||||||
const displayUser = (pubkey: string, verifySignature = false) => {
|
|
||||||
const profile = metadata[pubkey]
|
|
||||||
|
|
||||||
let isValidSignature = false
|
|
||||||
|
|
||||||
if (verifySignature) {
|
|
||||||
const npub = hexToNpub(pubkey)
|
|
||||||
const signedEventString = meta ? meta.docSignatures[npub] : null
|
|
||||||
if (signedEventString) {
|
|
||||||
try {
|
|
||||||
const signedEvent = JSON.parse(signedEventString)
|
|
||||||
const isVerifiedEvent = verifyEvent(signedEvent)
|
|
||||||
|
|
||||||
if (isVerifiedEvent) {
|
|
||||||
// get the actual signature of prev signer
|
|
||||||
const prevSignersSig = getPrevSignersSig(npub)
|
|
||||||
|
|
||||||
// get the signature of prev signer from the content of current signers signedEvent
|
|
||||||
|
|
||||||
try {
|
|
||||||
const obj: SignedEventContent = JSON.parse(signedEvent.content)
|
|
||||||
if (
|
|
||||||
obj.prevSig &&
|
|
||||||
prevSignersSig &&
|
|
||||||
obj.prevSig === prevSignersSig
|
|
||||||
) {
|
|
||||||
isValidSignature = true
|
|
||||||
}
|
|
||||||
} catch (error) {
|
|
||||||
isValidSignature = false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} catch (error) {
|
|
||||||
console.error(
|
|
||||||
`An error occurred in parsing and verifying the signature event for ${pubkey}`,
|
|
||||||
error
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return (
|
|
||||||
<>
|
|
||||||
<UserAvatar
|
|
||||||
pubkey={pubkey}
|
|
||||||
name={
|
|
||||||
profile?.display_name || profile?.name || shorten(hexToNpub(pubkey))
|
|
||||||
}
|
|
||||||
image={profile?.picture}
|
|
||||||
/>
|
|
||||||
|
|
||||||
{verifySignature && (
|
|
||||||
<>
|
|
||||||
{isValidSignature && (
|
|
||||||
<Tooltip title="Valid signature">
|
|
||||||
<CheckCircle sx={{ color: theme.palette.success.light }} />
|
|
||||||
</Tooltip>
|
|
||||||
)}
|
|
||||||
|
|
||||||
{!isValidSignature && (
|
|
||||||
<Tooltip title="Invalid signature">
|
|
||||||
<Cancel sx={{ color: theme.palette.error.main }} />
|
|
||||||
</Tooltip>
|
|
||||||
)}
|
|
||||||
</>
|
|
||||||
)}
|
|
||||||
</>
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
const displayExportedBy = () => {
|
const displayExportedBy = () => {
|
||||||
if (!meta || !meta.exportSignature) return null
|
if (!meta || !meta.exportSignature) return null
|
||||||
|
|
||||||
@ -529,7 +347,24 @@ export const VerifyPage = () => {
|
|||||||
const exportSignatureEvent = JSON.parse(exportSignatureString) as Event
|
const exportSignatureEvent = JSON.parse(exportSignatureString) as Event
|
||||||
|
|
||||||
if (verifyEvent(exportSignatureEvent)) {
|
if (verifyEvent(exportSignatureEvent)) {
|
||||||
return displayUser(exportSignatureEvent.pubkey)
|
const exportedBy = exportSignatureEvent.pubkey
|
||||||
|
const profile = profiles[exportedBy]
|
||||||
|
return (
|
||||||
|
<Tooltip
|
||||||
|
title={
|
||||||
|
profile?.display_name ||
|
||||||
|
profile?.name ||
|
||||||
|
shorten(hexToNpub(exportedBy))
|
||||||
|
}
|
||||||
|
placement="top"
|
||||||
|
arrow
|
||||||
|
disableInteractive
|
||||||
|
>
|
||||||
|
<TooltipChild>
|
||||||
|
<UserAvatar pubkey={exportedBy} image={profile?.picture} />
|
||||||
|
</TooltipChild>
|
||||||
|
</Tooltip>
|
||||||
|
)
|
||||||
} else {
|
} else {
|
||||||
toast.error(`Invalid export signature!`)
|
toast.error(`Invalid export signature!`)
|
||||||
return (
|
return (
|
||||||
@ -576,113 +411,13 @@ export const VerifyPage = () => {
|
|||||||
)}
|
)}
|
||||||
|
|
||||||
{meta && (
|
{meta && (
|
||||||
<>
|
<StickySideColumns
|
||||||
<List
|
left={
|
||||||
sx={{
|
<>
|
||||||
bgcolor: 'background.paper',
|
|
||||||
marginTop: 2
|
|
||||||
}}
|
|
||||||
subheader={
|
|
||||||
<ListSubheader className={styles.subHeader}>
|
|
||||||
Meta Info
|
|
||||||
</ListSubheader>
|
|
||||||
}
|
|
||||||
>
|
|
||||||
{submittedBy && (
|
|
||||||
<ListItem
|
|
||||||
sx={{
|
|
||||||
marginTop: 1,
|
|
||||||
gap: '15px'
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<Typography variant="h6" sx={{ color: textColor }}>
|
|
||||||
Submitted By
|
|
||||||
</Typography>
|
|
||||||
{displayUser(submittedBy)}
|
|
||||||
</ListItem>
|
|
||||||
)}
|
|
||||||
|
|
||||||
<ListItem
|
|
||||||
sx={{
|
|
||||||
marginTop: 1,
|
|
||||||
gap: '15px'
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<Typography variant="h6" sx={{ color: textColor }}>
|
|
||||||
Exported By
|
|
||||||
</Typography>
|
|
||||||
{displayExportedBy()}
|
|
||||||
<Box sx={{ mt: 1, display: 'flex', justifyContent: 'center' }}>
|
|
||||||
<Button onClick={handleExport} variant="contained">
|
|
||||||
Export Sigit
|
|
||||||
</Button>
|
|
||||||
</Box>
|
|
||||||
</ListItem>
|
|
||||||
|
|
||||||
{signers.length > 0 && (
|
|
||||||
<ListItem
|
|
||||||
sx={{
|
|
||||||
marginTop: 1,
|
|
||||||
flexDirection: 'column',
|
|
||||||
alignItems: 'flex-start'
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<Typography variant="h6" sx={{ color: textColor }}>
|
|
||||||
Signers
|
|
||||||
</Typography>
|
|
||||||
<ul className={styles.usersList}>
|
|
||||||
{signers.map((signer) => (
|
|
||||||
<li
|
|
||||||
key={signer}
|
|
||||||
style={{
|
|
||||||
color: textColor,
|
|
||||||
display: 'flex',
|
|
||||||
alignItems: 'center',
|
|
||||||
gap: '15px'
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
{displayUser(npubToHex(signer)!, true)}
|
|
||||||
</li>
|
|
||||||
))}
|
|
||||||
</ul>
|
|
||||||
</ListItem>
|
|
||||||
)}
|
|
||||||
|
|
||||||
{viewers.length > 0 && (
|
|
||||||
<ListItem
|
|
||||||
sx={{
|
|
||||||
marginTop: 1,
|
|
||||||
flexDirection: 'column',
|
|
||||||
alignItems: 'flex-start'
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<Typography variant="h6" sx={{ color: textColor }}>
|
|
||||||
Viewers
|
|
||||||
</Typography>
|
|
||||||
<ul className={styles.usersList}>
|
|
||||||
{viewers.map((viewer) => (
|
|
||||||
<li key={viewer} style={{ color: textColor }}>
|
|
||||||
{displayUser(npubToHex(viewer)!)}
|
|
||||||
</li>
|
|
||||||
))}
|
|
||||||
</ul>
|
|
||||||
</ListItem>
|
|
||||||
)}
|
|
||||||
|
|
||||||
<ListItem
|
|
||||||
sx={{
|
|
||||||
marginTop: 1,
|
|
||||||
flexDirection: 'column',
|
|
||||||
alignItems: 'flex-start'
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<Typography variant="h6" sx={{ color: textColor }}>
|
|
||||||
Files
|
|
||||||
</Typography>
|
|
||||||
<Box className={styles.filesWrapper}>
|
<Box className={styles.filesWrapper}>
|
||||||
{Object.entries(currentFileHashes).map(
|
{Object.entries(currentFileHashes).map(
|
||||||
([filename, hash], index) => {
|
([filename, hash], index) => {
|
||||||
const isValidHash = creatorFileHashes[filename] === hash
|
const isValidHash = fileHashes[filename] === hash
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Box key={`file-${index}`} className={styles.file}>
|
<Box key={`file-${index}`} className={styles.file}>
|
||||||
@ -714,9 +449,16 @@ export const VerifyPage = () => {
|
|||||||
}
|
}
|
||||||
)}
|
)}
|
||||||
</Box>
|
</Box>
|
||||||
</ListItem>
|
{displayExportedBy()}
|
||||||
</List>
|
<Box sx={{ mt: 1, display: 'flex', justifyContent: 'center' }}>
|
||||||
</>
|
<Button onClick={handleExport} variant="contained">
|
||||||
|
Export Sigit
|
||||||
|
</Button>
|
||||||
|
</Box>
|
||||||
|
</>
|
||||||
|
}
|
||||||
|
right={<UsersDetails meta={meta} />}
|
||||||
|
/>
|
||||||
)}
|
)}
|
||||||
</Container>
|
</Container>
|
||||||
</>
|
</>
|
||||||
|
9
src/types/file.ts
Normal file
9
src/types/file.ts
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
import { PdfFile } from './drawing.ts'
|
||||||
|
|
||||||
|
export interface CurrentUserFile {
|
||||||
|
id: number
|
||||||
|
pdfFile: PdfFile
|
||||||
|
filename: string
|
||||||
|
hash?: string
|
||||||
|
isHashValid: boolean
|
||||||
|
}
|
@ -1,9 +1,11 @@
|
|||||||
import { MarkType } from './drawing'
|
import { MarkType } from './drawing'
|
||||||
|
|
||||||
export interface CurrentUserMark {
|
export interface CurrentUserMark {
|
||||||
|
id: number
|
||||||
mark: Mark
|
mark: Mark
|
||||||
isLast: boolean
|
isLast: boolean
|
||||||
isCompleted: boolean
|
isCompleted: boolean
|
||||||
|
currentValue?: string
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface Mark {
|
export interface Mark {
|
||||||
@ -12,6 +14,7 @@ export interface Mark {
|
|||||||
pdfFileHash: string
|
pdfFileHash: string
|
||||||
type: MarkType
|
type: MarkType
|
||||||
location: MarkLocation
|
location: MarkLocation
|
||||||
|
fileName: string
|
||||||
value?: string
|
value?: string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -4,6 +4,11 @@ export const EMPTY: string = ''
|
|||||||
export const MARK_TYPE_TRANSLATION: { [key: string]: string } = {
|
export const MARK_TYPE_TRANSLATION: { [key: string]: string } = {
|
||||||
[MarkType.FULLNAME.valueOf()]: 'Full Name'
|
[MarkType.FULLNAME.valueOf()]: 'Full Name'
|
||||||
}
|
}
|
||||||
|
export const SIGN: string = 'Sign'
|
||||||
|
export const NEXT: string = 'Next'
|
||||||
|
export const ARRAY_BUFFER = 'arraybuffer'
|
||||||
|
export const DEFLATE = 'DEFLATE'
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Number of milliseconds in one week.
|
* Number of milliseconds in one week.
|
||||||
* Calc based on: 7 * 24 * 60 * 60 * 1000
|
* Calc based on: 7 * 24 * 60 * 60 * 1000
|
||||||
|
24
src/utils/file.ts
Normal file
24
src/utils/file.ts
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
import { Meta } from '../types'
|
||||||
|
import { extractMarksFromSignedMeta } from './mark.ts'
|
||||||
|
import { addMarks, convertToPdfBlob, groupMarksByPage } from './pdf.ts'
|
||||||
|
import JSZip from 'jszip'
|
||||||
|
import { PdfFile } from '../types/drawing.ts'
|
||||||
|
|
||||||
|
const getZipWithFiles = async (
|
||||||
|
meta: Meta,
|
||||||
|
files: { [filename: string]: PdfFile }
|
||||||
|
): Promise<JSZip> => {
|
||||||
|
const zip = new JSZip()
|
||||||
|
const marks = extractMarksFromSignedMeta(meta)
|
||||||
|
const marksByPage = groupMarksByPage(marks)
|
||||||
|
|
||||||
|
for (const [fileName, pdf] of Object.entries(files)) {
|
||||||
|
const pages = await addMarks(pdf.file, marksByPage)
|
||||||
|
const blob = await convertToPdfBlob(pages)
|
||||||
|
zip.file(`/files/${fileName}`, blob)
|
||||||
|
}
|
||||||
|
|
||||||
|
return zip
|
||||||
|
}
|
||||||
|
|
||||||
|
export { getZipWithFiles }
|
@ -2,6 +2,7 @@ import { CurrentUserMark, Mark } from '../types/mark.ts'
|
|||||||
import { hexToNpub } from './nostr.ts'
|
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'
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Takes in an array of Marks already filtered by User.
|
* Takes in an array of Marks already filtered by User.
|
||||||
@ -15,13 +16,12 @@ const getCurrentUserMarks = (
|
|||||||
): CurrentUserMark[] => {
|
): CurrentUserMark[] => {
|
||||||
return marks.map((mark, index, arr) => {
|
return marks.map((mark, index, arr) => {
|
||||||
const signedMark = signedMetaMarks.find((m) => m.id === mark.id)
|
const signedMark = signedMetaMarks.find((m) => m.id === mark.id)
|
||||||
if (signedMark && !!signedMark.value) {
|
|
||||||
mark.value = signedMark.value
|
|
||||||
}
|
|
||||||
return {
|
return {
|
||||||
mark,
|
mark,
|
||||||
|
currentValue: signedMark?.value ?? EMPTY,
|
||||||
|
id: index + 1,
|
||||||
isLast: isLast(index, arr),
|
isLast: isLast(index, arr),
|
||||||
isCompleted: !!mark.value
|
isCompleted: !!signedMark?.value
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@ -30,7 +30,7 @@ const getCurrentUserMarks = (
|
|||||||
* Returns next incomplete CurrentUserMark if there is one
|
* Returns next incomplete CurrentUserMark if there is one
|
||||||
* @param usersMarks
|
* @param usersMarks
|
||||||
*/
|
*/
|
||||||
const findNextCurrentUserMark = (
|
const findNextIncompleteCurrentUserMark = (
|
||||||
usersMarks: CurrentUserMark[]
|
usersMarks: CurrentUserMark[]
|
||||||
): CurrentUserMark | undefined => {
|
): CurrentUserMark | undefined => {
|
||||||
return usersMarks.find((mark) => !mark.isCompleted)
|
return usersMarks.find((mark) => !mark.isCompleted)
|
||||||
@ -99,12 +99,38 @@ const updateCurrentUserMarks = (
|
|||||||
|
|
||||||
const isLast = <T>(index: number, arr: T[]) => index === arr.length - 1
|
const isLast = <T>(index: number, arr: T[]) => index === arr.length - 1
|
||||||
|
|
||||||
|
const isCurrentValueLast = (
|
||||||
|
currentUserMarks: CurrentUserMark[],
|
||||||
|
selectedMark: CurrentUserMark,
|
||||||
|
selectedMarkValue: string
|
||||||
|
) => {
|
||||||
|
const filteredMarks = currentUserMarks.filter(
|
||||||
|
(mark) => mark.id !== selectedMark.id
|
||||||
|
)
|
||||||
|
return (
|
||||||
|
isCurrentUserMarksComplete(filteredMarks) && selectedMarkValue.length > 0
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
const getUpdatedMark = (
|
||||||
|
selectedMark: CurrentUserMark,
|
||||||
|
selectedMarkValue: string
|
||||||
|
): CurrentUserMark => {
|
||||||
|
return {
|
||||||
|
...selectedMark,
|
||||||
|
currentValue: selectedMarkValue,
|
||||||
|
isCompleted: !!selectedMarkValue
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
export {
|
export {
|
||||||
getCurrentUserMarks,
|
getCurrentUserMarks,
|
||||||
filterMarksByPubkey,
|
filterMarksByPubkey,
|
||||||
extractMarksFromSignedMeta,
|
extractMarksFromSignedMeta,
|
||||||
isCurrentUserMarksComplete,
|
isCurrentUserMarksComplete,
|
||||||
findNextCurrentUserMark,
|
findNextIncompleteCurrentUserMark,
|
||||||
updateMarks,
|
updateMarks,
|
||||||
updateCurrentUserMarks
|
updateCurrentUserMarks,
|
||||||
|
isCurrentValueLast,
|
||||||
|
getUpdatedMark
|
||||||
}
|
}
|
||||||
|
@ -5,8 +5,10 @@ import { toast } from 'react-toastify'
|
|||||||
|
|
||||||
export enum SignStatus {
|
export enum SignStatus {
|
||||||
Signed = 'Signed',
|
Signed = 'Signed',
|
||||||
|
Awaiting = 'Awaiting',
|
||||||
Pending = 'Pending',
|
Pending = 'Pending',
|
||||||
Invalid = 'Invalid Sign'
|
Invalid = 'Invalid',
|
||||||
|
Viewer = 'Viewer'
|
||||||
}
|
}
|
||||||
|
|
||||||
export enum SigitStatus {
|
export enum SigitStatus {
|
||||||
@ -62,38 +64,33 @@ function handleError(error: unknown): Error {
|
|||||||
|
|
||||||
// Reuse common error messages for meta parsing
|
// Reuse common error messages for meta parsing
|
||||||
export enum SigitMetaParseErrorType {
|
export enum SigitMetaParseErrorType {
|
||||||
'PARSE_ERROR_SIGNATURE_EVENT' = 'error occurred in parsing the create signature event',
|
'PARSE_ERROR_EVENT' = 'error occurred in parsing the create signature event',
|
||||||
'PARSE_ERROR_SIGNATURE_EVENT_CONTENT' = "err in parsing the createSignature event's content"
|
'PARSE_ERROR_SIGNATURE_EVENT_CONTENT' = "err in parsing the createSignature event's content"
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface SigitCardDisplayInfo {
|
export interface SigitCardDisplayInfo {
|
||||||
createdAt?: number
|
createdAt?: number
|
||||||
title?: string
|
title?: string
|
||||||
submittedBy?: string
|
submittedBy?: `npub1${string}`
|
||||||
signers: `npub1${string}`[]
|
signers: `npub1${string}`[]
|
||||||
fileExtensions: string[]
|
fileExtensions: string[]
|
||||||
signedStatus: SigitStatus
|
signedStatus: SigitStatus
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Wrapper for createSignatureEvent parse that throws custom SigitMetaParseError with cause and context
|
* Wrapper for event parser that throws custom SigitMetaParseError with cause and context
|
||||||
* @param raw Raw string for parsing
|
* @param raw Raw string for parsing
|
||||||
* @returns parsed Event
|
* @returns parsed Event
|
||||||
*/
|
*/
|
||||||
export const parseCreateSignatureEvent = async (
|
export const parseNostrEvent = async (raw: string): Promise<Event> => {
|
||||||
raw: string
|
|
||||||
): Promise<Event> => {
|
|
||||||
try {
|
try {
|
||||||
const createSignatureEvent = await parseJson<Event>(raw)
|
const event = await parseJson<Event>(raw)
|
||||||
return createSignatureEvent
|
return event
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
throw new SigitMetaParseError(
|
throw new SigitMetaParseError(SigitMetaParseErrorType.PARSE_ERROR_EVENT, {
|
||||||
SigitMetaParseErrorType.PARSE_ERROR_SIGNATURE_EVENT,
|
cause: handleError(error),
|
||||||
{
|
context: raw
|
||||||
cause: handleError(error),
|
})
|
||||||
context: raw
|
|
||||||
}
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -135,9 +132,7 @@ export const extractSigitCardDisplayInfo = async (meta: Meta) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const createSignatureEvent = await parseCreateSignatureEvent(
|
const createSignatureEvent = await parseNostrEvent(meta.createSignature)
|
||||||
meta.createSignature
|
|
||||||
)
|
|
||||||
|
|
||||||
// created_at in nostr events are stored in seconds
|
// created_at in nostr events are stored in seconds
|
||||||
sigitInfo.createdAt = fromUnixTimestamp(createSignatureEvent.created_at)
|
sigitInfo.createdAt = fromUnixTimestamp(createSignatureEvent.created_at)
|
||||||
@ -147,13 +142,7 @@ export const extractSigitCardDisplayInfo = async (meta: Meta) => {
|
|||||||
)
|
)
|
||||||
|
|
||||||
const files = Object.keys(createSignatureContent.fileHashes)
|
const files = Object.keys(createSignatureContent.fileHashes)
|
||||||
const extensions = files.reduce((result: string[], file: string) => {
|
const extensions = extractFileExtensions(files)
|
||||||
const extension = file.split('.').pop()
|
|
||||||
if (extension) {
|
|
||||||
result.push(extension)
|
|
||||||
}
|
|
||||||
return result
|
|
||||||
}, [])
|
|
||||||
|
|
||||||
const signedBy = Object.keys(meta.docSignatures) as `npub1${string}`[]
|
const signedBy = Object.keys(meta.docSignatures) as `npub1${string}`[]
|
||||||
const isCompletelySigned = createSignatureContent.signers.every((signer) =>
|
const isCompletelySigned = createSignatureContent.signers.every((signer) =>
|
||||||
@ -161,7 +150,7 @@ export const extractSigitCardDisplayInfo = async (meta: Meta) => {
|
|||||||
)
|
)
|
||||||
|
|
||||||
sigitInfo.title = createSignatureContent.title
|
sigitInfo.title = createSignatureContent.title
|
||||||
sigitInfo.submittedBy = createSignatureEvent.pubkey
|
sigitInfo.submittedBy = createSignatureEvent.pubkey as `npub1${string}`
|
||||||
sigitInfo.signers = createSignatureContent.signers
|
sigitInfo.signers = createSignatureContent.signers
|
||||||
sigitInfo.fileExtensions = extensions
|
sigitInfo.fileExtensions = extensions
|
||||||
|
|
||||||
@ -179,3 +168,15 @@ export const extractSigitCardDisplayInfo = async (meta: Meta) => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export const extractFileExtensions = (fileNames: string[]) => {
|
||||||
|
const extensions = fileNames.reduce((result: string[], file: string) => {
|
||||||
|
const extension = file.split('.').pop()
|
||||||
|
if (extension) {
|
||||||
|
result.push(extension)
|
||||||
|
}
|
||||||
|
return result
|
||||||
|
}, [])
|
||||||
|
|
||||||
|
return extensions
|
||||||
|
}
|
||||||
|
@ -142,7 +142,7 @@ const addMarks = async (
|
|||||||
canvas.width = viewport.width
|
canvas.width = viewport.width
|
||||||
await page.render({ canvasContext: context!, viewport: viewport }).promise
|
await page.render({ canvasContext: context!, viewport: viewport }).promise
|
||||||
|
|
||||||
marksPerPage[i].forEach((mark) => draw(mark, context!))
|
marksPerPage[i]?.forEach((mark) => draw(mark, context!))
|
||||||
|
|
||||||
images.push(canvas.toDataURL())
|
images.push(canvas.toDataURL())
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
import { PdfFile } from '../types/drawing.ts'
|
import { PdfFile } from '../types/drawing.ts'
|
||||||
|
import { CurrentUserFile } from '../types/file.ts'
|
||||||
|
|
||||||
export const compareObjects = (
|
export const compareObjects = (
|
||||||
obj1: object | null | undefined,
|
obj1: object | null | undefined,
|
||||||
@ -71,12 +72,20 @@ export const timeout = (ms: number = 60000) => {
|
|||||||
* including its name, hash, and content
|
* including its name, hash, and content
|
||||||
* @param files
|
* @param files
|
||||||
* @param fileHashes
|
* @param fileHashes
|
||||||
|
* @param creatorFileHashes
|
||||||
*/
|
*/
|
||||||
export const getFilesWithHashes = (
|
export const getCurrentUserFiles = (
|
||||||
files: { [filename: string]: PdfFile },
|
files: { [filename: string]: PdfFile },
|
||||||
fileHashes: { [key: string]: string | null }
|
fileHashes: { [key: string]: string | null },
|
||||||
) => {
|
creatorFileHashes: { [key: string]: string }
|
||||||
return Object.entries(files).map(([filename, pdfFile]) => {
|
): CurrentUserFile[] => {
|
||||||
return { pdfFile, filename, hash: fileHashes[filename] }
|
return Object.entries(files).map(([filename, pdfFile], index) => {
|
||||||
|
return {
|
||||||
|
pdfFile,
|
||||||
|
filename,
|
||||||
|
id: index + 1,
|
||||||
|
...(!!fileHashes[filename] && { hash: fileHashes[filename]! }),
|
||||||
|
isHashValid: creatorFileHashes[filename] === fileHashes[filename]
|
||||||
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user