Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

/preview route #179

Merged
merged 28 commits into from
Nov 16, 2024
Merged
Show file tree
Hide file tree
Changes from 15 commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
2f7768d
added preview page
mrudulpatil18 Nov 9, 2024
12d54bd
added /preview route
mrudulpatil18 Nov 9, 2024
428f756
enabled copy emebed from snippet sidebar
mrudulpatil18 Nov 9, 2024
a9c1dee
format
mrudulpatil18 Nov 9, 2024
3e9f60f
added playwright tests for preview snippets
mrudulpatil18 Nov 10, 2024
3da1ee4
url fix
mrudulpatil18 Nov 11, 2024
73b617a
Merge branch 'main' into issue-171
mrudulpatil18 Nov 14, 2024
5da6553
update preview route
mrudulpatil18 Nov 14, 2024
b8302c0
format
mrudulpatil18 Nov 14, 2024
6272dca
added save-button classname for testing
mrudulpatil18 Nov 14, 2024
fc62875
added circuit_json to seed.ts
mrudulpatil18 Nov 14, 2024
4cd7726
added playwright-test
mrudulpatil18 Nov 14, 2024
6dfa14f
removed previous test snapshots
mrudulpatil18 Nov 14, 2024
4ca1620
default /preview to pcb
mrudulpatil18 Nov 14, 2024
974bb42
updated bun.lockb
mrudulpatil18 Nov 14, 2024
4f9e6ce
Merge branch 'main' into issue-171
mrudulpatil18 Nov 15, 2024
241d7ec
improve pcbview reloading (#213)
seveibar Nov 15, 2024
34b6a98
format fix
mrudulpatil18 Nov 15, 2024
0fad79a
removed 3d view from test
mrudulpatil18 Nov 15, 2024
a694435
update core and circuit-to-svg for capacitor rotation fixes (#220)
seveibar Nov 15, 2024
2a30d86
run tests against main branch
seveibar Nov 15, 2024
4c91e24
Update renovate.json
seveibar Nov 15, 2024
51993b8
fix format
seveibar Nov 15, 2024
9e1ef5e
chore(deps): update dependency circuit-to-svg to ^0.0.78 (#223)
renovate[bot] Nov 15, 2024
0be7d28
chore(deps): update dependency @tscircuit/core to ^0.0.180 (#219)
renovate[bot] Nov 15, 2024
0a02532
fix(deps): update dependency jscad-electronics to ^0.0.20 (#226)
renovate[bot] Nov 15, 2024
a080f5a
fix(deps): update dependency @tscircuit/3d-viewer to ^0.0.38 (#224)
renovate[bot] Nov 16, 2024
971fcfa
Merge branch 'issue-171'
mrudulpatil18 Nov 16, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified bun.lockb
Binary file not shown.
1,474 changes: 1,474 additions & 0 deletions fake-snippets-api/lib/db/seed.ts

Large diffs are not rendered by default.

19 changes: 19 additions & 0 deletions playwright-tests/preview-page.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
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(1000)
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(1000)
await expect(page).toHaveScreenshot(`preview-snippet-schematic.png`)

await page.goto("http://127.0.0.1:5177/preview?snippet_id=snippet_5&view=3d")
// Wait for 3D viewer to load
await page.waitForTimeout(1000)
await expect(page).toHaveScreenshot(`preview-snippet-3d.png`)
})
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { EditorPage } from "./pages/editor"
import { LandingPage } from "./pages/landing"
import { MyOrdersPage } from "./pages/my-orders"
import { NewestPage } from "./pages/newest"
import { PreviewPage } from "./pages/preview"
import { QuickstartPage } from "./pages/quickstart"
import { SearchPage } from "./pages/search"
import { SettingsPage } from "./pages/settings"
Expand All @@ -31,6 +32,7 @@ function App() {
<Route path="/authorize" component={AuthenticatePage} />
<Route path="/my-orders" component={MyOrdersPage} />
<Route path="/orders/:orderId" component={ViewOrderPage} />
<Route path="/preview" component={PreviewPage} />
<Route path="/:username" component={UserProfilePage} />
<Route path="/:author/:snippetName" component={ViewSnippetPage} />
</Switch>
Expand Down
2 changes: 1 addition & 1 deletion src/components/EditorNav.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ export default function EditorNav({
<Button
variant="outline"
size="sm"
className={"h-6 px-2 text-xs"}
className={"h-6 px-2 text-xs save-button"}
disabled={!isLoggedIn || !canSave}
onClick={onSave}
>
Expand Down
24 changes: 4 additions & 20 deletions src/components/ViewSnippetSidebar.tsx
Original file line number Diff line number Diff line change
@@ -1,26 +1,10 @@
import { Link } from "wouter"
import { Button } from "@/components/ui/button"
import { Input } from "@/components/ui/input"
import {
Code,
Monitor,
Bot,
GitFork,
AtSign,
Package,
Settings,
Link as LinkIcon,
Copy,
Hash,
Clock,
File,
} from "lucide-react"
import { GitHubLogoIcon } from "@radix-ui/react-icons"
import { cn } from "@/lib/utils"
import { useCopyToClipboard } from "@/hooks/use-copy-to-clipboard"
import { useCurrentSnippet } from "@/hooks/use-current-snippet"
import { useToast } from "@/hooks/use-toast"
import { cn } from "@/lib/utils"
import { AtSign, Bot, Clock, Code, File, GitFork, Package } from "lucide-react"
import { Link } from "wouter"
import { useFilesDialog } from "./dialogs/files-dialog"
import { useCopyToClipboard } from "@/hooks/use-copy-to-clipboard"

export default function ViewSnippetSidebar({
className,
Expand Down
70 changes: 70 additions & 0 deletions src/pages/preview.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
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 { 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) {
return (
<div className="w-full h-screen flex items-center justify-center">
<Loader2 className="w-8 h-8 animate-spin" />
</div>
)
}

if (error) {
return (
<div className="w-full h-screen flex items-center justify-center text-red-500">
Error loading snippet: {error.message}
</div>
)
}

if (!snippet) {
return (
<div className="w-full h-screen flex items-center justify-center text-gray-500">
Snippet not found
</div>
)
}

if (!snippet.circuit_json) {
return (
<div className="w-full h-screen flex items-center justify-center text-gray-500">
No circuit data available
</div>
)
}

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>
)
}