refactor(sign): cleaner divider code in PDVview

This commit is contained in:
enes 2024-12-20 16:07:12 +01:00
parent d965e56f76
commit b7eadf0081

View File

@ -45,18 +45,17 @@ const PdfView = ({
const filterMarksByFile = (marks: Mark[], hash: string): Mark[] => { const filterMarksByFile = (marks: Mark[], hash: string): Mark[] => {
return marks.filter((mark) => mark.pdfFileHash === hash) return marks.filter((mark) => mark.pdfFileHash === hash)
} }
const isNotLastPdfFile = (index: number, files: CurrentUserFile[]): boolean =>
index !== files.length - 1
return ( return (
<div className="files-wrapper"> <div className="files-wrapper">
{files.length > 0 ? ( {files.length > 0 ? (
files.map((currentUserFile, index, arr) => { files
const { hash, file, id } = currentUserFile .map<React.ReactNode>((currentUserFile) => {
const { hash, file, id } = currentUserFile
if (!hash) return if (!hash) return
return ( return (
<React.Fragment key={index}>
<div <div
key={`file-${file.name}`}
id={file.name} id={file.name}
className="file-wrapper" className="file-wrapper"
ref={(el) => (pdfRefs.current[id] = el)} ref={(el) => (pdfRefs.current[id] = el)}
@ -70,10 +69,13 @@ const PdfView = ({
otherUserMarks={filterMarksByFile(otherUserMarks, hash)} otherUserMarks={filterMarksByFile(otherUserMarks, hash)}
/> />
</div> </div>
{isNotLastPdfFile(index, arr) && <FileDivider />} )
</React.Fragment> })
) .reduce((prev, curr, i) => [
}) prev,
<FileDivider key={`separator-${i}`} />,
curr
])
) : ( ) : (
<LoadingSpinner variant="small" /> <LoadingSpinner variant="small" />
)} )}