import { useState, useRef, useEffect } from 'react'; import { Save, Play, Plus, ArrowLeft, FileText, Zap, Code, Loader2, } from 'lucide-react'; import { Button } from '../../ui/Button'; import { Badge } from '../../ui/Badge'; import { Dropdown } from '../../ui/Dropdown'; import { useNotebookStore } from '../../../lib/notebook-store'; import type { CellType } from '../../../lib/types'; export function NotebookToolbar() { const { notebook, dirty, saving, runningCells, saveNotebook, addCell, runAllCells, updateTitle, updateEngine, } = useNotebookStore(); const [editingTitle, setEditingTitle] = useState(false); const [titleDraft, setTitleDraft] = useState(''); const titleInputRef = useRef(null); useEffect(() => { if (editingTitle && titleInputRef.current) { titleInputRef.current.focus(); titleInputRef.current.select(); } }, [editingTitle]); if (!notebook) return null; const isRunning = runningCells.size > 0; function handleTitleClick() { setTitleDraft(notebook!.metadata.title); setEditingTitle(true); } function commitTitle() { const trimmed = titleDraft.trim(); if (trimmed && trimmed !== notebook!.metadata.title) { updateTitle(trimmed); } setEditingTitle(false); } function handleTitleKeyDown(e: React.KeyboardEvent) { if (e.key === 'Enter') { commitTitle(); } else if (e.key === 'Escape') { setEditingTitle(false); } } const addCellItems = [ { label: 'Markdown', icon: , onClick: () => addCell('markdown' as CellType), }, { label: 'SPICE', icon: , onClick: () => addCell('spice' as CellType), }, { label: 'Python', icon: , onClick: () => addCell('python' as CellType), }, ]; return (
{/* Back link */} {/* Editable title */}
{editingTitle ? ( setTitleDraft(e.target.value)} onBlur={commitTitle} onKeyDown={handleTitleKeyDown} className="bg-slate-800 border border-slate-600 rounded px-2 py-1 text-sm text-slate-100 w-full max-w-md focus:outline-none focus:border-blue-500" /> ) : ( )}
{/* Engine badge */} {/* Dirty indicator */} {dirty && ( unsaved )} {/* Add Cell dropdown */} Add Cell } items={addCellItems} /> {/* Run All */} {/* Save */}
); }