1import querystring from 'querystring';
2import * as React from 'react';
3
4import { ServerTimeProvider } from './hooks/useServerTime';
5import { Game, GameProps } from './pages/game';
6import { Login } from './pages/login';
7import { StaticView } from './pages/staticView';
8
9export const App = (_props: {}) => {
10 const [gameProps, setGameProps] = React.useState<GameProps | undefined>();
11
12 if (process.env.NODE_ENV === 'development') {
13 const query = querystring.parse(window.location.search.substring(1));
14 if (query.static !== undefined) {
15 return <StaticView />;
16 }
17 }
18
19 if (gameProps) {
20 return (
21 <ServerTimeProvider>
22 <Game {...gameProps} />
23 </ServerTimeProvider>
24 );
25 }
26
27 return (
28 <Login
29 onLogin={(roomID, nickname) => setGameProps({ roomID, nickname, leave: () => setGameProps(undefined) })}
30 />
31 );
32};