make layout better

This commit is contained in:
Abi Raja 2023-11-14 23:33:06 -05:00
parent 51c7334c0e
commit c4b99c125e
3 changed files with 90 additions and 70 deletions

View File

@ -21,6 +21,14 @@ function App() {
setBlobUrl(url); setBlobUrl(url);
}; };
const reset = () => {
setAppState("INITIAL");
setGeneratedCode("");
setReferenceImages([]);
setExecutionConsole([]);
setBlobUrl("");
};
function startCodeGeneration(referenceImages: string[]) { function startCodeGeneration(referenceImages: string[]) {
setAppState("CODING"); setAppState("CODING");
setReferenceImages(referenceImages); setReferenceImages(referenceImages);
@ -42,34 +50,42 @@ function App() {
} }
return ( return (
<div className="mx-auto mt-6 max-w-[1000px]"> <div className="mt-6">
<h1 className="text-4xl mb-2 text-center">Screenshot to Code</h1> <div className="hidden lg:fixed lg:inset-y-0 lg:z-50 lg:flex lg:w-96 lg:flex-col">
<h1 className="text-base text-gray-500 mb-2 text-center"> <div className="flex grow flex-col gap-y-2 overflow-y-auto border-r border-gray-200 bg-white px-6">
drag & drop a screenshot below <h1 className="text-2xl mt-10">Screenshot to Code</h1>
</h1> <h2 className="text-sm text-gray-500 mb-2">
Drag & drop a screenshot to get started.
{appState === "INITIAL" && ( </h2>
<>
<ImageUpload setReferenceImages={startCodeGeneration} />
</>
)}
{(appState === "CODING" || appState === "CODE_READY") && ( {(appState === "CODING" || appState === "CODE_READY") && (
<> <>
<div className="flex gap-x-2 justify-around"> {/* Show code preview only when coding */}
{appState === "CODING" && (
<div className="flex flex-col">
<div className="flex items-center gap-x-1">
<Spinner />
{executionConsole.slice(-1)[0]}
</div>
<CodePreview code={generatedCode} />
</div>
)}
<div className="flex gap-x-2">
<div <div
className={classNames({ className={classNames({
"scanning relative": appState === "CODING", "scanning relative": appState === "CODING",
})} })}
> >
<img <img
className="w-[300px]" className="w-[340px]"
src={referenceImages[0]} src={referenceImages[0]}
alt="Reference" alt="Reference"
/> />
</div> </div>
<div className="bg-gray-400 px-4 py-2 rounded text-sm hidden"> <div className="bg-gray-400 px-4 py-2 rounded text-sm hidden">
<h2 className="text-lg mb-4 border-b border-gray-800">Console</h2> <h2 className="text-lg mb-4 border-b border-gray-800">
Console
</h2>
{executionConsole.map((line, index) => ( {executionConsole.map((line, index) => (
<div <div
key={index} key={index}
@ -80,18 +96,9 @@ function App() {
))} ))}
</div> </div>
</div> </div>
{/* Show code preview only when coding */}
{appState === "CODING" && (
<>
<div className="flex items-center gap-x-1">
<Spinner />
{executionConsole.slice(-1)[0]}
</div>
<CodePreview code={generatedCode} />
</>
)}
{appState === "CODE_READY" && ( {appState === "CODE_READY" && (
<div className="flex items-center gap-x-2 mb-4 justify-end"> <div className="flex items-center gap-x-2 mb-4">
<a <a
className="bg-button/70 hover:bg-highlight text-black className="bg-button/70 hover:bg-highlight text-black
py-2 px-4 rounded transition duration-300" py-2 px-4 rounded transition duration-300"
@ -99,23 +106,36 @@ function App() {
href={blobUrl} href={blobUrl}
download="index.html" download="index.html"
> >
Download code Download
</a> </a>
<a <button
className="bg-button/70 hover:bg-highlight text-black className="bg-button/70 hover:bg-highlight text-black
py-2 px-4 rounded transition duration-300" py-2 px-4 rounded transition duration-300"
onClick={createBlobUrl} onClick={reset}
href={blobUrl}
download="index.html"
> >
Reset Reset
</a> </button>
</div> </div>
)} )}
<Preview code={generatedCode} />
</> </>
)} )}
</div> </div>
</div>
<main className="py-2 lg:pl-96">
{appState === "INITIAL" && (
<>
<ImageUpload setReferenceImages={startCodeGeneration} />
</>
)}
{(appState === "CODING" || appState === "CODE_READY") && (
<div className="ml-4">
<Preview code={generatedCode} />
</div>
)}
</main>
</div>
); );
} }

View File

@ -5,7 +5,7 @@ import { toast } from "react-hot-toast";
const baseStyle = { const baseStyle = {
flex: 1, flex: 1,
width: "50%", width: "80%",
margin: "0 auto", margin: "0 auto",
minHeight: "400px", minHeight: "400px",
display: "flex", display: "flex",

View File

@ -28,6 +28,6 @@ body {
transform: translateX(0px); transform: translateX(0px);
} }
50% { 50% {
transform: translateX(300px); transform: translateX(340px);
} }
} }