From 0d52cd71134c9b3eee41e1ea853dba65afc7c79b Mon Sep 17 00:00:00 2001 From: Eugene Date: Mon, 12 Aug 2024 10:16:30 +0300 Subject: [PATCH] fix: selected mark selection --- src/components/MarkFormField/style.module.scss | 1 + src/components/PDFView/PdfMarking.tsx | 11 ++++++++--- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/src/components/MarkFormField/style.module.scss b/src/components/MarkFormField/style.module.scss index bff4644..e4e76ea 100644 --- a/src/components/MarkFormField/style.module.scss +++ b/src/components/MarkFormField/style.module.scss @@ -138,6 +138,7 @@ button:active { .submitButton { width: 100%; max-width: 300px; + margin-top: 10px; } .footerContainer { diff --git a/src/components/PDFView/PdfMarking.tsx b/src/components/PDFView/PdfMarking.tsx index e162062..b0e0748 100644 --- a/src/components/PDFView/PdfMarking.tsx +++ b/src/components/PDFView/PdfMarking.tsx @@ -39,8 +39,13 @@ const PdfMarking = (props: PdfMarkingProps) => { const [selectedMarkValue, setSelectedMarkValue] = useState('') useEffect(() => { - setSelectedMark(findNextIncompleteCurrentUserMark(currentUserMarks) || null) - }, []) + if (selectedMark === null && currentUserMarks.length > 0) { + setSelectedMark( + findNextIncompleteCurrentUserMark(currentUserMarks) || + currentUserMarks[0] + ) + } + }, [currentUserMarks, selectedMark]) const handleMarkClick = (id: number) => { const nextMark = currentUserMarks.find((mark) => mark.mark.id === id) @@ -60,8 +65,8 @@ const PdfMarking = (props: PdfMarkingProps) => { updatedSelectedMark ) setCurrentUserMarks(updatedCurrentUserMarks) - setSelectedMark(mark) setSelectedMarkValue(mark.currentValue ?? EMPTY) + setSelectedMark(mark) } const handleSubmit = (event: React.FormEvent) => {