2024-11-19 01:35:35 +00:00
|
|
|
import React, { useEffect, useState } from 'react';
|
2024-11-12 04:13:52 +00:00
|
|
|
import './App.css';
|
2024-11-19 13:53:04 +00:00
|
|
|
import { TabletopElement } from './components/Tabletop/Tabletop';
|
2024-11-12 04:13:52 +00:00
|
|
|
import { Client } from './client';
|
2024-11-19 01:35:35 +00:00
|
|
|
import { createBrowserRouter, RouterProvider } from 'react-router-dom';
|
|
|
|
import { GmPlayingFieldComponent } from './components/GmPlayingField/GmPlayingField';
|
2024-11-19 05:09:48 +00:00
|
|
|
import { WebsocketProvider } from './components/WebsocketProvider';
|
2024-11-12 04:13:52 +00:00
|
|
|
|
2024-11-19 01:52:04 +00:00
|
|
|
interface AppProps {
|
|
|
|
client: Client;
|
|
|
|
}
|
|
|
|
|
|
|
|
const App = ({ client }: AppProps) => {
|
2024-11-19 01:35:35 +00:00
|
|
|
console.log("rendering app");
|
|
|
|
const [websocketUrl, setWebsocketUrl] = useState<string | undefined>(undefined);
|
|
|
|
|
|
|
|
useEffect(() => {
|
2024-11-19 01:52:04 +00:00
|
|
|
client.registerWebsocket().then((url) => setWebsocketUrl(url))
|
2024-11-19 01:35:35 +00:00
|
|
|
}, [client]);
|
|
|
|
|
|
|
|
let router =
|
|
|
|
createBrowserRouter([
|
|
|
|
{
|
|
|
|
path: "/gm",
|
|
|
|
element: <GmPlayingFieldComponent client={client} />
|
|
|
|
},
|
|
|
|
{
|
|
|
|
path: "/",
|
2024-11-19 13:53:04 +00:00
|
|
|
element: websocketUrl ? <WebsocketProvider websocketUrl={websocketUrl}> <TabletopElement client={client} /> </WebsocketProvider> : <div> </div>
|
2024-11-19 01:35:35 +00:00
|
|
|
}
|
|
|
|
]);
|
2024-11-12 04:13:52 +00:00
|
|
|
return (
|
|
|
|
<div className="App">
|
2024-11-19 01:35:35 +00:00
|
|
|
<RouterProvider router={router} />
|
2024-11-12 04:13:52 +00:00
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
export default App;
|