Skip to content

Commit 6d1dbda

Browse files
committed
allow opening an example
1 parent 2c4d36d commit 6d1dbda

File tree

2 files changed

+20
-4
lines changed

2 files changed

+20
-4
lines changed

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"name": "dsn-viewer2",
2+
"name": "circuit-json-viewer",
33
"private": true,
44
"version": "0.0.0",
55
"type": "module",

src/App.tsx

+19-3
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,11 @@ function App() {
66
const [error, setError] = useState<string | null>(null)
77

88
const processFile = useCallback(
9-
async (content: string) => {
9+
async (content: string | object) => {
1010
setError(null)
1111
try {
12-
const jsonContent = JSON.parse(content)
12+
const jsonContent =
13+
typeof content === "string" ? JSON.parse(content) : content
1314
setCircuitJson(jsonContent)
1415
} catch (err) {
1516
console.error("Processing error:", err)
@@ -85,7 +86,22 @@ function App() {
8586
</p>
8687
</div>
8788

88-
<div className="text-gray-400 text-sm mt-16">
89+
<button
90+
onClick={async () => {
91+
try {
92+
const response = await fetch("/example.json")
93+
const exampleJson = await response.json()
94+
processFile(exampleJson)
95+
} catch (err) {
96+
setError("Failed to load example file")
97+
}
98+
}}
99+
className="mt-2 text-blue-400 hover:text-blue-300 underline"
100+
>
101+
or open an example
102+
</button>
103+
104+
<div className="text-gray-400 text-sm mt-8">
89105
Circuit JSON Viewer created by{" "}
90106
<a
91107
className="underline hover:text-blue-400"

0 commit comments

Comments
 (0)