Skip to content

Drop in a screenshot and convert it to clean code (HTML/Tailwind/React/Vue)

Python

aider: Add a button to download the code as index.html in frontend/src/components/Preview.tsx.

Abi Rajafdecb93ea659
diff --git a/frontend/src/components/Preview.tsx b/frontend/src/components/Preview.tsx
index c8508b1b..ff225133 100644
--- a/frontend/src/components/Preview.tsx
+++ b/frontend/src/components/Preview.tsx
@@ -1,8 +1,18 @@
+import { useState } from 'react';
+
interface Props {
code: string;
}
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 (
<div className="w-[704px]">
<iframe
@@ -11,6 +21,9 @@ function Preview({ code }: Props) {
className="border-[5px] border-black rounded-[33px] p-4 shadow-lg
transform scale-[0.8] origin-top-left w-[1280px] h-[832px]"
></iframe>
+ <button onClick={createBlobUrl} href={blobUrl} download="index.html">
+ Download code
+ </button>
</div>
);
}