// A Bible dictionary lookup (Easton, Hastings, Hitchcock, Schaff, Smith: all public domain, from IQ Bible). // Type a word, pick a dictionary; the entry named for the word comes first and the entries that only mention it // are folded below. Scripture references in an entry open in the Reader. import { useState } from 'react'; import { useApp } from '../../context/AppContext.js'; import { useIq } from '../../hooks/useIq.js'; import { pickEntries, preview, refTarget } from '../../utils/dictionary.js'; const field = 'rounded-lg border border-[var(--r-line)] bg-[var(--r-bg)] px-2.5 py-1.5 text-sm text-[var(--r-text)] focus:outline-none focus:ring-2 focus:ring-[var(--r-line)]'; function Entry({ entry, credit, open: startOpen }) { const { jumpToReaderVerse, openBibleReader } = useApp(); const [open, setOpen] = useState(startOpen); const p = preview(entry.definition); const refs = [...new Set(entry.scripture_refs ?? [])].map(refTarget).filter(Boolean).slice(0, 14); return (

{entry.term}

{open || !p.cut ? entry.definition : p.text}

{p.cut && } {refs.length > 0 && (

{refs.map((r) => ( ))}

)}

{credit}

); } export default function IqDictionary() { const [dictId, setDictId] = useState(() => { try { return localStorage.getItem('dictionary') || 'easton'; } catch { return 'easton'; } }); const [typed, setTyped] = useState(''); const [asked, setAsked] = useState(''); const list = useIq('dictionaries'); const dictionaries = list.data?.data ?? []; const current = dictionaries.find((d) => d.id === dictId) ?? dictionaries[0]; const result = useIq(asked && current ? `dictionaries/${current.id}` : null, { q: asked }); const { exact, others } = pickEntries(result.data?.data, asked); const credit = current ? `${current.name}, ${current.author}, ${current.year}. ${current.license}.` : ''; const choose = (id) => { setDictId(id); try { localStorage.setItem('dictionary', id); } catch { /* storage unavailable */ } }; const ask = () => setAsked(typed.trim().slice(0, 100)); return (
Bible dictionary
setTyped(e.target.value)} placeholder="A name, place or word, e.g. cubit" onKeyDown={(e) => { if (e.key === 'Enter') { e.preventDefault(); ask(); } }} className={`${field} min-w-0 flex-1`} />
{result.status === 'loading' &&

Looking up…

} {result.status === 'error' &&

{result.error || 'The dictionary could not be reached.'}

} {asked && (result.status === 'ready' || result.status === 'empty') && !exact && others.length === 0 && (

Nothing for “{asked}” in this dictionary. Try another dictionary or the singular of the word.

)} {exact && } {others.length > 0 && (
{exact ? 'Other entries that mention' : 'Entries that mention'} “{asked}” ({others.length})
{others.slice(0, 8).map((e) => )}
)}
); }