HomePage.jsx 1.4 KB

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