Spaces:
Paused
Paused
File size: 8,720 Bytes
55153d0 8846eb6 55153d0 8846eb6 55153d0 8846eb6 8075297 55153d0 8846eb6 55153d0 8846eb6 55153d0 8075297 55153d0 8846eb6 55153d0 8846eb6 55153d0 8075297 55153d0 8846eb6 55153d0 8846eb6 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 | import { useState, useEffect } from 'react'
import { AnimatePresence, motion } from 'framer-motion'
import {
Home, FileText, Search, Code, Settings, Shield, ArrowLeft, Rocket,
Dna, BookOpen,
} from 'lucide-react'
import Dashboard from './Dashboard.jsx'
import FileDetail from './FileDetail.jsx'
import FileIntelligence from './FileIntelligence.jsx'
import FileDossier from './FileDossier.jsx'
import FormulasPanel from './FormulasPanel.jsx'
import QueryPanel from './QueryPanel.jsx'
import APIPanel from './APIPanel.jsx'
import SettingsPanel from './SettingsPanel.jsx'
import PipelinePanel from './PipelinePanel.jsx'
import { useContextMenu } from './ContextMenu.jsx'
const API_BASE = ''
const navItems = [
{ id: 'dashboard', label: 'Dashboard', icon: Home },
{ id: 'files', label: 'Files', icon: FileText },
{ id: 'intel', label: 'Intelligence', icon: Dna },
{ id: 'dossier', label: 'Dossier', icon: FileText },
{ id: 'formulas', label: 'Formulas', icon: BookOpen },
{ id: 'query', label: 'Query', icon: Search },
{ id: 'pipeline', label: 'Pipeline', icon: Rocket },
{ id: 'api', label: 'API', icon: Code },
{ id: 'settings', label: 'Settings', icon: Settings },
]
export default function CommandCenter({ activePanel, setActivePanel, onExit, selectedFileId, setSelectedFileId }) {
const { openNavMenu } = useContextMenu()
const [health, setHealth] = useState(null)
const [fileCount, setFileCount] = useState(0)
useEffect(() => {
const poll = async () => {
try {
const hRes = await fetch(`${API_BASE}/health`)
const h = await hRes.json()
setHealth(h)
setFileCount(h.files_registered ?? 0)
} catch {
setHealth({ status: 'error' })
}
}
poll()
const id = setInterval(poll, 10000)
return () => clearInterval(id)
}, [])
const isLive = health?.status === 'ok'
const renderPanel = () => {
switch (activePanel) {
case 'dashboard':
return <Dashboard setActivePanel={setActivePanel} onSelectFile={(id) => { setSelectedFileId(id); setActivePanel('files') }} />
case 'files':
return <FileDetail fileId={selectedFileId} onClear={() => setSelectedFileId(null)} />
case 'intel':
return <FileIntelligence fileId={selectedFileId} onBack={() => { setSelectedFileId(null); setActivePanel('dashboard') }} />
case 'dossier':
return selectedFileId
? <FileDossier fileId={selectedFileId} onClose={() => { setSelectedFileId(null); setActivePanel('dashboard') }} />
: <FileSelector onFileSelect={(id) => { setSelectedFileId(id); setActivePanel('dossier') }} />
case 'formulas':
return <FormulasPanel />
case 'query':
return <QueryPanel />
case 'pipeline':
return <PipelinePanel />
case 'api':
return <APIPanel />
case 'settings':
return <SettingsPanel />
default:
return <Dashboard setActivePanel={setActivePanel} onSelectFile={(id) => { setSelectedFileId(id); setActivePanel('files') }} />
}
}
return (
<div className="flex h-screen w-screen overflow-hidden bg-bg">
{/* Sidebar */}
<div className="w-56 flex-shrink-0 glass-strong border-r border-white/5 flex flex-col">
{/* Logo */}
<div className="flex items-center gap-2 px-5 h-14 border-b border-white/5">
<div className="w-7 h-7 rounded-lg bg-gradient-to-br from-primary to-accent flex items-center justify-center glow-orange">
<span className="text-bg font-black text-sm">J</span>
</div>
<span className="font-bold tracking-tight">Jorki</span>
<span className={`ml-auto text-[10px] font-mono flex items-center gap-1 ${isLive ? 'text-success' : 'text-critical'}`}>
<span className={`w-1.5 h-1.5 rounded-full ${isLive ? 'bg-success animate-pulse' : 'bg-critical'}`} />
{isLive ? 'LIVE' : 'OFF'}
</span>
</div>
{/* Nav */}
<nav className="flex-1 overflow-y-auto thin-scrollbar py-3 px-2">
{navItems.map(item => (
<button
key={item.id}
onClick={() => setActivePanel(item.id)}
onContextMenu={(e) => openNavMenu(e, item)}
className={`w-full flex items-center gap-3 px-3 py-2.5 rounded-xl text-sm transition-all mb-0.5 ${activePanel === item.id
? 'glass-orange text-primary font-medium'
: 'text-secondary hover:text-text hover:bg-white/5'
}`}
>
<item.icon className="w-4 h-4 flex-shrink-0" />
<span className="flex-1 text-left">{item.label}</span>
{item.id === 'files' && fileCount > 0 && (
<span className="text-[10px] font-mono px-1.5 py-0.5 rounded bg-white/5 text-secondary">
{fileCount}
</span>
)}
</button>
))}
</nav>
{/* Bottom — real status only */}
<div className="border-t border-white/5 p-3 space-y-2">
<div className="flex items-center gap-2 px-3 py-2 rounded-xl glass text-xs">
<Shield className={`w-3.5 h-3.5 ${isLive ? 'text-success' : 'text-critical'}`} />
<span className="text-secondary">{isLive ? 'Verified' : 'Unverified'}</span>
<span className={`ml-auto font-mono ${isLive ? 'text-success' : 'text-critical'}`}>
{health?.version ? `v${health.version}` : '—'}
</span>
</div>
<button
onClick={onExit}
className="w-full flex items-center gap-2 text-xs text-secondary/60 hover:text-text px-3 py-2 transition-colors"
>
<ArrowLeft className="w-3 h-3" />
Back to Landing
</button>
</div>
</div>
{/* Main content */}
<div className="flex-1 flex flex-col overflow-hidden">
{/* Top bar — real data only */}
<div className="h-14 border-b border-white/5 glass-strong flex items-center px-6 gap-4 flex-shrink-0">
<h2 className="text-sm font-semibold capitalize">
{navItems.find(n => n.id === activePanel)?.label || 'Dashboard'}
</h2>
<div className="flex-1" />
<div className="flex items-center gap-3 text-xs">
<div className="flex items-center gap-1.5 text-secondary">
<FileText className="w-3.5 h-3.5 text-primary" />
<span className="font-mono tabular-nums">{fileCount} files</span>
</div>
<div className="w-px h-4 bg-white/10" />
<div className="flex items-center gap-1.5 text-secondary">
<span className={`w-1.5 h-1.5 rounded-full ${isLive ? 'bg-success' : 'bg-critical'}`} />
<span className="font-mono">{isLive ? 'Space Live' : 'Space Down'}</span>
</div>
</div>
</div>
{/* Panel content */}
<div className="flex-1 overflow-y-auto thin-scrollbar">
<AnimatePresence mode="wait">
<motion.div
key={activePanel}
initial={{ opacity: 0, y: 10 }}
animate={{ opacity: 1, y: 0 }}
exit={{ opacity: 0, y: -10 }}
transition={{ duration: 0.2 }}
className="h-full"
>
{renderPanel()}
</motion.div>
</AnimatePresence>
</div>
</div>
</div>
)
}
function FileSelector({ onFileSelect }) {
const [files, setFiles] = useState([])
useEffect(() => {
fetch(`${API_BASE}/files`).then(r => r.json()).then(d => setFiles(d.files || [])).catch(() => { })
}, [])
return (
<div className="p-6">
<div className="glass rounded-2xl p-5">
<div className="text-sm font-semibold mb-4">Select a file to view dossier</div>
{files.length === 0 ? (
<div className="text-xs text-secondary/40 py-4 text-center">No files indexed. Upload from Dashboard.</div>
) : (
<div className="space-y-1">
{files.map(f => (
<button
key={f.file_id}
onClick={() => onFileSelect(f.file_id)}
className="w-full flex items-center gap-3 py-2.5 px-3 rounded-xl glass hover:glass-orange text-secondary hover:text-primary transition-all"
>
<FileText className="w-4 h-4 flex-shrink-0" />
<span className="text-xs font-mono flex-1 text-left">{f.filename}</span>
<span className="text-[10px] font-mono text-secondary/40">{f.size}</span>
</button>
))}
</div>
)}
</div>
</div>
)
}
|