import React, { useState, useEffect } from 'react'; import { Button } from './ui/button'; import axios from 'axios'; // Fallback data in case of API failure const fallbackData = { keyTopics: ['Document analysis unavailable'], entities: ['Try refreshing the page'], wordCloudData: [ { text: 'Document', value: 50 }, { text: 'Summary', value: 40 }, { text: 'Unavailable', value: 30 }, ], documentStructure: [ { title: 'Document structure unavailable', subsections: ['Please refresh the page or try a different document'] } ] }; const DocumentSummary = ({ fileName, sessionId, userId }) => { const [activeTab, setActiveTab] = useState('overview'); const [summaryData, setSummaryData] = useState(null); const [loading, setLoading] = useState(true); const [error, setError] = useState(null); useEffect(() => { const fetchSummary = async () => { if (!sessionId) return; try { setLoading(true); setError(''); // Add user ID to the request if available const response = await axios.post('/document-summary', { session_id: sessionId, user_id: userId }); setSummaryData(response.data); setLoading(false); } catch (error) { console.error('Error fetching document summary:', error); setError('Failed to load document summary'); setLoading(false); } }; fetchSummary(); }, [sessionId, userId]); if (loading) { return (
Word size represents frequency in the document. Click on any word to search for it.
Document structure extracted from headings and content organization.