RoundSummary.jsx 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. import React, { useRef } from "react";
  2. import styled from "styled-components";
  3. import { useLastRound, dispatch } from "../../../domain/gameStore";
  4. import useRoundInfo from "../../../hooks/useRoundInfo";
  5. import DelayedButton from "../../util/DelayedButton";
  6. import Button from "../../util/Button";
  7. import useMapWithMarkers from "./useMapWithMarkers";
  8. const SummaryDiv = styled.div`
  9. position: absolute;
  10. display: flex;
  11. flex-flow: column nowrap;
  12. background-color: #333;
  13. z-index: 1;
  14. bottom: 16px;
  15. right: 8px;
  16. padding: 8px;
  17. `
  18. const ScoreSpan = styled.span`
  19. padding-bottom: 2px;
  20. `;
  21. const MapDiv = styled.div`
  22. position: absolute;
  23. height: 100%;
  24. width: 100%;
  25. `
  26. const FinishedButton = styled(Button)`
  27. margin-top: 5px;
  28. padding: 1em;
  29. `
  30. const NextButton = styled(DelayedButton)`
  31. margin-top: 5px;
  32. padding: 1em;
  33. `
  34. export default () => {
  35. // get the info about the last round
  36. const { roundNum, score, totalScore } = useLastRound();
  37. // draw the map
  38. const mapDivRef = useRef(null);
  39. useMapWithMarkers(mapDivRef);
  40. // whether or not the game is done
  41. const [gameFinished] = useRoundInfo();
  42. return (
  43. <div>
  44. <MapDiv ref={mapDivRef} />
  45. <SummaryDiv>
  46. <ScoreSpan>Score for Round {roundNum}: {score}</ScoreSpan>
  47. <ScoreSpan>Running Total: {totalScore}</ScoreSpan>
  48. {
  49. gameFinished
  50. ? <FinishedButton onClick={dispatch.startRound}>
  51. View Summary
  52. </FinishedButton>
  53. : <NextButton onEnd={dispatch.startRound} countDownFormatter={rem => `Click to cancel, ${rem}s...`}>
  54. Next Round
  55. </NextButton>
  56. }
  57. </SummaryDiv>
  58. </div>
  59. );
  60. };