import { Link, useLocation } from 'react-router'; import { LayoutDashboard, MessageSquare, Database, FileText, Globe, Youtube, History, Settings as SettingsIcon, Plus, Sun, Moon, Gavel, Image as ImageIcon, BarChart3 } from 'lucide-react'; import { useTheme } from './ThemeProvider'; import { SourceCard } from './SourceCard'; import { useEffect, useState } from 'react'; import { KnowledgeSource } from '../types'; import { fetchSources } from '../api'; const navigation = [ { name: 'Dashboard', path: '/app', icon: LayoutDashboard }, { name: 'Ask AI', path: '/app/ask', icon: MessageSquare }, { name: 'Legal AI', path: '/app/legal', icon: Gavel }, { name: 'System Audit', path: '/app/evaluate', icon: BarChart3 }, { name: 'Vision / Image', path: '/app/upload-image', icon: ImageIcon }, { name: 'Knowledge Sources', path: '/app/sources', icon: Database }, { name: 'Upload PDF', path: '/app/upload-pdf', icon: FileText }, { name: 'Add Website', path: '/app/add-website', icon: Globe }, { name: 'Add YouTube', path: '/app/add-youtube', icon: Youtube }, { name: 'Query History', path: '/app/history', icon: History }, { name: 'Settings', path: '/app/settings', icon: SettingsIcon }, ]; export function Sidebar() { const location = useLocation(); const { theme, toggleTheme } = useTheme(); const [sources, setSources] = useState([]); // ── Load sources + refresh when any upload completes ───────────────────── const loadSources = () => { fetchSources() .then(setSources) .catch(() => { }); }; useEffect(() => { loadSources(); // Listen for the custom event fired by notifySidebarRefresh() in api.ts window.addEventListener('sources-updated', loadSources); return () => window.removeEventListener('sources-updated', loadSources); }, []); const pdfSources = sources.filter(s => s.type === 'pdf'); const webSources = sources.filter(s => s.type === 'web'); const youtubeSources = sources.filter(s => s.type === 'youtube'); return (
{/* Header */}

InteleX

Intelligence

{/* Navigation */} {/* Sources Preview */}
{pdfSources.length > 0 && (

PDF Documents ({pdfSources.length})

{pdfSources.slice(0, 2).map(source => ( ))}
)} {webSources.length > 0 && (

Web Pages ({webSources.length})

{webSources.slice(0, 2).map(source => ( ))}
)} {youtubeSources.length > 0 && (

YouTube Videos ({youtubeSources.length})

{youtubeSources.slice(0, 2).map(source => ( ))}
)} {sources.length === 0 && (

No sources yet. Upload a PDF, website, or YouTube video.

)}
{/* New Source Button */}
New Source
); }