From 82b7b9f7ce1e8e6edfc547e18b56090236b02bdf Mon Sep 17 00:00:00 2001 From: enes Date: Tue, 3 Sep 2024 14:13:35 +0200 Subject: [PATCH] fix(mark): scroll into marks, add scroll margin and forwardRef Closes #172 --- src/App.scss | 2 + src/components/PDFView/PdfMarkItem.tsx | 68 ++++++++++++++------------ src/components/PDFView/PdfPageItem.tsx | 19 ++++--- 3 files changed, 49 insertions(+), 40 deletions(-) diff --git a/src/App.scss b/src/App.scss index d3bff8a..4d95be6 100644 --- a/src/App.scss +++ b/src/App.scss @@ -141,6 +141,8 @@ li { color: black; letter-spacing: normal; border: 1px solid transparent; + + scroll-margin-top: $header-height + $body-vertical-padding; } [data-dev='true'] { diff --git a/src/components/PDFView/PdfMarkItem.tsx b/src/components/PDFView/PdfMarkItem.tsx index d5a7c78..db57800 100644 --- a/src/components/PDFView/PdfMarkItem.tsx +++ b/src/components/PDFView/PdfMarkItem.tsx @@ -2,6 +2,8 @@ import { CurrentUserMark } from '../../types/mark.ts' import styles from '../DrawPDFFields/style.module.scss' import { FONT_SIZE, FONT_TYPE, inPx } from '../../utils/pdf.ts' import { useScale } from '../../hooks/useScale.tsx' +import { forwardRef } from 'react' +import { npubToHex } from '../../utils/nostr.ts' interface PdfMarkItemProps { userMark: CurrentUserMark @@ -14,35 +16,41 @@ interface PdfMarkItemProps { /** * Responsible for display an individual Pdf Mark. */ -const PdfMarkItem = ({ - selectedMark, - handleMarkClick, - selectedMarkValue, - userMark, - pageWidth -}: PdfMarkItemProps) => { - const { location } = userMark.mark - const handleClick = () => handleMarkClick(userMark.mark.id) - const isEdited = () => selectedMark?.mark.id === userMark.mark.id - const getMarkValue = () => - isEdited() ? selectedMarkValue : userMark.currentValue - const { from } = useScale() - return ( -
- {getMarkValue()} -
- ) -} +const PdfMarkItem = forwardRef( + ( + { selectedMark, handleMarkClick, selectedMarkValue, userMark, pageWidth }, + ref + ) => { + const { location } = userMark.mark + const handleClick = () => handleMarkClick(userMark.mark.id) + const isEdited = () => selectedMark?.mark.id === userMark.mark.id + const getMarkValue = () => + isEdited() ? selectedMarkValue : userMark.currentValue + const { from } = useScale() + return ( +
+ {getMarkValue()} +
+ ) + } +) export default PdfMarkItem diff --git a/src/components/PDFView/PdfPageItem.tsx b/src/components/PDFView/PdfPageItem.tsx index ec9034a..bbf6e4e 100644 --- a/src/components/PDFView/PdfPageItem.tsx +++ b/src/components/PDFView/PdfPageItem.tsx @@ -48,16 +48,15 @@ const PdfPageItem = ({ alt={`page ${pageIndex + 1} of ${fileName}`} /> {currentUserMarks.map((m, i) => ( -
(markRefs.current[m.id] = el)}> - -
+ (markRefs.current[m.id] = el)} + handleMarkClick={handleMarkClick} + selectedMarkValue={selectedMarkValue} + userMark={m} + selectedMark={selectedMark} + pageWidth={page.width} + /> ))} {otherUserMarks.map((m, i) => { return ( -- 2.34.1