Spaces:
Configuration error
Configuration error
Commit Β·
eb69de5
1
Parent(s): 5b4b486
commit initial 09-12-2025 017
Browse filesFiles changed (2)
- src/App.css+43
- src/App.js+102-120
405 unmodified lines406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451405 unmodified lines width: auto; }}
/* ---------- progress bar under menubar ---------- */.ide-progress-wrap { height: 3px; background: transparent; width: 100%; position: relative; overflow: hidden;}.ide-progress { position: absolute; height: 3px; width: 30%; left: -30%; top: 0; background: linear-gradient(90deg, #0e9, #08f); animation: progress-slide 1.2s linear infinite; border-radius: 2px;}
@keyframes progress-slide { 0% { left: -30%; width: 30%; } 50% { left: 35%; width: 40%; } 100% { left: 100%; width: 30%; }}
/* ---------- small inline spinner (optional) ---------- */.button-spinner { display: inline-block; width: 12px; height: 12px; border: 2px solid rgba(255,255,255,0.25); border-top-color: rgba(255,255,255,0.95); border-radius: 50%; animation: spin 0.8s linear infinite; margin-left: 6px; vertical-align: middle;}
@keyframes spin { to { transform: rotate(360deg); }}48 unmodified lines495051525354555657585914 unmodified lines74757672737778797 unmodified lines878889879091925 unmodified lines9899100991011021031041041051061073 unmodified lines1111121131141141151163 unmodified lines1201211221241231241251 unmodified line1271281291321301311329 unmodified lines14214314414814514614715114814915012 unmodified lines1631641651701661671731741751681691701791711721732 unmodified lines1761771781881891791801811826 unmodified lines1891901911921931941952022032041961971981992002012022032042052062 unmodified lines2092102112122132132142152162172182142152162172182192202212222232242252262272 unmodified lines23023123222722823323423523623723023123223323423523623723823924024124224324424524624724824925025125225325425525624324425725825926026126226326413 unmodified lines27827928026428128228328412 unmodified lines29729829928328430030130230330430530630730830931031129329429529629729829931231331431531631731830630730830931031131231932032132232332432532632732831631731831932032933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036133233333433536236336436536636719 unmodified lines3873883893623633643653663673683693703903913923932 unmodified lines39639739837938038138238338439940040140214 unmodified lines4174184194054064074084094104204214224234144154244254264274288 unmodified lines43743843943043143243344044144244344444544644044144244344444544644744844945045145245345445545645745845946046146246346446546646746844744844945045145245348 unmodified lines const editorRef = useRef(null); const fileInputRef = useRef(null);
// NEW: loading states const [isRunning, setIsRunning] = useState(false); const [isFixing, setIsFixing] = useState(false); const [isExplaining, setIsExplaining] = useState(false);
// Always persist tree on change useEffect(() => { saveTree(tree);14 unmodified lines };
// ---------- File / Folder actions ----------
// Create a new file inside selected folder (or root) const handleNewFile = () => { const filename = window.prompt("Filename (with extension):", "untitled.js"); if (!filename) return;7 unmodified lines parentPath = parts.join("/"); }
// Offer user to choose another parent folder const folders = collectFolderPaths(tree); const suggestion = parentPath || folders[0] || ""; const chosen = window.prompt(5 unmodified lines const updated = addFile(tree, filename, targetParent); setTree(updated);
// Set active to newly created file const newPath = (targetParent ? targetParent + "/" : "") + filename; setActivePath(newPath); };
// Create a folder under selected folder or root const handleNewFolder = () => { const name = window.prompt("Folder name:", "new_folder"); if (!name) return;3 unmodified lines setTree(updated); };
// Rename selected node (file or folder) const handleRename = () => { if (!activePath) return; const node = getNodeByPath(tree, activePath);3 unmodified lines const updated = renameNode(tree, activePath, newName); setTree(updated);
// compute new activePath (preserve parent) const parts = activePath.split("/"); parts.pop(); const parent = parts.join("/");1 unmodified line setActivePath(newPath); };
// Delete selected node (confirm if folder not empty) const handleDelete = () => { if (!activePath) return; const node = getNodeByPath(tree, activePath);9 unmodified lines
const updated = deleteNode(tree, activePath); setTree(updated); setActivePath(""); // deselect / fallback setActivePath(""); };
// Download single file const downloadFile = () => { const node = getNodeByPath(tree, activePath); if (!node || node.type !== "file") return;12 unmodified lines if (!f) return; const text = await f.text();
// decide parent folder const selected = getNodeByPath(tree, activePath); let parentPath = ""; if (selected?.type === "folder") parentPath = selected.path; // fallback // (above line intentionally split to maintain code clarity) // compute parent path correctly: if (selected?.type === "folder") parentPath = selected.path; else if (selected?.type === "file") parentPath = selected.path.split("/").slice(0, -1).join("");
// create file under parent and write content const updated = addFile(tree, f.name, parentPath); const newPath = (parentPath ? parentPath + "/" : "") + f.name; const finalTree = updateFileContent(updated, newPath, text);2 unmodified lines e.target.value = ""; };
// ---------- Run & Agent ----------
// ---------- Run & Agent (with progress flags) ---------- const handleRun = async () => { const node = getNodeByPath(tree, activePath); if (!node || node.type !== "file") {6 unmodified lines return; }
setIsRunning(true); setOutput(""); // clear previous setProblems([]); try { const res = await runCode(node.content, selectedLang, stdin); setOutput(res.output || ""); setProblems(res.error ? parseProblems(res.output) : []); const res = await runCode(node.content, selectedLang, stdin); setOutput(res.output || ""); setProblems(res.error ? parseProblems(res.output) : []); } catch (err) { setOutput(String(err)); } finally { setIsRunning(false); } };
const handleAskFix = async () => {2 unmodified lines setOutput("Select a file to apply fix."); return; } setIsFixing(true); try { const userHint = prompt.trim() ? `User request: ${prompt}` : ""; const reply = await askAgent( `Improve, debug, or refactor this ${LANGUAGE_OPTIONS.find((l) => node.name.endsWith(l.ext))?.id || "file"} file.\n${userHint}\nReturn ONLY updated code, no explanation.\n\nCODE:\n${node.content}` ); const updatedTree = updateFileContent(tree, node.path, reply); setTree(updatedTree); const userHint = prompt.trim() ? `User request: ${prompt}` : ""; const reply = await askAgent( `Improve, debug, or refactor this ${LANGUAGE_OPTIONS.find((l) => node.name.endsWith(l.ext))?.id || "file"} file.\n${userHint}\nReturn ONLY updated code, no explanation.\n\nCODE:\n${node.content}` ); const updatedTree = updateFileContent(tree, node.path, reply); setTree(updatedTree); } catch (err) { setOutput(String(err)); } finally { setIsFixing(false); } };
const handleExplainSelection = async () => {2 unmodified lines setExplanation("Select a file to explain."); return; } const editor = editorRef.current; let selectedCode = ""; setIsExplaining(true); try { const editor = editorRef.current; let selectedCode = ""; try { selectedCode = editor?.getModel()?.getValueInRange(editor.getSelection()) || ""; } catch {} const code = selectedCode.trim() || node.content; const userHint = prompt.trim() ? `Focus on: ${prompt}` : "Give a clear and simple explanation."; const reply = await askAgent( `Explain what this code does, any risks, and improvements.\n${userHint}\n\nCODE:\n${code}` ); setExplanation(reply); selectedCode = editor?.getModel()?.getValueInRange(editor.getSelection()) || ""; } catch {} const code = selectedCode.trim() || node.content; const userHint = prompt.trim() ? `Focus on: ${prompt}` : "Give a clear and simple explanation."; const reply = await askAgent( `Explain what this code does, any risks, and improvements.\n${userHint}\n\nCODE:\n${code}` ); setExplanation(reply); } catch (err) { setExplanation(String(err)); } finally { setIsExplaining(false); } };
// AI suggestions for continuation (simple) const fetchAiSuggestions = async (code) => { if (!code?.trim()) return; try { const reply = await askAgent(`Suggest possible next lines for continuation. Return 3 short snippets.\n${code}`); setAiSuggestions(reply.split("\n").filter((l) => l.trim())); const reply = await askAgent(`Suggest possible next lines for continuation. Return 3 short snippets.\n${code}`); setAiSuggestions(reply.split("\n").filter((l) => l.trim())); } catch { // ignore suggestion errors } };
// ---------- Search ----------13 unmodified lines setTree(updated); };
// ---------- Render Tree (moved inside component so it sees activePath) ---------- // ---------- Render Tree (inside component) ---------- const renderTree = (node, depth = 0) => { const isActive = node.path === activePath; return (12 unmodified lines <span className="ide-file-name">{node.name}</span> </div>
{node.children && node.children.map((c) => renderTree(c, depth + 1))} {node.children && node.children.map((c) => renderTree(c, depth + 1))} </div> ); };
// any loading? const anyLoading = isRunning || isFixing || isExplaining;
// ---------- JSX UI ---------- return ( <div className={`ide-root ${theme === "vs-dark" ? "ide-dark" : "ide-light"}`}> {/* Hidden file input for import */} <input ref={fileInputRef} id="file-import-input" type="file" style={{ display: "none" }} onChange={handleFileInputChange} /> <input ref={fileInputRef} id="file-import-input" type="file" style={{ display: "none" }} onChange={handleFileInputChange} />
{/* Top menu */} <div className="ide-menubar"> <div className="ide-menubar-left"> <span className="ide-logo">βοΈ DevMate IDE</span>
<button onClick={handleNewFile}>π New File</button> <button onClick={handleNewFolder}>π New Folder</button> <button onClick={handleRename}>βοΈ Rename</button> <button onClick={handleDelete}>π Delete</button> <button onClick={downloadFile}>π₯ Download</button> <button onClick={() => downloadProjectZip()}>π¦ ZIP</button> <button onClick={handleImportFileClick}>π€ Import File</button> <button onClick={handleNewFile} disabled={anyLoading}>π New File</button> <button onClick={handleNewFolder} disabled={anyLoading}>π New Folder</button> <button onClick={handleRename} disabled={anyLoading}>βοΈ Rename</button> <button onClick={handleDelete} disabled={anyLoading}>π Delete</button> <button onClick={downloadFile} disabled={anyLoading}>π₯ Download</button> <button onClick={() => downloadProjectZip()} disabled={anyLoading}>π¦ ZIP</button> <button onClick={handleImportFileClick} disabled={anyLoading}>π€ Import File</button> </div>
<div className="ide-menubar-right"> <button onClick={handleSearchToggle}>π Search</button> <button onClick={handleRun}>βΆ Run</button> <button onClick={handleAskFix}>π€ Fix</button> <button onClick={handleExplainSelection}>π Explain</button> <button onClick={() => setTheme((t) => (t === "vs-dark" ? "light" : "vs-dark"))}> <button onClick={handleSearchToggle} disabled={anyLoading}>π Search</button>
<button onClick={handleRun} disabled={isRunning || anyLoading}> {isRunning ? "β³ Running..." : "βΆ Run"} </button>
<button onClick={handleAskFix} disabled={isFixing || anyLoading}> {isFixing ? "β³ Fixing..." : "π€ Fix"} </button>
<button onClick={handleExplainSelection} disabled={isExplaining || anyLoading}> {isExplaining ? "β³ Explaining..." : "π Explain"} </button>
<button onClick={() => setTheme((t) => (t === "vs-dark" ? "light" : "vs-dark"))} disabled={anyLoading}> {theme === "vs-dark" ? "βοΈ" : "π"} </button> </div> </div>
{/* Indeterminate progress bar under menubar when busy */} {anyLoading && ( <div className="ide-progress-wrap"> <div className="ide-progress" /> </div> )}
{/* Body */} <div className="ide-body"> {/* Sidebar */} <div className="ide-sidebar"> <div className="ide-sidebar-header"> <span>EXPLORER</span> <button className="ide-icon-button" onClick={handleNewFile} title="New File">οΌ</button> </div> <div className="ide-file-list" style={{ padding: 6 }}> {renderTree(tree)} <button className="ide-icon-button" onClick={handleNewFile} title="New File" disabled={anyLoading}>οΌ</button> </div> <div className="ide-file-list" style={{ padding: 6 }}>{renderTree(tree)}</div> </div>
{/* Main (editor + bottom panels) */}19 unmodified lines {aiSuggestions.length > 0 && ( <div className="ai-popup"> {aiSuggestions.map((s, i) => ( <div key={i} className="ai-suggest" onClick={() => updateActiveFileContent((currentNode?.content || "") + "\n" + s) } > {s} </div> <div key={i} className="ai-suggest" onClick={() => updateActiveFileContent((currentNode?.content || "") + "\n" + s)}>{s}</div> ))} </div> )}2 unmodified lines <div className="ide-panels"> <pre className="ide-output">{output}</pre>
<input className="ide-input-box" placeholder="Program input..." value={stdin} onChange={(e) => setStdin(e.target.value)} /> <input className="ide-input-box" placeholder="Program input..." value={stdin} onChange={(e) => setStdin(e.target.value)} />
{problems.length > 0 && ( <div className="ide-problems-panel">14 unmodified lines
<div className="ide-ai-section"> <label className="ide-ai-label">Instruction</label> <textarea className="ide-agent-textarea" placeholder="Ask the AI (optimize, add tests, convert, etc.)" value={prompt} onChange={(e) => setPrompt(e.target.value)} /> <textarea className="ide-agent-textarea" placeholder="Ask the AI (optimize, add tests, convert, etc.)" value={prompt} onChange={(e) => setPrompt(e.target.value)} /> </div>
<div className="ide-ai-buttons"> <button onClick={handleAskFix}>π‘ Apply Fix</button> <button onClick={handleExplainSelection}>π Explain Code</button> <button onClick={handleAskFix} disabled={isFixing || anyLoading}>{isFixing ? "β³ Apply Fix" : "π‘ Apply Fix"}</button> <button onClick={handleExplainSelection} disabled={isExplaining || anyLoading}>{isExplaining ? "β³ Explaining" : "π Explain Code"}</button> </div>
{explanation && (8 unmodified lines {/* Search dialog */} {searchOpen && ( <div className="search-dialog"> <input placeholder="Search text..." onChange={(e) => setSearchQuery(e.target.value)} /> <input placeholder="Search text..." onChange={(e) => setSearchQuery(e.target.value)} /> <button onClick={handleSearchNow}>Search</button> </div> )}
{/* Context menu */} {contextMenu && ( <div className="ide-context-menu" style={{ top: contextMenu.y, left: contextMenu.x }} onMouseLeave={() => setContextMenu(null)} > <div onClick={() => { setContextMenu(null); handleRename(); }} > βοΈ Rename </div> <div onClick={() => { setContextMenu(null); handleDelete(); }} > π Delete </div> <div onClick={() => { setContextMenu(null); downloadFile(); }} > π₯ Download </div> <div className="ide-context-menu" style={{ top: contextMenu.y, left: contextMenu.x }} onMouseLeave={() => setContextMenu(null)}> <div onClick={() => { setContextMenu(null); handleRename(); }}>βοΈ Rename</div> <div onClick={() => { setContextMenu(null); handleDelete(); }}>π Delete</div> <div onClick={() => { setContextMenu(null); downloadFile(); }}>π₯ Download</div> </div> )} </div>src/App.css+43
src/App.js+102-120