// More commentaries from IQ Bible: Gill and Matthew Henry plus hundreds of church-history sources. // Only sources that actually have notes on the chapter being read are offered. import { useState } from 'react'; import { useIq } from '../../hooks/useIq.js'; import { listOf, pickIqEntries } from '../../utils/iqbible.js'; const KEY = 'iq-commentary'; const muted = 'text-xs text-[var(--r-sub,#64748b)]'; export default function IqCommentary({ book, chapter, verse }) { const [chosen, setChosen] = useState(() => { try { return localStorage.getItem(KEY) || 'mhenry'; } catch { return 'mhenry'; } }); const sources = useIq(`books/${book}/commentaries`, { chapter }); const list = listOf(sources.data); const source = list.find((s) => s.name === chosen) ?? list.find((s) => s.name === 'mhenry') ?? list[0]; const notes = useIq(source ? `commentaries/${source.name}/${book}/${chapter}` : null); const entries = pickIqEntries(notes.data?.entries, chapter, verse); const pick = (name) => { setChosen(name); try { localStorage.setItem(KEY, name); } catch { /* storage unavailable */ } }; const groups = list.reduce((acc, s) => { (acc[s.category || 'Other'] ??= []).push(s); return acc; }, {}); if (sources.status === 'loading') return
Loading…
; if (sources.status === 'error') return{sources.error}
; if (!list.length) returnNo IQ Bible commentaries cover this chapter.
; return (Loading…
} {notes.status === 'error' &&{notes.error}
} {(notes.status === 'empty' || (notes.status === 'ready' && entries.length === 0)) && ({source?.author_name} has no notes at or before verse {verse} in this chapter.
)} {entries.map((e, i) => ({e.verse !== verse || e.verse_end ? `Notes on verse${e.verse_end && e.verse_end !== e.verse ? `s ${e.verse}–${e.verse_end}` : ` ${e.verse}`}` : ''} {e.source_title ? ` · ${e.source_title}` : ''}
{source.author_name}{source.year ? `, ${source.year}` : ''} · via IQ Bible{source.license ? ` · ${source.license}` : ''}
}