import { useState, useEffect, useCallback } from 'react' import { motion } from 'framer-motion' import { useAuth } from '@clerk/clerk-react' import NotebookGuide from './NotebookGuide.jsx' import SuggestedQuestions from './SuggestedQuestions.jsx' import DocumentSummaryCard from './DocumentSummaryCard.jsx' import { API_BASE } from '../config.js' export default function NotebookTab({ onAsk }) { const { getToken } = useAuth() const [notebookData, setNotebookData] = useState({ guide: null, summaries: {} }) const [documents, setDocuments] = useState([]) const [loading, setLoading] = useState(true) const fetchData = useCallback(async () => { setLoading(true) try { const token = await getToken() const headers = token ? { Authorization: `Bearer ${token}` } : {} const [nbRes, docsRes] = await Promise.all([ fetch(`${API_BASE}/notebook`, { headers }), fetch(`${API_BASE}/documents`, { headers }), ]) const nb = await nbRes.json() const docs = await docsRes.json() setNotebookData(nb) setDocuments(docs.documents || []) } catch { // backend not reachable } finally { setLoading(false) } }, [getToken]) useEffect(() => { fetchData() }, [fetchData]) const handleGuideReady = (guide) => setNotebookData(prev => ({ ...prev, guide })) const handleSummaryReady = (source, entry) => setNotebookData(prev => ({ ...prev, summaries: { ...prev.summaries, [source]: entry } })) if (loading) { return (
Loading notebook…
) } return ( {notebookData.guide?.suggested_questions?.length > 0 && ( )} {documents.length > 0 && (

Document Library

{documents.length}
{documents.map(doc => ( ))}
)} {documents.length === 0 && (

No documents indexed yet.

Switch to the Chat tab and upload PDFs first.

)}
) }