diff --git a/frontend/src/App.tsx b/frontend/src/App.tsx index 06bbec4..b45953e 100644 --- a/frontend/src/App.tsx +++ b/frontend/src/App.tsx @@ -16,14 +16,24 @@ function App() { const [generatedCode, setGeneratedCode] = useState(""); const [referenceImages, setReferenceImages] = useState([]); const [executionConsole, setExecutionConsole] = useState([]); - const [blobUrl, setBlobUrl] = useState(""); const [updateInstruction, setUpdateInstruction] = useState(""); const [history, setHistory] = useState([]); - const createBlobUrl = () => { + const downloadCode = () => { + // Create a blob from the generated code const blob = new Blob([generatedCode], { type: "text/html" }); const url = URL.createObjectURL(blob); - setBlobUrl(url); + + // Create an anchor element and set properties for download + const a = document.createElement("a"); + a.href = url; + a.download = "index.html"; // Set the file name for download + document.body.appendChild(a); // Append to the document + a.click(); // Programmatically click the anchor to trigger download + + // Clean up by removing the anchor and revoking the Blob URL + document.body.removeChild(a); + URL.revokeObjectURL(url); }; const reset = () => { @@ -31,7 +41,7 @@ function App() { setGeneratedCode(""); setReferenceImages([]); setExecutionConsole([]); - setBlobUrl(""); + setHistory([]); }; function doGenerateCode(params: CodeGenerationParams) { @@ -119,25 +129,6 @@ function App() { {appState === "CODE_READY" && (
-
- - Download - - -