11import { createFileRoute , useNavigate } from '@tanstack/solid-router'
22import { createServerFn } from '@tanstack/solid-start'
33import { useServerFn } from '@tanstack/solid-start'
4- import { createSignal , onMount , Show } from 'solid-js'
4+ import { createSignal , Match , onMount , Switch } from 'solid-js'
55import PlaygroundLanding from '../components/playground/PlaygroundLanding'
66import PlaygroundLayout from '../components/playground/PlaygroundLayout'
77import SurfaceCard from '../components/ui/SurfaceCard'
@@ -74,7 +74,6 @@ function PlaygroundPage() {
7474 const result = await startManualSession ( { data : { } } )
7575 const nextSession = result as PlaygroundSession
7676 setSession ( nextSession )
77- setLoading ( false )
7877 navigate ( { search : { session : nextSession . id } , replace : true } )
7978 } catch ( e ) {
8079 setError ( e instanceof Error ? e . message : 'Failed to create playground session.' )
@@ -83,67 +82,72 @@ function PlaygroundPage() {
8382 }
8483 }
8584
86- const shouldShowLanding = ( ) => ! search ( ) . session && ! session ( )
85+ const currentState = ( ) => {
86+ if ( session ( ) ) return 'session'
87+ if ( loading ( ) ) return 'loading'
88+ if ( ! search ( ) . session ) return 'landing'
89+ return 'unavailable'
90+ }
8791
8892 return (
89- < >
90- < Show when = { shouldShowLanding ( ) } >
93+ < Switch >
94+ < Match when = { currentState ( ) === 'landing' } >
9195 < PlaygroundLanding
9296 creatingSession = { creatingManualSession ( ) }
9397 error = { error ( ) }
9498 onStartManualSession = { handleStartManualSession }
9599 />
96- </ Show >
97-
98- < Show when = { ! shouldShowLanding ( ) } >
99- < Show
100- when = { session ( ) }
101- keyed
102- fallback = {
103- loading ( ) ? (
104- < div class = "flex min-h-[calc(100dvh-56px)] items-center justify-center" >
105- < div class = "h-6 w-6 animate-spin rounded-full border-2 border-accent border-t-transparent" />
106- </ div >
107- ) : (
108- < main class = "mx-auto flex min-h-[calc(100dvh-56px)] w-full max-w-3xl items-center px-4 py-10" >
109- < SurfaceCard class = "w-full rounded-[2rem] p-8 " >
110- < p class = "text-[0.68rem] font-semibold uppercase tracking-[0.2em] text-text-muted " >
111- Playground session
112- </ p >
113- < h1 class = "mt-3 text-3xl font-semibold tracking-tight text-text-primary" >
114- Session unavailable
115- </ h1 >
116- < p class = "mt-3 text-sm leading-7 text-text-secondary" >
117- { error ( ) || 'This playground session could not be loaded.' }
118- </ p >
119- < div class = "mt-6 flex flex-col gap-3 sm:flex-row" >
120- < button
121- type = "button"
122- onClick = { ( ) => {
123- setError ( '' )
124- navigate ( { search : { } , replace : true } )
125- } }
126- class = "inline-flex items-center justify-center rounded-xl border border-surface-card-border bg-surface-card px-4 py-3 text-sm font-semibold text-text-primary transition hover:-translate-y-[1px] hover:border-accent/30 hover:text-accent active:translate-y-0 active:scale-[0.98] "
127- >
128- Back to MCP instructions
129- </ button >
130- < button
131- type = "button "
132- onClick = { ( ) => void handleStartManualSession ( ) }
133- disabled = { creatingManualSession ( ) }
134- class = "inline-flex items-center justify-center rounded-xl bg-accent px-4 py-3 text-sm font-semibold text-white transition hover:-translate-y-[1px] hover:bg-accent/90 disabled:cursor-wait disabled:opacity-70 active:translate-y-0 active:scale-[0.98]"
135- >
136- { creatingManualSession ( ) ? 'Starting manual session...' : 'Start manual session' }
137- </ button >
138- </ div >
139- </ SurfaceCard >
140- </ main >
141- )
142- }
143- >
144- { ( loadedSession ) => < PlaygroundLayout session = { loadedSession } /> }
145- </ Show >
146- </ Show >
147- </ >
100+ </ Match >
101+
102+ < Match when = { currentState ( ) === 'loading' } >
103+ < div class = "flex min-h-[calc(100dvh-56px)] items-center justify-center" >
104+ < div class = "h-6 w-6 animate-spin rounded-full border-2 border-accent border-t-transparent" />
105+ </ div >
106+ </ Match >
107+
108+ < Match when = { currentState ( ) === 'session' } >
109+ < PlaygroundLayout session = { session ( ) as PlaygroundSession } />
110+ </ Match >
111+
112+ < Match when = { currentState ( ) === 'unavailable' } >
113+ < main class = "mx-auto flex min-h-[calc(100dvh-56px)] w-full max-w-3xl items-center px-4 py-10 " >
114+ < SurfaceCard class = "w-full rounded-[2rem] p-8 " >
115+ < p class = "text-[0.68rem] font-semibold uppercase tracking-[0.2em] text-text-muted" >
116+ Playground session
117+ </ p >
118+ < h1 class = "mt-3 text-3xl font-semibold tracking-tight text-text-primary" >
119+ Session unavailable
120+ </ h1 >
121+ < p
122+ role = "alert"
123+ aria-live = "assertive"
124+ class = "mt-3 text-sm leading-7 text-text-secondary"
125+ >
126+ { error ( ) || 'This playground session could not be loaded.' }
127+ </ p >
128+ < div class = "mt-6 flex flex-col gap-3 sm:flex-row" >
129+ < button
130+ type = "button "
131+ onClick = { ( ) => {
132+ setError ( '' )
133+ navigate ( { search : { } , replace : true } )
134+ } }
135+ class = "inline-flex items-center justify-center rounded-xl border border-surface-card-border bg-surface-card px-4 py-3 text-sm font-semibold text-text-primary transition hover:-translate-y-[1px] hover:border-accent/30 hover:text-accent active:translate-y-0 active:scale-[0.98] "
136+ >
137+ Back to MCP instructions
138+ </ button >
139+ < button
140+ type = "button"
141+ onClick = { ( ) => void handleStartManualSession ( ) }
142+ disabled = { creatingManualSession ( ) }
143+ class = "inline-flex items-center justify-center rounded-xl bg-accent px-4 py-3 text-sm font-semibold text-white transition hover:-translate-y-[1px] hover:bg-accent/90 disabled:cursor-wait disabled:opacity-70 active:translate-y-0 active:scale-[0.98]"
144+ >
145+ { creatingManualSession ( ) ? 'Starting manual session...' : 'Start manual session' }
146+ </ button >
147+ </ div >
148+ </ SurfaceCard >
149+ </ main >
150+ </ Match >
151+ </ Switch >
148152 )
149153}
0 commit comments