Skip to content

Commit

Permalink
refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
imrishabh18 committed Oct 29, 2024
1 parent bfe725a commit dc2ba71
Showing 1 changed file with 8 additions and 12 deletions.
20 changes: 8 additions & 12 deletions src/components/CodeEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,12 @@ import { EditorView, basicSetup } from "codemirror"
import ts from "typescript"
import { useImportSnippetDialog } from "./dialogs/import-snippet-dialog"

const DEFAULT_IMPORTS = `
import React from "@types/react/jsx-runtime"
import { Circuit, createUseComponent } from "@tscircuit/core"
import type { CommonLayoutProps } from "@tscircuit/props"
`

export const CodeEditor = ({
onCodeChange,
onDtsChange,
Expand Down Expand Up @@ -272,12 +278,7 @@ export const CodeEditor = ({

// Initial ATA run for index.tsx
if (currentFile === "index.tsx") {
ata(`
import React from "@types/react/jsx-runtime"
import { Circuit, createUseComponent } from "@tscircuit/core"
import type { CommonLayoutProps } from "@tscircuit/props"
${files["index.tsx"]}
`)
ata(`${DEFAULT_IMPORTS}${files["index.tsx"]}`)
}

return () => {
Expand All @@ -301,12 +302,7 @@ ${files["index.tsx"]}

useEffect(() => {
if (ataRef.current && currentFile === "index.tsx") {
ataRef.current(`
import React from "@types/react/jsx-runtime"
import { Circuit, createUseComponent } from "@tscircuit/core"
import type { CommonLayoutProps } from "@tscircuit/props"
${files["index.tsx"]}
`)
ataRef.current(`${DEFAULT_IMPORTS}${files["index.tsx"]}`)
}
}, [codeImports])

Expand Down

0 comments on commit dc2ba71

Please sign in to comment.