From 5f0dbc3612c7e8705e06b924d326c72a27462f45 Mon Sep 17 00:00:00 2001 From: Paulo Pinto Date: Thu, 5 Sep 2024 11:56:21 +0100 Subject: [PATCH 1/7] Lift state for playgroundInfo --- src/ui/App.tsx | 10 ++++++++-- src/ui/preview/Preview.tsx | 18 +++++++----------- 2 files changed, 15 insertions(+), 13 deletions(-) diff --git a/src/ui/App.tsx b/src/ui/App.tsx index e93d359d..43855880 100644 --- a/src/ui/App.tsx +++ b/src/ui/App.tsx @@ -11,13 +11,14 @@ import { useNavigate, useRouteLoaderData, } from 'react-router-dom'; -import { StrictMode, useEffect } from 'react'; +import { StrictMode, useEffect, useState } from 'react'; import { NewSession } from '@/ui/start/NewSession'; import { ViewSession } from '@/ui/session/ViewSession'; import { Home } from '@/ui/start/Home'; import { getConfig, setConfig } from '@/storage/config'; import { getSession, listSessions, Session } from '@/storage/session'; import { PlaceholderPreview } from '@/ui/preview/PlaceholderPreview'; +import { PlaygroundInfo } from '@/ui/preview/Playground'; export const Screens = { home: () => '/start/home', @@ -75,11 +76,16 @@ function App() { }, [ location ] ); const session = useRouteLoaderData( 'session' ) as Session; + const [ playgroundInfo, setPlaygroundInfo ] = useState< PlaygroundInfo >(); const preview = ! session ? ( ) : ( - + setPlaygroundInfo( playgroundInfo ) } + /> ); return ( diff --git a/src/ui/preview/Preview.tsx b/src/ui/preview/Preview.tsx index 70cff15b..5a8bd230 100644 --- a/src/ui/preview/Preview.tsx +++ b/src/ui/preview/Preview.tsx @@ -6,10 +6,13 @@ const tabFront = 0; const tabAdmin = 1; const defaultTab = tabFront; -export function Preview( props: { sessionId: string } ) { - const { sessionId } = props; +export function Preview( props: { + sessionId: string; + playgroundInfo?: PlaygroundInfo; + onReady: ( info: PlaygroundInfo ) => void; +} ) { + const { sessionId, playgroundInfo, onReady } = props; const [ currentTab, setCurrentTab ] = useState< number >( defaultTab ); - const [ playgroundInfo, setPlaygroundInfo ] = useState< PlaygroundInfo >(); const previewAdminUrl = playgroundInfo?.url && playgroundInfo.url?.length > 0 @@ -28,14 +31,7 @@ export function Preview( props: { sessionId: string } ) { /> ); - const previewFront = ( - { - setPlaygroundInfo( info ); - } } - /> - ); + const previewFront = ; const previewAdmin = (