File tree 2 files changed +20
-4
lines changed
2 files changed +20
-4
lines changed Original file line number Diff line number Diff line change 1
1
{
2
- "name" : " dsn-viewer2 " ,
2
+ "name" : " circuit-json-viewer " ,
3
3
"private" : true ,
4
4
"version" : " 0.0.0" ,
5
5
"type" : " module" ,
Original file line number Diff line number Diff line change @@ -6,10 +6,11 @@ function App() {
6
6
const [ error , setError ] = useState < string | null > ( null )
7
7
8
8
const processFile = useCallback (
9
- async ( content : string ) => {
9
+ async ( content : string | object ) => {
10
10
setError ( null )
11
11
try {
12
- const jsonContent = JSON . parse ( content )
12
+ const jsonContent =
13
+ typeof content === "string" ? JSON . parse ( content ) : content
13
14
setCircuitJson ( jsonContent )
14
15
} catch ( err ) {
15
16
console . error ( "Processing error:" , err )
@@ -85,7 +86,22 @@ function App() {
85
86
</ p >
86
87
</ div >
87
88
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" >
89
105
Circuit JSON Viewer created by{ " " }
90
106
< a
91
107
className = "underline hover:text-blue-400"
You can’t perform that action at this time.
0 commit comments