HomePage.jsx 1.3 KB

1234567891011121314151617181920212223242526272829303132333435
  1. import { useState, useEffect, useRef, forwardRef } from 'react';
  2. import { dispatch } from '../../../domain/gameStore';
  3. import { hasSavedGameInfo } from '../../../domain/localStorageMethods';
  4. import DelayedButton from '../../util/DelayedButton';
  5. import GameCreationForm from '../../util/GameCreationForm';
  6. import styles from './HomePage.module.css';
  7. import { CSSTransition } from 'react-transition-group';
  8. const Rejoin = forwardRef((_, ref) => (
  9. <div className={styles.rejoinSection} ref={ref}>
  10. <span className={styles.rejoinLabel}>Looks like you were in a game before that you didn't finish!</span>
  11. <DelayedButton onEnd={() => dispatch.rejoinGame()} countDownFormatter={(rem) => `Rejoining in ${rem}s...`}>
  12. Rejoin Game?
  13. </DelayedButton>
  14. </div>
  15. ));
  16. const HomePage = () => {
  17. const [hasSavedInfo, setHasSavedInfo] = useState(false);
  18. useEffect(() => {
  19. hasSavedGameInfo().then(setHasSavedInfo)
  20. }, []);
  21. const transitionRef = useRef(null);
  22. return (
  23. <div className={styles.page}>
  24. <CSSTransition nodeRef={transitionRef} in={hasSavedInfo} mountOnEnter unmountOnExit timeout={500} classNames="fade">
  25. <Rejoin ref={transitionRef}/>
  26. </CSSTransition>
  27. <GameCreationForm afterCreate={(gameId) => dispatch.goToLobby(gameId)} />
  28. </div>
  29. );
  30. };
  31. export default HomePage;