// Observe / Interpret / Apply as an accordion (one open at a time), plus a "More" // area for background notes and tags so the page stays quiet. import { useEffect, useRef, useState } from 'react'; import SessionNotes from './SessionNotes.jsx'; import FirstDraft from './FirstDraft.jsx'; import ScriptureRefs from '../ScriptureRefs.jsx'; import { usePasteCheck } from './PastePrompt.jsx'; import { listNoteVersions, recordNoteVersion } from '../../utils/noteHistory.js'; import DictateButton, { appendSpoken } from '../DictateButton.jsx'; import { ownShare, ownWords, pastedWords, clearPastes } from '../../utils/ownWork.js'; import { templateFromChunk, templatePrompt } from '../../utils/studyTemplates.js'; const SECTIONS = [ { field: 'observation', label: 'Observe', hint: 'What does the text say?', placeholder: "What does the text actually say?\n• Who is speaking, and to whom?\n• What key words or phrases repeat?\n• What's the tone, structure, or literary style?" }, { field: 'interpretation', label: 'Interpret', hint: 'What does it mean?', placeholder: "What did this mean to its original audience?\n• What's the historical/cultural context?\n• How does it fit the surrounding argument?\n• What does it reveal about God's character?" }, { field: 'application', label: 'Apply', hint: 'What do I do with it?', placeholder: 'How should this shape your life today?\n• What attitude or action does this call for?\n• Is there a promise to trust or a warning to heed?\n• Who could you share this with?' }, ]; const areaCls = 'w-full resize-y rounded-xl border border-[var(--r-line)] bg-[var(--r-bg)] px-3.5 py-3 font-serif text-[15px] leading-7 text-[var(--r-text)] placeholder:font-sans placeholder:text-[13px] placeholder:leading-5 placeholder:text-[var(--r-sub)] focus:outline-none focus:ring-2 focus:ring-[var(--r-line)]'; const words = (s) => (s ?? '').trim().split(/\s+/).filter(Boolean).length; export default function NotesPane({ chunk, updateChunk, allTags, templateId, saveTemplate, notify, onPray, focusRequest }) { const [open, setOpen] = useState(() => { try { return localStorage.getItem('studyNotesOpen') || 'observation'; } catch { return 'observation'; } }); const [more, setMore] = useState(false); // A keyboard jump (1 / 2 / 3 on the Study page): open that note and put the cursor in it. const areas = useRef({}); const wanted = useRef(null); useEffect(() => { if (!focusRequest) return; wanted.current = focusRequest.field; setOpen(focusRequest.field); }, [focusRequest]); useEffect(() => { if (wanted.current && wanted.current === open) { const el = areas.current[open]; if (el) { el.focus(); const end = el.value.length; el.setSelectionRange(end, end); wanted.current = null; } } }); const [tplName, setTplName] = useState(''); const [tplOpen, setTplOpen] = useState(false); const [tagInput, setTagInput] = useState(''); useEffect(() => { setTagInput(''); }, [chunk.id]); useEffect(() => { try { localStorage.setItem('studyNotesOpen', open || ''); } catch { /* storage unavailable */ } }, [open]); const tags = chunk.tags ?? []; const addTag = (tag) => { const t = tag.trim(); if (!t || tags.some((x) => x.toLowerCase() === t.toLowerCase())) { setTagInput(''); return; } updateChunk(chunk.id, { tags: [...tags, t] }); setTagInput(''); }; const suggestions = allTags.filter((t) => !tags.some((x) => x.toLowerCase() === t.toLowerCase())); const share = ownShare(chunk); const pasteCheck = usePasteCheck(chunk, updateChunk); // Earlier versions of one note: kept when you start and stop editing it; "History" lists them with Restore. const [historyField, setHistoryField] = useState(null); const [versions, setVersions] = useState([]); useEffect(() => { setHistoryField(null); }, [chunk.id]); const keepVersion = (field) => { const list = recordNoteVersion(chunk.id, field, chunk[field]); if (historyField === field) setVersions(list); }; const openHistory = (field) => { if (historyField === field) { setHistoryField(null); return; } recordNoteVersion(chunk.id, field, chunk[field]); setVersions(listNoteVersions(chunk.id, field)); setHistoryField(field); }; const restore = (field, text) => { recordNoteVersion(chunk.id, field, chunk[field]); // so restoring can itself be undone updateChunk(chunk.id, { [field]: text }); setVersions(listNoteVersions(chunk.id, field)); }; return (
{share !== null && (

{share === 100 ? 'All of these notes are your own words.' : `${share}% of these notes are your own words.`}

)} {SECTIONS.map(({ field, label, hint, placeholder }) => { const isOpen = open === field; const n = words(chunk[field]); const pasted = pastedWords(chunk, field); return (
{isOpen && (