MCPcopy Create free account
hub / github.com/pacexy/flow / FindMatches

Function FindMatches

apps/reader/src/components/Annotation.tsx:17–56  ·  view source on GitHub ↗
({ tab })

Source from the content-addressed store, hash-verified

15 tab: BookTab
16}
17const FindMatches: React.FC<FindMatchProps> = ({ tab }) => {
18 const setAction = useSetAction()
19 const { rendition, results, currentHref } = useSnapshot(tab)
20
21 useEffect(() => {
22 const result = results?.find((r) => compareHref(currentHref, r.id))
23
24 const matches = result?.subitems
25 matches?.forEach((m) => {
26 try {
27 const h = rendition?.annotations.highlight(
28 m.cfi!,
29 undefined,
30 undefined,
31 undefined,
32 {
33 // tailwind yellow-500
34 fill: 'rgba(234, 179, 8, 0.3)',
35 'fill-opacity': 'unset',
36 },
37 )
38
39 const g = h?.mark.element as SVGGElement
40 g?.addEventListener('click', () => {
41 setClickedAnnotation(true)
42 })
43 } catch (error) {
44 // ignore matched text in `<title>`
45 }
46 })
47
48 return () => {
49 matches?.forEach((m) => {
50 rendition?.annotations.remove(m.cfi!, 'highlight')
51 })
52 }
53 }, [currentHref, rendition?.annotations, results, setAction])
54
55 return null
56}
57
58interface DefinitionProps {
59 tab: BookTab

Callers

nothing calls this directly

Calls 7

useSetActionFunction · 0.90
compareHrefFunction · 0.90
setClickedAnnotationFunction · 0.85
findMethod · 0.45
forEachMethod · 0.45
highlightMethod · 0.45
removeMethod · 0.45

Tested by

no test coverage detected