diff --git a/src/App.scss b/src/App.scss
index 6724890..f21738d 100644
--- a/src/App.scss
+++ b/src/App.scss
@@ -69,3 +69,73 @@ a {
input {
font-family: inherit;
}
+
+// Shared styles for center content (Create, Sign, Verify)
+.files-wrapper {
+ display: flex;
+ flex-direction: column;
+ gap: 25px;
+}
+
+.file-wrapper {
+ display: flex;
+ flex-direction: column;
+ gap: 15px;
+ position: relative;
+
+ // CSS, scroll position when scrolling to the files is adjusted by
+ // - first-child Header height, default body padding, and center content border (10px) and padding (10px)
+ // - others We don't include border and padding and scroll to the top of the image
+ &:first-child {
+ scroll-margin-top: $header-height + $body-vertical-padding + 20px;
+ }
+ &:not(:first-child) {
+ scroll-margin-top: $header-height + $body-vertical-padding;
+ }
+}
+
+// For pdf marks
+.image-wrapper {
+ position: relative;
+ -webkit-user-select: none;
+ user-select: none;
+
+ overflow: hidden; /* Ensure no overflow */
+
+ > img {
+ display: block;
+ max-width: 100%;
+ max-height: 100%;
+ object-fit: contain; /* Ensure the image fits within the container */
+ }
+}
+
+// For image rendering (uploaded image as a file)
+.file-image {
+ -webkit-user-select: none;
+ user-select: none;
+
+ display: block;
+ width: 100%;
+ height: auto;
+ object-fit: contain; /* Ensure the image fits within the container */
+}
+
+[data-dev='true'] {
+ .image-wrapper {
+ // outline: 1px solid #ccc; /* Optional: for visual debugging */
+ background-color: #e0f7fa; /* Optional: for visual debugging */
+ }
+}
+
+.extension-file-box {
+ border-radius: 4px;
+ background: rgba(255, 255, 255, 0.5);
+ height: 100px;
+ display: flex;
+ flex-direction: column;
+ justify-content: center;
+ align-items: center;
+ color: rgba(0, 0, 0, 0.25);
+ font-size: 14px;
+}
diff --git a/src/components/DisplaySigit/index.tsx b/src/components/DisplaySigit/index.tsx
index 92dc01d..473a942 100644
--- a/src/components/DisplaySigit/index.tsx
+++ b/src/components/DisplaySigit/index.tsx
@@ -10,7 +10,8 @@ import {
faCalendar,
faCopy,
faEye,
- faFile
+ faFile,
+ faFileCircleExclamation
} from '@fortawesome/free-solid-svg-icons'
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'
import { UserAvatarGroup } from '../UserAvatarGroup'
@@ -20,6 +21,7 @@ import { TooltipChild } from '../TooltipChild'
import { getExtensionIconLabel } from '../getExtensionIconLabel'
import { useSigitProfiles } from '../../hooks/useSigitProfiles'
import { useSigitMeta } from '../../hooks/useSigitMeta'
+import { extractFileExtensions } from '../../utils/file'
type SigitProps = {
meta: Meta
@@ -27,23 +29,18 @@ type SigitProps = {
}
export const DisplaySigit = ({ meta, parsedMeta }: SigitProps) => {
- const {
- title,
- createdAt,
- submittedBy,
- signers,
- signedStatus,
- fileExtensions,
- isValid
- } = parsedMeta
+ const { title, createdAt, submittedBy, signers, signedStatus, isValid } =
+ parsedMeta
- const { signersStatus } = useSigitMeta(meta)
+ const { signersStatus, fileHashes } = useSigitMeta(meta)
const profiles = useSigitProfiles([
...(submittedBy ? [submittedBy] : []),
...signers
])
+ const { extensions, isSame } = extractFileExtensions(Object.keys(fileHashes))
+
return (
{
{signedStatus}
- {fileExtensions.length > 0 ? (
+ {extensions.length > 0 ? (
- {fileExtensions.length > 1 ? (
+ {!isSame ? (
<>
Multiple File Types
>
) : (
- getExtensionIconLabel(fileExtensions[0])
+ getExtensionIconLabel(extensions[0])
)}
- ) : null}
+ ) : (
+ <>
+ —
+ >
+ )}
diff --git a/src/components/DrawPDFFields/index.tsx b/src/components/DrawPDFFields/index.tsx
index a3d43ae..b720dad 100644
--- a/src/components/DrawPDFFields/index.tsx
+++ b/src/components/DrawPDFFields/index.tsx
@@ -2,7 +2,6 @@ import { Close } from '@mui/icons-material'
import {
Box,
CircularProgress,
- Divider,
FormControl,
InputLabel,
MenuItem,
@@ -10,19 +9,15 @@ import {
} from '@mui/material'
import styles from './style.module.scss'
import React, { useEffect, useState } from 'react'
-
import * as PDFJS from 'pdfjs-dist'
import { ProfileMetadata, User, UserRole } from '../../types'
-import {
- PdfFile,
- MouseState,
- PdfPage,
- DrawnField,
- DrawTool
-} from '../../types/drawing'
+import { MouseState, PdfPage, DrawnField, DrawTool } from '../../types/drawing'
import { truncate } from 'lodash'
-import { extractFileExtension, hexToNpub } from '../../utils'
-import { toPdfFiles } from '../../utils/pdf.ts'
+import { settleAllFullfilfedPromises, hexToNpub } from '../../utils'
+import { getSigitFile, SigitFile } from '../../utils/file'
+import { FileDivider } from '../FileDivider'
+import { ExtensionFileBox } from '../ExtensionFileBox'
+
PDFJS.GlobalWorkerOptions.workerSrc = new URL(
'pdfjs-dist/build/pdf.worker.min.mjs',
import.meta.url
@@ -32,15 +27,15 @@ interface Props {
selectedFiles: File[]
users: User[]
metadata: { [key: string]: ProfileMetadata }
- onDrawFieldsChange: (pdfFiles: PdfFile[]) => void
+ onDrawFieldsChange: (sigitFiles: SigitFile[]) => void
selectedTool?: DrawTool
}
export const DrawPDFFields = (props: Props) => {
const { selectedFiles, selectedTool, onDrawFieldsChange, users } = props
- const [pdfFiles, setPdfFiles] = useState([])
- const [parsingPdf, setParsingPdf] = useState(false)
+ const [sigitFiles, setSigitFiles] = useState([])
+ const [parsingPdf, setIsParsing] = useState(false)
const [mouseState, setMouseState] = useState({
clicked: false
@@ -49,42 +44,43 @@ export const DrawPDFFields = (props: Props) => {
useEffect(() => {
if (selectedFiles) {
/**
- * Reads the pdf binary files and converts it's pages to images
- * creates the pdfFiles object and sets to a state
+ * Reads the binary files and converts to internal file type
+ * and sets to a state (adds images if it's a PDF)
*/
- const parsePdfPages = async () => {
- const pdfFiles: PdfFile[] = await toPdfFiles(selectedFiles)
+ const parsePages = async () => {
+ const files = await settleAllFullfilfedPromises(
+ selectedFiles,
+ getSigitFile
+ )
- setPdfFiles(pdfFiles)
+ setSigitFiles(files)
}
- setParsingPdf(true)
+ setIsParsing(true)
- parsePdfPages().finally(() => {
- setParsingPdf(false)
+ parsePages().finally(() => {
+ setIsParsing(false)
})
}
}, [selectedFiles])
useEffect(() => {
- if (pdfFiles) onDrawFieldsChange(pdfFiles)
- }, [onDrawFieldsChange, pdfFiles])
+ if (sigitFiles) onDrawFieldsChange(sigitFiles)
+ }, [onDrawFieldsChange, sigitFiles])
/**
* Drawing events
*/
useEffect(() => {
- // window.addEventListener('mousedown', onMouseDown);
window.addEventListener('mouseup', onMouseUp)
return () => {
- // window.removeEventListener('mousedown', onMouseDown);
window.removeEventListener('mouseup', onMouseUp)
}
}, [])
const refreshPdfFiles = () => {
- setPdfFiles([...pdfFiles])
+ setSigitFiles([...sigitFiles])
}
/**
@@ -303,10 +299,10 @@ export const DrawPDFFields = (props: Props) => {
) => {
event.stopPropagation()
- pdfFiles[pdfFileIndex].pages[pdfPageIndex].drawnFields.splice(
- drawnFileIndex,
- 1
- )
+ const pages = sigitFiles[pdfFileIndex]?.pages
+ if (pages) {
+ pages[pdfPageIndex]?.drawnFields?.splice(drawnFileIndex, 1)
+ }
}
/**
@@ -345,14 +341,17 @@ export const DrawPDFFields = (props: Props) => {
/**
* Renders the pdf pages and drawing elements
*/
- const getPdfPages = (pdfFile: PdfFile, pdfFileIndex: number) => {
+ const getPdfPages = (file: SigitFile, fileIndex: number) => {
+ // Early return if this is not a pdf
+ if (!file.isPdf) return null
+
return (
<>
- {pdfFile.pages.map((page, pdfPageIndex: number) => {
+ {file.pages?.map((page, pageIndex: number) => {
return (
{
@@ -393,8 +392,8 @@ export const DrawPDFFields = (props: Props) => {
onMouseDown={(event) => {
onRemoveHandleMouseDown(
event,
- pdfFileIndex,
- pdfPageIndex,
+ fileIndex,
+ pageIndex,
drawnFieldIndex
)
}}
@@ -469,40 +468,29 @@ export const DrawPDFFields = (props: Props) => {
)
}
- if (!pdfFiles.length) {
+ if (!sigitFiles.length) {
return ''
}
return (
-
- {selectedFiles.map((file, i) => {
- const name = file.name
- const extension = extractFileExtension(name)
- const pdfFile = pdfFiles.find((pdf) => pdf.file.name === name)
+
+ {sigitFiles.map((file, i) => {
return (
-
-
- {pdfFile ? (
- getPdfPages(pdfFile, i)
- ) : (
-
- This is a {extension} file
-
+
+
+ {file.isPdf && getPdfPages(file, i)}
+ {file.isImage && (
+
+ )}
+ {!(file.isPdf || file.isImage) && (
+
)}
- {i < selectedFiles.length - 1 && (
-
- File Separator
-
- )}
+ {i < selectedFiles.length - 1 && }
)
})}
diff --git a/src/components/DrawPDFFields/style.module.scss b/src/components/DrawPDFFields/style.module.scss
index 142f88a..83844ce 100644
--- a/src/components/DrawPDFFields/style.module.scss
+++ b/src/components/DrawPDFFields/style.module.scss
@@ -8,17 +8,6 @@
}
.pdfImageWrapper {
- position: relative;
- -webkit-user-select: none;
- user-select: none;
-
- > img {
- display: block;
- max-width: 100%;
- max-height: 100%;
- object-fit: contain; /* Ensure the image fits within the container */
- }
-
&.drawing {
cursor: crosshair;
}
@@ -90,29 +79,3 @@
padding: 5px 0;
}
}
-
-.fileWrapper {
- display: flex;
- flex-direction: column;
- gap: 15px;
- position: relative;
- scroll-margin-top: $header-height + $body-vertical-padding;
-}
-
-.view {
- display: flex;
- flex-direction: column;
- gap: 25px;
-}
-
-.otherFile {
- border-radius: 4px;
- background: rgba(255, 255, 255, 0.5);
- height: 100px;
- display: flex;
- flex-direction: column;
- justify-content: center;
- align-items: center;
- color: rgba(0, 0, 0, 0.25);
- font-size: 14px;
-}
diff --git a/src/components/ExtensionFileBox.tsx b/src/components/ExtensionFileBox.tsx
new file mode 100644
index 0000000..f36d38c
--- /dev/null
+++ b/src/components/ExtensionFileBox.tsx
@@ -0,0 +1,6 @@
+interface ExtensionFileBoxProps {
+ extension: string
+}
+export const ExtensionFileBox = ({ extension }: ExtensionFileBoxProps) => (
+
This is a {extension} file
+)
diff --git a/src/components/FileDivider.tsx b/src/components/FileDivider.tsx
new file mode 100644
index 0000000..b66b8f4
--- /dev/null
+++ b/src/components/FileDivider.tsx
@@ -0,0 +1,12 @@
+import Divider from '@mui/material/Divider/Divider'
+
+export const FileDivider = () => (
+
+ File Separator
+
+)
diff --git a/src/components/FileList/index.tsx b/src/components/FileList/index.tsx
index 53557a5..38fab88 100644
--- a/src/components/FileList/index.tsx
+++ b/src/components/FileList/index.tsx
@@ -24,19 +24,23 @@ const FileList = ({