// Under a note: each Scripture reference written in it (Rom 8:28, Psalm 23…) as a chip. Click one to read the verse // (BSB) right there, or open it in the Bible reader. The text itself is never changed. import { useEffect, useMemo, useState } from 'react'; import { useApp } from '../context/AppContext.js'; import { fetchChapter } from '../utils/bibleText.js'; import { labelFor, uniqueReferences } from '../utils/scriptureRefs.js'; const MAX_VERSES = 12; const CHAPTER_PREVIEW = 6; function Preview({ r }) { const { jumpToReaderVerse, openBibleReader } = useApp(); const [state, setState] = useState({ loading: true }); useEffect(() => { let live = true; setState({ loading: true }); fetchChapter('BSB', r.book, r.chapter) .then(({ verses }) => { const from = r.verse ?? 1; const to = r.verse ? (r.endVerse ?? r.verse) : from + CHAPTER_PREVIEW - 1; const picked = verses.filter((v) => v.number >= from && v.number <= to).slice(0, MAX_VERSES); if (live) setState({ verses: picked, more: !r.verse && verses.length > picked.length }); }) .catch((err) => { if (live) setState({ error: err.message || 'Could not load the verse.' }); }); return () => { live = false; }; }, [r.book, r.chapter, r.verse, r.endVerse]); return (
Loading…
} {state.error &&{state.error} You can still open it in the Bible.
} {state.verses && (state.verses.length === 0 ?That verse isn’t in the BSB.
:{v.number}{v.text}
)}{state.more &&…
}Verses mentioned: {refs.map((r) => { const label = labelFor(r); return ( ); })}
{openRef &&