| 397 | |
| 398 | // Create file |
| 399 | const handleCreateFile = async () => { |
| 400 | if (!newFileName.trim()) return; |
| 401 | const filePath = path ? `${path}/${newFileName.trim()}` : newFileName.trim(); |
| 402 | try { |
| 403 | await fetch("/api/files/write", { |
| 404 | method: "POST", |
| 405 | headers: { "Content-Type": "application/json" }, |
| 406 | body: JSON.stringify({ workspace, path: filePath, content: "" }), |
| 407 | }); |
| 408 | setNewFileName(""); |
| 409 | setShowNewFile(false); |
| 410 | loadItems(); |
| 411 | // Open editor immediately |
| 412 | setEditorFile({ workspace, path: filePath, name: newFileName.trim() }); |
| 413 | } catch { |
| 414 | alert("Failed to create file"); |
| 415 | } |
| 416 | }; |
| 417 | |
| 418 | // Drag and drop |
| 419 | const handleDragOver = (e: React.DragEvent) => { e.preventDefault(); setDragging(true); }; |