1import querystring from 'querystring';
 2import * as React from 'react';
 3
 4import { ServerTimeProvider } from './hooks';
 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    const leave = React.useCallback(() => setGameProps(undefined), []);
12    const onLogin = React.useCallback((roomID, nickname) => setGameProps({ roomID, nickname, leave }), [leave]);
13
14    if (process.env.NODE_ENV === 'development') {
15        const query = querystring.parse(window.location.search.substring(1));
16        if (query.static !== undefined) {
17            return <StaticView />;
18        }
19    }
20
21    if (gameProps) {
22        return (
23            <ServerTimeProvider>
24                <Game {...gameProps} />
25            </ServerTimeProvider>
26        );
27    }
28
29    return <Login onLogin={onLogin} />;
30};