| 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 |