monorepo/visions/ui/src/App.tsx

37 lines
1.1 KiB
TypeScript
Raw Normal View History

import React, { useEffect, useState } from 'react';
import logo from './logo.svg';
import './App.css';
import { WebsocketPlayingFieldComponent } from './components/PlayingField/PlayingField';
import { Client } from './client';
import { createBrowserRouter, RouterProvider } from 'react-router-dom';
import { GmPlayingFieldComponent } from './components/GmPlayingField/GmPlayingField';
const App = () => {
console.log("rendering app");
const client = new Client();
const [websocketUrl, setWebsocketUrl] = useState<string | undefined>(undefined);
useEffect(() => {
client.registerWebsocket().then((url) => setWebsocketUrl(url));
}, [client]);
let router =
createBrowserRouter([
{
path: "/gm",
element: <GmPlayingFieldComponent client={client} />
},
{
path: "/",
element: websocketUrl ? <WebsocketPlayingFieldComponent websocketUrl={websocketUrl} /> : <div> </div>
}
]);
return (
<div className="App">
<RouterProvider router={router} />
</div>
);
}
export default App;