2024-11-19 01:35:35 +00:00
|
|
|
import React, { useEffect, useState } from 'react';
|
2024-11-12 04:13:52 +00:00
|
|
|
import logo from './logo.svg';
|
|
|
|
import './App.css';
|
2024-11-19 01:35:35 +00:00
|
|
|
import { WebsocketPlayingFieldComponent } from './components/PlayingField/PlayingField';
|
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-12 04:13:52 +00:00
|
|
|
|
|
|
|
const App = () => {
|
2024-11-19 01:35:35 +00:00
|
|
|
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>
|
|
|
|
}
|
|
|
|
]);
|
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;
|