// Home card: your five minutes for today. A short prompt on a passage from your studies, a five-minute clock, and a // box to write in. What you write is added to that passage's notes. Pasting is turned off here on purpose. import { useEffect, useMemo, useRef, useState } from 'react'; import { useApp } from '../context/AppContext.js'; import { loadProjectById } from '../utils/projectStorage.js'; import { FIELD_NAMES, MINUTES, dailyPatch, pickDaily } from '../utils/dailyFive.js'; import { formatClock } from '../utils/present.js'; const box = 'mb-4 rounded-xl border border-[var(--r-line)] bg-[var(--r-bar)] px-4 py-3 text-sm'; export default function DailyFive() { const { projectIndex, saveChunkPatch } = useApp(); const [step, setStep] = useState('card'); // card -> write -> done const [text, setText] = useState(''); const [left, setLeft] = useState(MINUTES * 60); const [pasteTried, setPasteTried] = useState(false); const pick = useMemo(() => pickDaily(projectIndex.map((e) => loadProjectById(e.id)).filter(Boolean)), [projectIndex]); const started = useRef(null); useEffect(() => { if (step !== 'write') return undefined; started.current = Date.now(); const t = window.setInterval(() => setLeft(Math.max(0, MINUTES * 60 - Math.round((Date.now() - started.current) / 1000))), 1000); return () => window.clearInterval(t); }, [step]); if (step === 'done') return
{pick.reference} · {FIELD_NAMES[prompt.field]}
{left === 0 ? 'Time’s up, finish your thought' : formatClock(left)}{v.number}{v.text}
)}{prompt.text}