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

Function AnnotationPane

apps/reader/src/components/viewlets/AnnotationView.tsx:45–108  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

43}
44
45const AnnotationPane: React.FC = () => {
46 const { focusedBookTab } = useReaderSnapshot()
47 const t = useTranslation('annotation')
48
49 const annotations = useMemo(
50 () => (focusedBookTab?.book.annotations as Annotation[]) ?? [],
51 [focusedBookTab?.book.annotations],
52 )
53
54 const groupedAnnotation = useMemo(() => {
55 return group(annotations ?? [], (a) => a.spine.index)
56 }, [annotations])
57
58 const exportAnnotations = () => {
59 // process annotations to be under each section
60 // group annotations by title
61 const grouped = group(annotations, (a) => a.spine.title)
62 const exported: Record<string, any[]> = {}
63 for (const chapter in grouped) {
64 const annotations =
65 grouped[chapter]?.map((a) => {
66 const annotation: Record<string, any> = {}
67 if (a.notes !== undefined) annotation.notes = a.notes
68 if (a.text !== undefined) annotation.text = a.text
69 return annotation
70 }) ?? []
71 exported[chapter] = annotations
72 }
73
74 // Copy to clipboard as markdown
75 const exportedAnnotationsMd = Object.entries(exported)
76 .map(([chapter, annotations]) => {
77 return `## ${chapter}\n${annotations
78 .map((a) => `- ${a.text} ${a.notes ? `(${a.notes})` : ''}`)
79 .join('\n')}`
80 })
81 .join('\n\n')
82 copy(exportedAnnotationsMd)
83 }
84
85 return (
86 <Pane
87 headline={t('annotations')}
88 actions={
89 annotations.length > 0
90 ? [
91 {
92 id: 'copy-all',
93 title: t('copy_as_markdown'),
94 Icon: VscCopy,
95 handle() {
96 exportAnnotations()
97 },
98 },
99 ]
100 : undefined
101 }
102 >

Callers

nothing calls this directly

Calls 5

useReaderSnapshotFunction · 0.90
useTranslationFunction · 0.90
groupFunction · 0.90
keysFunction · 0.90
mapMethod · 0.80

Tested by

no test coverage detected