// Finish → Import notes: bring notes from a Word or Markdown file into this study, matched to its chunks by passage. import { useState } from 'react'; import { useApp } from '../context/AppContext.js'; import { useToast } from './Toasts.jsx'; import { applyImportedNotes, parseNotesText } from '../utils/importNotes.js'; export default function ImportNotes() { const { project, updateProject } = useApp(); const { toast } = useToast(); const [file, setFile] = useState(''); const [sections, setSections] = useState(null); // null until a file is read const [own, setOwn] = useState(true); const [error, setError] = useState(''); const choose = async (e) => { const f = e.target.files?.[0]; e.target.value = ''; setError(''); setSections(null); if (!f) return; try { let text; if (/\.docx$/i.test(f.name)) { const { default: mammoth } = await import('mammoth'); text = (await mammoth.extractRawText({ arrayBuffer: await f.arrayBuffer() })).value; } else text = await f.text(); const found = parseNotesText(text); setFile(f.name); setSections(found); if (found.length === 0) setError('No passage headings with Observe / Interpret / Apply notes were found in that file. Start each section with a heading like “John 3:16–18”.'); } catch { setError('That file couldn’t be read.'); } }; const preview = sections ? applyImportedNotes(project, sections, { own }) : null; const add = () => { updateProject((current) => applyImportedNotes(current, sections, { own }).project); toast(`Added notes to ${preview.matched.length} chunk${preview.matched.length === 1 ? '' : 's'}`); setSections(null); }; return (

Import notes

Bring in notes from a Word (.docx), Markdown or text file. Start each section with a passage heading (“John 3:16–18”), then label the notes “Observe:”, “Interpret:”, “Apply:”, “Background:” or “Questions:”. Notes you’ve already written are kept; imported text is added below them.

{error &&

{error}

} {preview && sections.length > 0 && (

{file}: {sections.length} section{sections.length === 1 ? '' : 's'} found.

)}
); }