| // src/components/data-hub/ProtocolsWorkspace.tsx | |
| import { useState } from "react"; | |
| import { useProtocolsWorkspace } from "@/hooks/useProtocolsWorkspace"; | |
| import { ProtocolStepCard } from "./ProtocolStepCard"; | |
| import { Plus, GitFork, Edit, Play, Check, X, Loader2, ClipboardList } from "lucide-react"; | |
| export function ProtocolsWorkspace() { | |
| const { | |
| protocols, loading, activeProtocolId, setActiveProtocolId, activeProtocol, | |
| editMode, setEditMode, runMode, setRunMode, | |
| createProtocol, addStep, updateStep, toggleStepComplete, forkProtocol, | |
| } = useProtocolsWorkspace(); | |
| const [newTitle, setNewTitle] = useState(""); | |
| const handleCreate = () => { | |
| if (!newTitle.trim()) return; | |
| createProtocol({ title: newTitle.trim(), steps: [], materials: [], tags: [], authors: [] }); | |
| setNewTitle(""); | |
| }; | |
| if (loading) return <div className="flex justify-center py-8"><Loader2 className="w-6 h-6 animate-spin text-gray-400"/></div>; | |
| return ( | |
| <div className="grid grid-cols-1 lg:grid-cols-3 gap-6"> | |
| {/* Protocol list */} | |
| <div className="space-y-2"> | |
| <div className="flex gap-2 mb-3"> | |
| <input type="text" value={newTitle} onChange={e => setNewTitle(e.target.value)} placeholder="New protocol title" className="flex-1 text-sm px-3 py-1.5 bg-white/10 rounded-lg" | |
| onKeyDown={e => e.key === "Enter" && handleCreate()} /> | |
| <button onClick={handleCreate} className="btn btn-primary btn-sm" aria-label="Button"><Plus className="w-4 h-4"/></button> | |
| </div> | |
| {protocols.map(proto => ( | |
| <button key={proto.id} onClick={() => setActiveProtocolId(proto.id)} | |
| className={`w-full text-left p-3 rounded-xl transition ${ | |
| activeProtocolId === proto.id ? "bg-primary/10 border border-primary/30" : "hover:bg-white/5 border border-transparent" | |
| }`}> | |
| <p className="font-semibold text-sm truncate">{proto.title}</p> | |
| <p className="text-xs text-gray-500">{proto.steps.length} steps · v{proto.version}</p> | |
| </button> | |
| ))} | |
| </div> | |
| {/* Protocol detail */} | |
| <div className="lg:col-span-2"> | |
| {!activeProtocol ? ( | |
| <div className="text-center py-12 text-gray-400"><ClipboardList className="w-10 h-10 mx-auto mb-3 opacity-30"/><p>Select or create a protocol</p></div> | |
| ) : ( | |
| <div className="space-y-4"> | |
| <div className="flex items-center justify-between"> | |
| <h3 className="font-bold text-lg">{activeProtocol.title}</h3> | |
| <div className="flex gap-2"> | |
| <button onClick={() => setRunMode(!runMode)} className={`btn btn-ghost btn-sm gap-1 ${runMode ? "text-green-600" : ""}`}> | |
| <Play className="w-4 h-4"/> {runMode ? "Exit Bench Mode" : "Run at Bench"} | |
| </button> | |
| <button onClick={() => setEditMode(!editMode)} className={`btn btn-ghost btn-sm gap-1 ${editMode ? "text-primary" : ""}`}> | |
| <Edit className="w-4 h-4"/> Edit | |
| </button> | |
| <button onClick={() => forkProtocol(activeProtocol.id)} className="btn btn-ghost btn-sm gap-1"> | |
| <GitFork className="w-4 h-4"/> Fork | |
| </button> | |
| </div> | |
| </div> | |
| {activeProtocol.materials.length > 0 && ( | |
| <div className="p-3 bg-amber-50/30 dark:bg-amber-900/10 rounded-xl"> | |
| <h4 className="text-xs font-semibold text-amber-700 dark:text-amber-400 mb-1">Materials</h4> | |
| <ul className="list-disc pl-5 text-sm space-y-0.5">{activeProtocol.materials.map((m, i) => <li key={i}>{m}</li>)}</ul> | |
| </div> | |
| )} | |
| {/* Steps */} | |
| <div className="space-y-3"> | |
| {activeProtocol.steps.map((step, idx) => ( | |
| <ProtocolStepCard key={step.id} step={step} index={idx} runMode={runMode} editMode={editMode} | |
| onToggleComplete={() => toggleStepComplete(activeProtocol.id, step.id)} | |
| onUpdate={(data) => updateStep(activeProtocol.id, step.id, data)} /> | |
| ))} | |
| </div> | |
| {editMode && ( | |
| <button onClick={() => addStep(activeProtocol.id, { title: "New Step", description: "", isCheckpoint: true })} | |
| className="btn btn-secondary w-full gap-2"><Plus className="w-4 h-4"/> Add Step</button> | |
| )} | |
| </div> | |
| )} | |
| </div> | |
| </div> | |
| ); | |
| } |
Xet Storage Details
- Size:
- 4.48 kB
- Xet hash:
- 952dc78facf22667e1dc516a9f6b3a88f867cf3592e44d93e7923ecc3140852a
·
Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.