({ isThinking, content })
| 2 | import "./styles/ThinkingProcess.css"; |
| 3 | |
| 4 | const ThinkingProcess = ({ isThinking, content }) => { |
| 5 | const [elapsed, setElapsed] = useState(0); |
| 6 | const [isOpen, setIsOpen] = useState(isThinking); |
| 7 | const startTimeRef = useRef(null); |
| 8 | const timerRef = useRef(null); |
| 9 | |
| 10 | useEffect(() => { |
| 11 | if (isThinking) { |
| 12 | // Start or resume timer |
| 13 | if (!startTimeRef.current) { |
| 14 | startTimeRef.current = Date.now() - elapsed * 1000; |
| 15 | } |
| 16 | |
| 17 | timerRef.current = setInterval(() => { |
| 18 | setElapsed((Date.now() - startTimeRef.current) / 1000); |
| 19 | }, 100); |
| 20 | |
| 21 | // Auto-open when thinking starts |
| 22 | setIsOpen(true); |
| 23 | } else { |
| 24 | // Stop timer |
| 25 | if (timerRef.current) { |
| 26 | clearInterval(timerRef.current); |
| 27 | timerRef.current = null; |
| 28 | } |
| 29 | // If we were thinking and now stopped, we might want to close it or keep it open? |
| 30 | // Usually it collapses after thinking is done, or stays as is. |
| 31 | // The user image shows it collapsed (implied by "Thought for ..."). |
| 32 | // Let's default to collapsed if it's done, unless the user opened it. |
| 33 | // Actually, let's keep it collapsed by default when done. |
| 34 | if (elapsed > 0) { |
| 35 | setIsOpen(false); |
| 36 | } |
| 37 | } |
| 38 | |
| 39 | return () => { |
| 40 | if (timerRef.current) clearInterval(timerRef.current); |
| 41 | }; |
| 42 | }, [isThinking]); |
| 43 | |
| 44 | // If we have content but no elapsed time (e.g. loaded from history), |
| 45 | // we can't show accurate time. We'll just show "Thought". |
| 46 | // Unless we save the duration in the message. |
| 47 | // For now, if elapsed is 0 and not thinking, we hide the time or show a placeholder. |
| 48 | |
| 49 | const toggleOpen = () => setIsOpen(!isOpen); |
| 50 | |
| 51 | return ( |
| 52 | <div className={`thinking-process ${isThinking ? "thinking" : "done"}`}> |
| 53 | <div className="thinking-header" onClick={toggleOpen}> |
| 54 | <div className="thinking-icon-wrapper"> |
| 55 | <svg |
| 56 | xmlns="http://www.w3.org/2000/svg" |
| 57 | width="24" |
| 58 | height="24" |
| 59 | viewBox="0 0 24 24" |
| 60 | fill="none" |
| 61 | stroke="currentColor" |
nothing calls this directly
no outgoing calls
no test coverage detected