Drop in a screenshot and convert it to clean code (HTML/Tailwind/React/Vue)
Python
support import from code
Abi Rajac900201417dc
diff --git a/frontend/src/App.tsx b/frontend/src/App.tsxindex 7605b0d1..f32b2848 100644--- a/frontend/src/App.tsx+++ b/frontend/src/App.tsx@@ -337,27 +337,20 @@ function App() {// Set input statesetIsImportedFromCode(true);- console.log(code);-// Set up this project- // TODO*- // setGeneratedCode(code);setStack(stack);- // setAppHistory([- // {- // type: "code_create",- // parentIndex: null,- // code,- // inputs: { code },- // },- // ]);- // setVariant(0, {- // type: "code_create",- // parentIndex: null,- // code,- // });- // setCurrentVariantIndex(0);- // setCurrentVersion(0);++ // Set up the import commit+ const commit = createCommit({+ type: "code_create",+ parentHash: null,+ date_created: new Date(),+ variants: [{ code }],+ selectedVariantIndex: 0,+ inputs: null,+ });+ addCommit(commit);+ setHead(commit.hash);// Set the app statesetAppState(AppState.CODE_READY);diff --git a/frontend/src/components/history/HistoryDisplay.tsx b/frontend/src/components/history/HistoryDisplay.tsxindex 5b81f225..057c07d4 100644--- a/frontend/src/components/history/HistoryDisplay.tsx+++ b/frontend/src/components/history/HistoryDisplay.tsx@@ -22,7 +22,11 @@ export default function HistoryDisplay({ shouldDisableReverts }: Props) {// TODO: Clean this upconst newHistory = Object.values(commits).flatMap((commit) => {- if (commit.type === "ai_create" || commit.type === "ai_edit") {+ if (+ commit.type === "ai_create" ||+ commit.type === "ai_edit" ||+ commit.type === "code_create"+ ) {return {type: commit.type,hash: commit.hash,diff --git a/frontend/src/components/history/history_types.ts b/frontend/src/components/history/history_types.tsindex 183b1b62..e9171fc4 100644--- a/frontend/src/components/history/history_types.ts+++ b/frontend/src/components/history/history_types.ts@@ -17,8 +17,12 @@ export type BaseCommit = {import { nanoid } from "nanoid";// TODO: Move to a different file+// TODO: Fix the type to be betterexport function createCommit(- commit: Omit<AiCreateCommit, "hash"> | Omit<AiEditCommit, "hash">+ commit:+ | Omit<AiCreateCommit, "hash">+ | Omit<AiEditCommit, "hash">+ | Omit<CodeCreateCommit, "hash">): Commit {const hash = nanoid();return { ...commit, hash };@@ -38,7 +42,12 @@ export type AiEditCommit = BaseCommit & {};};-export type Commit = AiCreateCommit | AiEditCommit;+export type CodeCreateCommit = BaseCommit & {+ type: "code_create";+ inputs: null;+};++export type Commit = AiCreateCommit | AiEditCommit | CodeCreateCommit;export type RenderedHistoryItem = {type: string;diff --git a/frontend/src/components/history/utils.ts b/frontend/src/components/history/utils.tsindex e4429254..965a3429 100644--- a/frontend/src/components/history/utils.ts+++ b/frontend/src/components/history/utils.ts@@ -8,23 +8,20 @@ export function extractHistory(let currentCommitHash: CommitHash | null = hash;while (currentCommitHash !== null) {- const commit: Commit = commits[currentCommitHash];+ const commit: Commit | null = commits[currentCommitHash];if (commit) {- if (commit.type === "ai_create") {- // Don't include the image for ai_create- flatHistory.unshift(commit.variants[commit.selectedVariantIndex].code);- } else if (commit.type === "ai_edit") {- flatHistory.unshift(commit.variants[commit.selectedVariantIndex].code);+ flatHistory.unshift(commit.variants[commit.selectedVariantIndex].code);++ // For edits, add the prompt to the history+ if (commit.type === "ai_edit") {flatHistory.unshift(commit.inputs.prompt);}- // } else if (item.type === "code_create") {- // flatHistory.unshift(item.code);- // }// Move to the parent of the current itemcurrentCommitHash = commit.parentHash;} else {+ // TODO*: Send to Sentrythrow new Error("Malformed history: missing parent index");}}@@ -39,6 +36,8 @@ export function summarizeHistoryItem(commit: Commit) {return "Create";case "ai_edit":return commit.inputs.prompt;+ case "code_create":+ return "Imported from code";default: {const exhaustiveCheck: never = commitType;throw new Error(`Unhandled case: ${exhaustiveCheck}`);diff --git a/frontend/src/components/variants/Variants.tsx b/frontend/src/components/variants/Variants.tsxindex 3ad9f983..9a9fc454 100644--- a/frontend/src/components/variants/Variants.tsx+++ b/frontend/src/components/variants/Variants.tsx@@ -3,13 +3,17 @@ import { useProjectStore } from "../../store/project-store";function Variants() {const { head, commits, updateSelectedVariantIndex } = useProjectStore();- // TODO: Is HEAD null right? And check variants.length === 0 ||+ // TODO*: Is HEAD null right? And check variants.length === 0 ||if (head === null) {return null;}- const variants = commits[head || ""].variants;- const selectedVariantIndex = commits[head || ""].selectedVariantIndex;+ const variants = commits[head].variants;+ const selectedVariantIndex = commits[head].selectedVariantIndex;++ if (variants.length <= 1) {+ return <div className="mt-2"></div>;+ }return (<div className="mt-4 mb-4">