Skip to content

Commit

Permalink
fix: preview page using runframe (#604)
Browse files Browse the repository at this point in the history
* fix: preview page using runframe

* typo

* update test

* test update

* test update
  • Loading branch information
imrishabh18 authored Jan 23, 2025
1 parent c6f539b commit 6894251
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 37 deletions.
11 changes: 2 additions & 9 deletions playwright-tests/preview-page.spec.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,7 @@
import { expect, test } from "@playwright/test"

test(`preview-snippet Page`, async ({ page }) => {
await page.goto("http://127.0.0.1:5177/preview?snippet_id=snippet_5&view=pcb")
await page.waitForTimeout(5000)
await page.goto("http://127.0.0.1:5177/preview?snippet_id=snippet_5")
await page.waitForTimeout(20000)
await expect(page).toHaveScreenshot(`preview-snippet-pcb.png`)

await page.goto(
"http://127.0.0.1:5177/preview?snippet_id=snippet_5&view=schematic",
)
// Wait for schematic viewer to load
await page.waitForTimeout(5000)
await expect(page).toHaveScreenshot(`preview-snippet-schematic.png`)
})
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
30 changes: 2 additions & 28 deletions src/pages/preview.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
import { CircuitToSvgWithMouseControl } from "@/components/CircuitToSvgWithMouseControl"
import { useSnippet } from "@/hooks/use-snippet"
import { useUrlParams } from "@/hooks/use-url-params"
import { CadViewer } from "@tscircuit/3d-viewer"
import { PCBViewer } from "@tscircuit/pcb-viewer"
import { CircuitJsonPreview } from "@tscircuit/runframe"
import { Loader2 } from "lucide-react"

export const PreviewPage = () => {
const urlParams = useUrlParams()
const snippetId = urlParams.snippet_id
const view = urlParams.view || "pcb"
const { data: snippet, isLoading, error } = useSnippet(snippetId)

if (isLoading) {
Expand Down Expand Up @@ -43,28 +40,5 @@ export const PreviewPage = () => {
)
}

const validViews = ["pcb", "3d", "schematic"]
if (!validViews.includes(view)) {
return (
<div className="w-full h-screen">
{view === "pcb" && (
<PCBViewer soup={snippet.circuit_json} height={window.innerHeight} />
)}
</div>
)
}

return (
<div className="w-full h-screen">
{view === "pcb" && (
<PCBViewer soup={snippet.circuit_json} height={window.innerHeight} />
)}
{view === "3d" && <CadViewer soup={snippet.circuit_json as any} />}
{view === "schematic" && (
<CircuitToSvgWithMouseControl
circuitJson={snippet.circuit_json as any}
/>
)}
</div>
)
return <CircuitJsonPreview circuitJson={snippet.circuit_json as any} />
}

0 comments on commit 6894251

Please sign in to comment.