@@ -17,8 +17,7 @@ import {
17
17
} from "@/client/components/Select" ;
18
18
import * as Tabs from "@/client/components/Tabs" ;
19
19
import { useTheme } from "@/client/contexts/theme" ;
20
- import type { Diagnostic } from "@/client/diagnostics" ;
21
- import { useStore } from "@/client/store" ;
20
+ import { outputToDiagnostics , type Diagnostic } from "@/client/diagnostics" ;
22
21
import type {
23
22
ParameterWithSource ,
24
23
ParserLog ,
@@ -70,10 +69,12 @@ export const Preview: FC<PreviewProps> = ({
70
69
onReset,
71
70
setOwner,
72
71
} ) => {
73
- const $errors = useStore ( ( state ) => state . errors ) ;
74
72
const [ params ] = useSearchParams ( ) ;
75
73
const isDebug = params . has ( "debug" ) ;
76
74
const [ tab , setTab ] = useState ( ( ) => "preview" ) ;
75
+ const [ showErrors , setShowErrors ] = useState ( true ) ;
76
+
77
+ const errors = output ? outputToDiagnostics ( output ) : [ ] ;
77
78
78
79
const onDownloadOutput = ( ) => {
79
80
const blob = new Blob ( [ JSON . stringify ( output , null , 2 ) ] , {
@@ -204,13 +205,12 @@ export const Preview: FC<PreviewProps> = ({
204
205
< Tabs . Content value = "preview" asChild = { true } >
205
206
< div
206
207
aria-hidden = {
207
- wasmLoadState !== "loaded" ||
208
- ( $errors . show && $errors . diagnostics . length > 0 )
208
+ wasmLoadState !== "loaded" || ( showErrors && errors . length > 0 )
209
209
}
210
210
className = { cn (
211
211
"flex h-full w-full flex-col items-start gap-4 p-5 " ,
212
212
( wasmLoadState !== "loaded" ||
213
- ( $errors . show && $ errors. diagnostics . length > 0 ) ) &&
213
+ ( showErrors && errors . length > 0 ) ) &&
214
214
"pointer-events-none" ,
215
215
isDebug && "max-h-[calc(100%-48px)]" ,
216
216
) }
@@ -267,7 +267,11 @@ export const Preview: FC<PreviewProps> = ({
267
267
< Debugger output = { output } />
268
268
</ Tabs . Content >
269
269
270
- < ErrorPane />
270
+ < ErrorPane
271
+ errors = { errors }
272
+ setShowErrors = { setShowErrors }
273
+ showErrors = { showErrors }
274
+ />
271
275
</ ResizablePanel >
272
276
</ Tabs . Root >
273
277
) ;
@@ -303,16 +307,22 @@ const PreviewEmptyState = () => {
303
307
) ;
304
308
} ;
305
309
306
- const ErrorPane = ( ) => {
307
- const $errors = useStore ( ( state ) => state . errors ) ;
308
- const $toggleShowError = useStore ( ( state ) => state . toggleShowError ) ;
309
-
310
- const hasErrors = useMemo ( ( ) => $errors . diagnostics . length > 0 , [ $errors ] ) ;
310
+ type ErrorPaneProps = {
311
+ errors : Diagnostic [ ] ;
312
+ showErrors : boolean ;
313
+ setShowErrors : React . Dispatch < React . SetStateAction < boolean > > ;
314
+ } ;
315
+ const ErrorPane : FC < ErrorPaneProps > = ( {
316
+ errors,
317
+ setShowErrors,
318
+ showErrors,
319
+ } ) => {
320
+ const hasErrors = errors . length > 0 ;
311
321
312
322
return (
313
323
< >
314
324
< AnimatePresence propagate = { true } >
315
- { $errors . show && hasErrors ? (
325
+ { showErrors && hasErrors ? (
316
326
// lint/a11y/useKeyWithClickEvents: key events don't seem to
317
327
// work for divs, and I'm otherwise not sure how to make this element
318
328
// more accesible. But I think it's fine since the functionality is able to
@@ -324,7 +334,7 @@ const ErrorPane = () => {
324
334
aria-hidden = { true }
325
335
className = "absolute top-0 left-0 h-full w-full cursor-pointer bg-black/10 dark:bg-black/50"
326
336
onClick = { ( ) => {
327
- $toggleShowError ( false ) ;
337
+ setShowErrors ( false ) ;
328
338
} }
329
339
>
330
340
{ /* OVERLAY */ }
@@ -342,21 +352,21 @@ const ErrorPane = () => {
342
352
exit = { { opacity : 0 } }
343
353
className = { cn (
344
354
"absolute bottom-0 left-0 flex max-h-[60%] w-full flex-col justify-start" ,
345
- $errors . show && "h-auto" ,
355
+ showErrors && "h-auto" ,
346
356
) }
347
357
>
348
358
< motion . button
349
359
className = "flex h-4 min-h-4 w-full items-center justify-center rounded-t-xl bg-border-destructive"
350
- onClick = { ( ) => $toggleShowError ( ) }
360
+ onClick = { ( ) => setShowErrors ( ( curr ) => ! curr ) }
351
361
aria-label = {
352
- $errors . show ? "Hide error dialog" : "Show error dialog"
362
+ showErrors ? "Hide error dialog" : "Show error dialog"
353
363
}
354
364
>
355
365
< div className = "h-0.5 w-2/3 max-w-32 rounded-full bg-white/40" > </ div >
356
366
</ motion . button >
357
367
358
368
< AnimatePresence propagate = { true } >
359
- { $errors . show ? (
369
+ { showErrors ? (
360
370
< motion . div
361
371
initial = { { height : 0 } }
362
372
animate = { {
@@ -366,7 +376,7 @@ const ErrorPane = () => {
366
376
className = "flex flex-col gap-6 overflow-y-scroll bg-surface-secondary"
367
377
>
368
378
< div className = "flex w-full flex-col gap-3 p-6" >
369
- { $ errors. diagnostics . map ( ( diagnostic , index ) => (
379
+ { errors . map ( ( diagnostic , index ) => (
370
380
< ErrorBlock diagnostic = { diagnostic } key = { index } />
371
381
) ) }
372
382
</ div >
0 commit comments