1
1
import { Button } from "@/components/Button" ;
2
- import * as Dialog from "@radix-ui/react-dialog" ;
3
2
import {
4
3
ResizableHandle ,
5
4
ResizablePanel ,
@@ -15,6 +14,7 @@ import type { ParserLog, PreviewOutput } from "@/gen/types";
15
14
import { useDebouncedValue } from "@/hooks/debounce" ;
16
15
import { useStore } from "@/store" ;
17
16
import { cn } from "@/utils/cn" ;
17
+ import * as Dialog from "@radix-ui/react-dialog" ;
18
18
import {
19
19
ActivityIcon ,
20
20
BugIcon ,
@@ -31,10 +31,10 @@ import {
31
31
useCallback ,
32
32
useEffect ,
33
33
useMemo ,
34
- useRef ,
35
34
useState ,
36
35
} from "react" ;
37
36
import { useSearchParams } from "react-router" ;
37
+ import ReactJsonView from "@microlink/react-json-view" ;
38
38
39
39
export const Preview : FC = ( ) => {
40
40
const $wasmState = useStore ( ( state ) => state . wasmState ) ;
@@ -48,7 +48,6 @@ export const Preview: FC = () => {
48
48
const [ params ] = useSearchParams ( ) ;
49
49
const isDebug = useMemo ( ( ) => params . has ( "debug" ) , [ params ] ) ;
50
50
51
-
52
51
const onDownloadOutput = useCallback ( ( ) => {
53
52
const blob = new Blob ( [ JSON . stringify ( output , null , 2 ) ] , {
54
53
type : "application/json" ,
@@ -59,7 +58,16 @@ export const Preview: FC = () => {
59
58
const link = document . createElement ( "a" ) ;
60
59
link . href = url ;
61
60
link . download = "output.json" ;
61
+ document . appendChild ( link ) ;
62
62
link . click ( ) ;
63
+ document . removeChild ( link ) ;
64
+
65
+ // Give the click event enough time to fire and then revoke the URL.
66
+ // This method of doing it doesn't seem great but I'm not sure if there is a
67
+ // better way.
68
+ setTimeout ( ( ) => {
69
+ URL . revokeObjectURL ( url ) ;
70
+ } , 100 ) ;
63
71
} , [ output ] ) ;
64
72
65
73
useEffect ( ( ) => {
@@ -125,7 +133,13 @@ export const Preview: FC = () => {
125
133
< Tabs . Trigger value = "preview" icon = { PlayIcon } label = "Preview" />
126
134
< Tabs . Trigger value = "debug" icon = { BugIcon } label = "Debugger" />
127
135
</ div >
128
- < Button size = "sm" variant = "outline" className = "self-center" onClick = { onDownloadOutput } >
136
+ < Button
137
+ size = "sm"
138
+ variant = "outline"
139
+ className = "self-center"
140
+ onClick = { onDownloadOutput }
141
+ disabled = { isDebouncing }
142
+ >
129
143
< DownloadIcon />
130
144
Download output
131
145
</ Button >
@@ -353,7 +367,9 @@ const Debugger: FC<DebuggerProps> = ({ output }) => {
353
367
direction = "vertical"
354
368
className = "h-full w-full bg-surface-primary"
355
369
>
356
- < ResizablePanel > foo</ ResizablePanel >
370
+ < ResizablePanel >
371
+ < ReactJsonView src = { output ?? { } } />
372
+ </ ResizablePanel >
357
373
< ResizableHandle className = "bg-surface-quaternary" />
358
374
< ResizablePanel
359
375
className = { cn (
0 commit comments