import React, { useState, useEffect, useRef } from 'react'; import ReactMarkdown from 'react-markdown'; import remarkMath from 'remark-math'; import rehypeKatex from 'rehype-katex'; import { Send, Bot, User, Sparkles } from 'lucide-react'; import { querySystem } from '../api'; import { motion } from 'framer-motion'; const Notebook = ({ messages, setMessages, onCitationClick, notebookId }) => { // Accept notebookId // const [messages, setMessages] = useState([ ... ]); // Removed internal state const [input, setInput] = useState(''); const [loading, setLoading] = useState(false); const scrollRef = useRef(null); useEffect(() => { if (scrollRef.current) { scrollRef.current.scrollTop = scrollRef.current.scrollHeight; } }, [messages]); const handleSend = async () => { if (!input.trim()) return; const userMsg = { role: 'user', content: input }; setMessages(prev => [...prev, userMsg]); setInput(''); setLoading(true); try { // Pass notebookId to querySystem const response = await querySystem(userMsg.content, notebookId); const botMsg = { role: 'assistant', content: response.answer, citations: response.citations }; setMessages(prev => [...prev, botMsg]); } catch (err) { setMessages(prev => [...prev, { role: 'assistant', content: 'Connection error. Please ensure background services are running.' }]); } setLoading(false); }; return (
{/* Scrollable Notebook Area */}
{messages.map((msg, idx) => ( {msg.role === 'user' ? (

{msg.content}

) : (
{msg.content}
{/* Citation Chips */} {msg.citations && msg.citations.length > 0 && (
{msg.citations.map((cit, i) => ( ))}
)}
)}
))} {loading && ( Analyzing documents... )}
{/* Input Area - Fixed at bottom center like a floating bar */}
setInput(e.target.value)} onKeyDown={(e) => e.key === 'Enter' && handleSend()} />

AI can make mistakes. Check important info.

); }; export default Notebook;