import React, { useState, useEffect } from 'react'; import { v4 as uuidv4 } from 'uuid'; import FileUpload from './components/FileUpload'; import FileManager from './components/FileManager'; import Chat from './components/Chat'; import DocumentSummary from './components/DocumentSummary'; import { ThemeProvider } from './components/ui/theme-provider'; import { ThemeToggle } from './components/ui/theme-toggle'; import { SettingsDialog } from './components/ui/settings-dialog'; import { getVersionString, fetchApiVersion } from './utils/version'; import { identifyUser, setupUserIdInterceptor } from './utils/user'; import PromptEditor from './components/ui/PromptEditor'; // Setup the axios interceptor to include user ID in all requests setupUserIdInterceptor(); function App() { const [sessionId, setSessionId] = useState(''); const [showUploadForm, setShowUploadForm] = useState(true); const [uploadedFiles, setUploadedFiles] = useState([]); const [activeFileIndex, setActiveFileIndex] = useState(0); const [selectedQuestion, setSelectedQuestion] = useState(''); const [apiVersion, setApiVersion] = useState(null); const [userId, setUserId] = useState(null); // App settings with localStorage persistence const [settings, setSettings] = useState(() => { // Initialize from localStorage, default to true if not set const saved = localStorage.getItem('appSettings'); return saved ? JSON.parse(saved) : { showDashboard: true }; }); // Get active file data const activeFile = uploadedFiles[activeFileIndex] || null; useEffect(() => { // Generate a unique session ID if one doesn't exist if (!sessionId) { setSessionId(uuidv4()); } }, [sessionId]); // Identify user on app load useEffect(() => { const identify = async () => { const id = await identifyUser(); setUserId(id); }; identify(); }, []); // Fetch API version information useEffect(() => { const getApiVersion = async () => { const versionInfo = await fetchApiVersion(); setApiVersion(versionInfo); }; getApiVersion(); }, []); // Save settings to localStorage when they change useEffect(() => { localStorage.setItem('appSettings', JSON.stringify(settings)); }, [settings]); const handleSettingsChange = (newSettings) => { setSettings(newSettings); }; const handleFileUploadSuccess = (fileName, description, questions) => { // Add the new file to the uploaded files array setUploadedFiles(prev => [ ...prev, { name: fileName, description, suggestedQuestions: questions, sessionId // Save the sessionId associated with this file } ]); // Set the newly uploaded file as active setActiveFileIndex(uploadedFiles.length); // Hide the upload form setShowUploadForm(false); }; const handleSelectFile = (index) => { setActiveFileIndex(index); }; const handleUploadNew = () => { // Generate a new session ID for the new file setSessionId(uuidv4()); setShowUploadForm(true); }; const handleQuestionSelect = (question) => { setSelectedQuestion(question); }; const handlePromptsChange = () => { // Optional: Handle updates to prompts if needed console.log('Prompts were updated'); }; return (
🧠

Quick Understand

{userId && } {!showUploadForm && uploadedFiles.length > 0 && ( )}
{showUploadForm && ( )} {!showUploadForm && uploadedFiles.length > 0 && (

{activeFile.name.toLowerCase().endsWith('.pdf') ? '📕' : '📄'} File: {activeFile.name}

{activeFile.description}

{settings.showDashboard && }
{activeFile.suggestedQuestions && activeFile.suggestedQuestions.length > 0 && (

💡 Suggested questions:

{activeFile.suggestedQuestions.map((question, idx) => ( ))}
)}
setSelectedQuestion('')} />
)}
); } export default App;