// Commentary for the chunk's verse range, from seven open sources. Some sources // comment on whole passages, so when nothing starts inside the range we show the // closest earlier entry. "Add to notes" quotes a paragraph, with its citation, into // the chunk's background notes. import { COMMENTARIES } from '../../hooks/useVerseStudy.js'; import { formatChunkReference } from '../../utils/bibleUtils.jsx'; export default function CommentaryChunkTab({ resources, chunk, project, chapterIndex, updateChunk, notify }) { const { commentarySource, setCommentarySource, commentaryData, commentaryLoading, commentaryError } = resources; const source = COMMENTARIES.find((c) => c.id === commentarySource) ?? COMMENTARIES[0]; const items = (commentaryData?.chapter?.content ?? []).filter((i) => i.type === 'verse').sort((a, b) => a.number - b.number); let entries = items.filter((i) => i.number >= chunk.startVerse && i.number <= chunk.endVerse); let earlier = false; if (entries.length === 0) { const before = [...items].reverse().find((i) => i.number <= chunk.startVerse); if (before) { entries = [before]; earlier = true; } } const ref = formatChunkReference(project, chapterIndex, chunk, '–'); const quote = (text, verse) => { const citation = `${text} (${source.name}, ${ref.split(':')[0]}:${verse})`; const existing = chunk.generalNotes ?? ''; updateChunk(chunk.id, { generalNotes: existing ? `${existing}\n\n${citation}` : citation }); notify('Added to background notes.', 1600); }; return (
{commentaryLoading &&

Loading commentary…

} {commentaryError &&

{commentaryError}

} {!commentaryLoading && !commentaryError && commentaryData && entries.length === 0 && (

No commentary found for {ref}.

)} {!commentaryLoading && !commentaryError && entries.map((v) => (

{earlier ? `Notes on the passage starting at verse ${v.number}` : `Verse ${v.number}`}

{(v.content ?? []).map((p, i) => { const text = typeof p === 'string' ? p : ''; if (!text) return null; return (

{text}

); })}
))}

{source.credit}

); }