|
@@ -1,4 +1,5 @@
|
|
|
-import React from 'react';
|
|
|
+import React, { useState } from 'react';
|
|
|
+import { CSSTransition } from 'react-transition-group';
|
|
|
import styles from './App.module.css';
|
|
|
import GamePanel from './components/screens/GamePanel';
|
|
|
import HomePage from './components/screens/HomePage';
|
|
@@ -10,15 +11,6 @@ import { ERROR, IN_ROUND, POST_GAME, POST_ROUND, PRE_GAME, PRE_ROUND } from './d
|
|
|
import { useGameState } from './domain/gameStore';
|
|
|
import useDirectGameLinks from './hooks/useDirectGameLinks';
|
|
|
|
|
|
-const screenMap = {
|
|
|
- [PRE_GAME]: HomePage,
|
|
|
- [PRE_ROUND]: Lobby,
|
|
|
- [IN_ROUND]: GamePanel,
|
|
|
- [POST_ROUND]: RoundSummary,
|
|
|
- [POST_GAME]: PlayerScores,
|
|
|
- [ERROR]: () => <p>Application encountered unrecoverable error, please refresh the page.</p>
|
|
|
-};
|
|
|
-
|
|
|
const needsHeaderFooter = {
|
|
|
[PRE_GAME]: true,
|
|
|
[PRE_ROUND]: true,
|
|
@@ -28,26 +20,61 @@ const needsHeaderFooter = {
|
|
|
[ERROR]: true
|
|
|
};
|
|
|
|
|
|
+const Header = () => (
|
|
|
+ <div className={styles.header}>
|
|
|
+ <p>TerrAssumptions!</p>
|
|
|
+ </div>
|
|
|
+)
|
|
|
+
|
|
|
+const Footer = () => (
|
|
|
+ <div className={styles.footer}>
|
|
|
+ <ApiInfo />
|
|
|
+ </div>
|
|
|
+)
|
|
|
+
|
|
|
+const State = ({ show, children, onEnter, onExited }) => (
|
|
|
+ <CSSTransition
|
|
|
+ in={show}
|
|
|
+ timeout={1000}
|
|
|
+ mountOnEnter
|
|
|
+ unmountOnExit
|
|
|
+ classNames="state"
|
|
|
+ onEnter={onEnter}
|
|
|
+ onExited={onExited}
|
|
|
+ >
|
|
|
+ <div className="state">
|
|
|
+ {children}
|
|
|
+ </div>
|
|
|
+ </CSSTransition>
|
|
|
+)
|
|
|
+
|
|
|
export default () => {
|
|
|
+ const [st, setSt] = useState(true);
|
|
|
const gameState = useGameState();
|
|
|
useDirectGameLinks();
|
|
|
- const Screen = screenMap[gameState];
|
|
|
const needsHF = needsHeaderFooter[gameState];
|
|
|
|
|
|
return (
|
|
|
<React.StrictMode>
|
|
|
<div className={styles.page}>
|
|
|
- {needsHF && (
|
|
|
- <div className={styles.header}>
|
|
|
- <p>TerrAssumptions!</p>
|
|
|
- </div>
|
|
|
- )}
|
|
|
- <Screen />
|
|
|
- {needsHF && (
|
|
|
- <div className={styles.footer}>
|
|
|
- <ApiInfo />
|
|
|
- </div>
|
|
|
- )}
|
|
|
+ {needsHF && <Header />}
|
|
|
+ <State show={gameState === PRE_GAME} onExited={() => setSt(false)}>
|
|
|
+ <HomePage />
|
|
|
+ </State>
|
|
|
+ <State show={gameState === PRE_ROUND} onExited={() => setSt(false)}>
|
|
|
+ <Lobby />
|
|
|
+ </State>
|
|
|
+ {!st && gameState === IN_ROUND && <GamePanel />}
|
|
|
+ <State show={gameState === POST_ROUND} onEnter={() => setSt(true)} onExited={() => setSt(false)}>
|
|
|
+ <RoundSummary />
|
|
|
+ </State>
|
|
|
+ <State show={gameState === POST_GAME}>
|
|
|
+ <PlayerScores />
|
|
|
+ </State>
|
|
|
+ <State show={gameState === ERROR}>
|
|
|
+ <p>Application encountered unrecoverable error, please refresh the page.</p>
|
|
|
+ </State>
|
|
|
+ {needsHF && <Footer />}
|
|
|
</div>
|
|
|
</React.StrictMode>
|
|
|
);
|