@@ -17,8 +17,7 @@ import {
1717} from "@/client/components/Select" ;
1818import * as Tabs from "@/client/components/Tabs" ;
1919import { 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" ;
2221import type {
2322 ParameterWithSource ,
2423 ParserLog ,
@@ -70,10 +69,12 @@ export const Preview: FC<PreviewProps> = ({
7069 onReset,
7170 setOwner,
7271} ) => {
73- const $errors = useStore ( ( state ) => state . errors ) ;
7472 const [ params ] = useSearchParams ( ) ;
7573 const isDebug = params . has ( "debug" ) ;
7674 const [ tab , setTab ] = useState ( ( ) => "preview" ) ;
75+ const [ showErrors , setShowErrors ] = useState ( true ) ;
76+
77+ const errors = output ? outputToDiagnostics ( output ) : [ ] ;
7778
7879 const onDownloadOutput = ( ) => {
7980 const blob = new Blob ( [ JSON . stringify ( output , null , 2 ) ] , {
@@ -204,13 +205,12 @@ export const Preview: FC<PreviewProps> = ({
204205 < Tabs . Content value = "preview" asChild = { true } >
205206 < div
206207 aria-hidden = {
207- wasmLoadState !== "loaded" ||
208- ( $errors . show && $errors . diagnostics . length > 0 )
208+ wasmLoadState !== "loaded" || ( showErrors && errors . length > 0 )
209209 }
210210 className = { cn (
211211 "flex h-full w-full flex-col items-start gap-4 p-5 " ,
212212 ( wasmLoadState !== "loaded" ||
213- ( $errors . show && $ errors. diagnostics . length > 0 ) ) &&
213+ ( showErrors && errors . length > 0 ) ) &&
214214 "pointer-events-none" ,
215215 isDebug && "max-h-[calc(100%-48px)]" ,
216216 ) }
@@ -267,7 +267,11 @@ export const Preview: FC<PreviewProps> = ({
267267 < Debugger output = { output } />
268268 </ Tabs . Content >
269269
270- < ErrorPane />
270+ < ErrorPane
271+ errors = { errors }
272+ setShowErrors = { setShowErrors }
273+ showErrors = { showErrors }
274+ />
271275 </ ResizablePanel >
272276 </ Tabs . Root >
273277 ) ;
@@ -303,16 +307,22 @@ const PreviewEmptyState = () => {
303307 ) ;
304308} ;
305309
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 ;
311321
312322 return (
313323 < >
314324 < AnimatePresence propagate = { true } >
315- { $errors . show && hasErrors ? (
325+ { showErrors && hasErrors ? (
316326 // lint/a11y/useKeyWithClickEvents: key events don't seem to
317327 // work for divs, and I'm otherwise not sure how to make this element
318328 // more accesible. But I think it's fine since the functionality is able to
@@ -324,7 +334,7 @@ const ErrorPane = () => {
324334 aria-hidden = { true }
325335 className = "absolute top-0 left-0 h-full w-full cursor-pointer bg-black/10 dark:bg-black/50"
326336 onClick = { ( ) => {
327- $toggleShowError ( false ) ;
337+ setShowErrors ( false ) ;
328338 } }
329339 >
330340 { /* OVERLAY */ }
@@ -342,21 +352,21 @@ const ErrorPane = () => {
342352 exit = { { opacity : 0 } }
343353 className = { cn (
344354 "absolute bottom-0 left-0 flex max-h-[60%] w-full flex-col justify-start" ,
345- $errors . show && "h-auto" ,
355+ showErrors && "h-auto" ,
346356 ) }
347357 >
348358 < motion . button
349359 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 ) }
351361 aria-label = {
352- $errors . show ? "Hide error dialog" : "Show error dialog"
362+ showErrors ? "Hide error dialog" : "Show error dialog"
353363 }
354364 >
355365 < div className = "h-0.5 w-2/3 max-w-32 rounded-full bg-white/40" > </ div >
356366 </ motion . button >
357367
358368 < AnimatePresence propagate = { true } >
359- { $errors . show ? (
369+ { showErrors ? (
360370 < motion . div
361371 initial = { { height : 0 } }
362372 animate = { {
@@ -366,7 +376,7 @@ const ErrorPane = () => {
366376 className = "flex flex-col gap-6 overflow-y-scroll bg-surface-secondary"
367377 >
368378 < div className = "flex w-full flex-col gap-3 p-6" >
369- { $ errors. diagnostics . map ( ( diagnostic , index ) => (
379+ { errors . map ( ( diagnostic , index ) => (
370380 < ErrorBlock diagnostic = { diagnostic } key = { index } />
371381 ) ) }
372382 </ div >
0 commit comments