airboardgame/src/App.js

67 lines
1.4 KiB
JavaScript
Raw Normal View History

import React from 'react';
import './App.css';
2020-06-08 20:32:24 +02:00
import {
BrowserRouter as Router,
Route,
Switch,
Redirect,
} from 'react-router-dom';
2020-06-05 22:58:53 +02:00
2020-06-08 20:32:24 +02:00
import { Provider } from '@scripters/use-socket.io';
2020-06-05 22:58:53 +02:00
import { RecoilRoot } from 'recoil';
2020-06-08 20:32:24 +02:00
import { nanoid } from 'nanoid';
import { useParams } from 'react-router-dom';
import { C2CProvider } from './hooks/useC2C';
import BoardView from './views/BoardView';
2020-06-05 22:58:53 +02:00
2020-06-07 21:03:54 +02:00
const SOCKET_URL = process.env.REACT_APP_SOCKET_URL || 'http://localhost:4000';
2020-06-07 21:54:10 +02:00
const SOCKET_PATH = process.env.REACT_APP_SOCKET_PATH || '/socket.io';
2020-06-05 22:58:53 +02:00
const SOCKET_OPTIONS = {
forceNew: true,
2020-06-07 21:54:10 +02:00
path: SOCKET_PATH,
2020-06-05 22:58:53 +02:00
};
const room = 'test';
2020-06-08 20:32:24 +02:00
const genRoomName = () => {
return nanoid();
};
export const ConnectedBoardView = () => {
const { room } = useParams();
return (
<C2CProvider room={room}>
<BoardView />
</C2CProvider>
);
};
function App() {
return (
2020-06-05 22:58:53 +02:00
<RecoilRoot>
<Provider url={SOCKET_URL} options={SOCKET_OPTIONS}>
2020-06-08 20:32:24 +02:00
<div className='App'>
<Router>
<Switch>
<Route path='/room/:room/'>
<ConnectedBoardView />
</Route>
<Redirect path='/room/' to={`/room/${genRoomName()}`} />
{/*<Route exact path='/home'>
<HomePage />
</Route>*/}
<Redirect from='/' to='/room/' />
</Switch>
</Router>
</div>
2020-06-05 22:58:53 +02:00
</Provider>
</RecoilRoot>
);
}
export default App;