move download button to main App
This commit is contained in:
parent
c0d1c23145
commit
126972bee0
@ -10,6 +10,13 @@ function App() {
|
|||||||
);
|
);
|
||||||
const [generatedCode, setGeneratedCode] = useState<string>("");
|
const [generatedCode, setGeneratedCode] = useState<string>("");
|
||||||
const [referenceImages, setReferenceImages] = useState<string[]>([]);
|
const [referenceImages, setReferenceImages] = useState<string[]>([]);
|
||||||
|
const [blobUrl, setBlobUrl] = useState("");
|
||||||
|
|
||||||
|
const createBlobUrl = () => {
|
||||||
|
const blob = new Blob([generatedCode], { type: "text/html" });
|
||||||
|
const url = URL.createObjectURL(blob);
|
||||||
|
setBlobUrl(url);
|
||||||
|
};
|
||||||
|
|
||||||
function startCodeGeneration(referenceImages: string[]) {
|
function startCodeGeneration(referenceImages: string[]) {
|
||||||
setAppState("CODING");
|
setAppState("CODING");
|
||||||
@ -40,6 +47,11 @@ function App() {
|
|||||||
<img className="w-[300px]" src={referenceImages[0]} alt="Reference" />
|
<img className="w-[300px]" src={referenceImages[0]} alt="Reference" />
|
||||||
{/* Show code preview only when coding */}
|
{/* Show code preview only when coding */}
|
||||||
{appState === "CODING" && <CodePreview code={generatedCode} />}
|
{appState === "CODING" && <CodePreview code={generatedCode} />}
|
||||||
|
{appState === "CODE_READY" && (
|
||||||
|
<a onClick={createBlobUrl} href={blobUrl} download="index.html">
|
||||||
|
Download code
|
||||||
|
</a>
|
||||||
|
)}
|
||||||
<Preview code={generatedCode} />
|
<Preview code={generatedCode} />
|
||||||
</>
|
</>
|
||||||
)}
|
)}
|
||||||
|
|||||||
@ -1,18 +1,8 @@
|
|||||||
import { useState } from "react";
|
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
code: string;
|
code: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
function Preview({ code }: Props) {
|
function Preview({ code }: Props) {
|
||||||
const [blobUrl, setBlobUrl] = useState("");
|
|
||||||
|
|
||||||
const createBlobUrl = () => {
|
|
||||||
const blob = new Blob([code], { type: "text/html" });
|
|
||||||
const url = URL.createObjectURL(blob);
|
|
||||||
setBlobUrl(url);
|
|
||||||
};
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="w-[704px]">
|
<div className="w-[704px]">
|
||||||
<iframe
|
<iframe
|
||||||
@ -21,9 +11,6 @@ function Preview({ code }: Props) {
|
|||||||
className="border-[5px] border-black rounded-[33px] p-4 shadow-lg
|
className="border-[5px] border-black rounded-[33px] p-4 shadow-lg
|
||||||
transform scale-[0.8] origin-top-left w-[1280px] h-[832px]"
|
transform scale-[0.8] origin-top-left w-[1280px] h-[832px]"
|
||||||
></iframe>
|
></iframe>
|
||||||
<a onClick={createBlobUrl} href={blobUrl} download="index.html">
|
|
||||||
Download code
|
|
||||||
</a>
|
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user