import React, { PropsWithChildren, useContext, useEffect, useState } from 'react'; import './App.css'; import { Client } from './client'; import { createBrowserRouter, RouterProvider } from 'react-router-dom'; import { DesignPage } from './views/Design/Design'; import { GmView } from './views/GmView/GmView'; import { WebsocketProvider } from './components/WebsocketProvider'; import { PlayerView } from './views/PlayerView/PlayerView'; import { Admin } from './views/Admin/Admin'; import Candela from './plugins/Candela'; import { Authentication } from './views/Authentication/Authentication'; import { StateContext, StateProvider } from './providers/StateProvider/StateProvider'; const TEST_CHARSHEET_UUID = "12df9c09-1f2f-4147-8eda-a97bd2a7a803"; interface AppProps { client: Client; } const CandelaCharsheet = ({ client }: { client: Client }) => { let [sheet, setSheet] = useState(undefined); useEffect( () => { client.charsheet(TEST_CHARSHEET_UUID).then((c) => setSheet(c)); }, [client, setSheet] ); return sheet ? :
} interface AuthedViewProps { client: Client; } const AuthedView = ({ client, children }: PropsWithChildren) => { const [state, dispatch] = useContext(StateContext); return ( { dispatch({type: "SetAdminPassword", password }); }} onAuth={(username, password) => console.log(username, password)}> {children} ); } const App = ({ client }: AppProps) => { console.log("rendering app"); const [websocketUrl, setWebsocketUrl] = useState(undefined); useEffect(() => { client.registerWebsocket().then((url) => setWebsocketUrl(url)) }, [client]); let router = createBrowserRouter([ { path: "/", element: }, { path: "/gm", element: websocketUrl ? :
}, { path: "/admin", element: }, { path: "/candela", element: }, { path: "/design", element: } ]); return (
); } export default App;