Skip to content

Commit af8b0c5

Browse files
authored
Merge pull request #161 from oleksandr-danylchenko/simplify-popup-open-check
Simplified popup opening check with `isRevived`
2 parents c5ffd36 + ca1b8ec commit af8b0c5

File tree

1 file changed

+6
-11
lines changed

1 file changed

+6
-11
lines changed

packages/text-annotator-react/src/TextAnnotatorPopup/TextAnnotatorPopup.tsx

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { PointerEvent, ReactNode, useCallback, useEffect, useMemo, useState } from 'react';
22
import { useAnnotator, useSelection } from '@annotorious/react';
3-
import type { TextAnnotation, TextAnnotator } from '@recogito/text-annotator';
3+
import { isRevived, TextAnnotation, TextAnnotator } from '@recogito/text-annotator';
44
import { isMobile } from './isMobile';
55
import {
66
autoUpdate,
@@ -71,15 +71,10 @@ export const TextAnnotatorPopup = (props: TextAnnotationPopupProps) => {
7171
const { getFloatingProps } = useInteractions([dismiss, role]);
7272

7373
useEffect(() => {
74-
setOpen(
75-
// Selected annotation exists and has a selector?
76-
annotation?.target.selector &&
77-
// Selector not empty? (Annotations from plugins, general defensive programming)
78-
annotation.target.selector.length > 0 &&
79-
// Range not collapsed? (E.g. lazy loading PDFs. Note that this will have to
80-
// change if we switch from ranges to pre-computed bounds!)
81-
!annotation.target.selector[0].range.collapsed
82-
);
74+
const annotationSelector = annotation?.target.selector;
75+
if (!annotationSelector) return;
76+
77+
setOpen(isRevived(annotationSelector));
8378
}, [annotation]);
8479

8580
useEffect(() => {
@@ -154,4 +149,4 @@ export const TextAnnotatorPopup = (props: TextAnnotationPopupProps) => {
154149
</FloatingPortal>
155150
) : null;
156151

157-
}
152+
}

0 commit comments

Comments
 (0)