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 4 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.
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
36 changes: 15 additions & 21 deletions src/components/ViewSnippetSidebar.tsx
Original file line number Diff line number Diff line change
@@ -1,24 +1,8 @@
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 { 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"

export default function ViewSnippetSidebar({
Expand Down Expand Up @@ -126,8 +110,18 @@ export default function ViewSnippetSidebar({
<div className="p-4 border-t border-gray-200 space-y-4">
<div className="space-y-1">
<div className="text-xs font-medium">Copy embed code</div>
<div className="text-[0.5em] p-2 rounded-sm bg-blue-50 border border-blue-200 cursor-pointer font-mono whitespace-nowrap overflow-hidden text-ellipsis">
{`<iframe src="https://snippets.tscircuit.com/embed/seveibar/circuitmodule" width="100%" height="100%"></iframe>`}
<div
className="text-[0.5em] p-2 rounded-sm bg-blue-50 border border-blue-200 cursor-pointer font-mono whitespace-nowrap overflow-hidden text-ellipsis"
onClick={() => {
const embedCode = `<iframe src="${window.location.origin}/preview?snippet_id=${snippet?.snippet_id}" width="100%" height="500" frameborder="0"></iframe>`
navigator.clipboard.writeText(embedCode)
toast({
title: "Copied!",
description: "Embed code copied to clipboard",
})
}}
>
{`<iframe src="${window.location.origin}/preview?snippet_id=${snippet?.snippet_id}" width="100%" height="500" frameborder="0"></iframe>`}
</div>
</div>
<div className="space-y-1">
Expand Down
42 changes: 42 additions & 0 deletions src/pages/preview.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import { PreviewContent } from "@/components/PreviewContent"
import { useRunTsx } from "@/hooks/use-run-tsx"
import { useSnippet } from "@/hooks/use-snippet"
import { useUrlParams } from "@/hooks/use-url-params"
import { useState } from "react"

export const PreviewPage = () => {
const urlParams = useUrlParams()
const snippetId = urlParams.snippet_id
const { data: snippet } = useSnippet(snippetId)
const [manualEditsFileContent, setManualEditsFileContent] = useState("")

const {
message: errorMessage,
circuitJson,
triggerRunTsx,
tsxRunTriggerCount,
} = useRunTsx({
code: snippet?.code ?? "",
type: snippet?.snippet_type,
})

if (!snippet) return null

return (
<div className="w-full h-full">
<PreviewContent
className="w-full h-full"
code={snippet.code}
triggerRunTsx={triggerRunTsx}
tsxRunTriggerCount={tsxRunTriggerCount}
errorMessage={errorMessage}
circuitJson={circuitJson}
showCodeTab={false}
showJsonTab={true}
showImportAndFormatButtons={false}
manualEditsFileContent={manualEditsFileContent}
onManualEditsFileContentChange={setManualEditsFileContent}
/>
</div>
)
}
Loading