2020-05-23 21:51:11 +00:00
|
|
|
import querystring from 'querystring';
|
|
|
|
import * as React from 'react';
|
|
|
|
|
2020-05-29 02:03:07 +00:00
|
|
|
import { ServerTimeProvider } from './hooks';
|
2020-05-23 21:51:11 +00:00
|
|
|
import { Game, GameProps } from './pages/game';
|
|
|
|
import { Login } from './pages/login';
|
|
|
|
import { StaticView } from './pages/staticView';
|
|
|
|
|
|
|
|
export const App = (_props: {}) => {
|
|
|
|
const [gameProps, setGameProps] = React.useState<GameProps | undefined>();
|
2020-05-29 02:03:07 +00:00
|
|
|
const leave = React.useCallback(() => setGameProps(undefined), []);
|
|
|
|
const onLogin = React.useCallback((roomID, nickname) => setGameProps({ roomID, nickname, leave }), [leave]);
|
2020-05-23 21:51:11 +00:00
|
|
|
|
|
|
|
if (process.env.NODE_ENV === 'development') {
|
|
|
|
const query = querystring.parse(window.location.search.substring(1));
|
|
|
|
if (query.static !== undefined) {
|
|
|
|
return <StaticView />;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (gameProps) {
|
|
|
|
return (
|
|
|
|
<ServerTimeProvider>
|
|
|
|
<Game {...gameProps} />
|
|
|
|
</ServerTimeProvider>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2020-05-29 02:03:07 +00:00
|
|
|
return <Login onLogin={onLogin} />;
|
2020-05-23 21:51:11 +00:00
|
|
|
};
|