RoundSummary.jsx 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. import React, { useRef } from "react";
  2. import styled from "styled-components";
  3. import useMap from "../../../hooks/useMap";
  4. import useMarkedPoints from "./useMarkedPoints";
  5. import RoundInfoPane from "./RoundInfoPane";
  6. import useObservable from "../../../hooks/useObservable";
  7. import { gameIdStore, playerNameStore } from "../../../domain/store";
  8. const Container = styled.div`
  9. flex: 1;
  10. display: flex;
  11. flex-flow: column nowrap;
  12. justify-content: space-around;
  13. align-items: center;
  14. @media only screen and (min-width: 600px) {
  15. flex-flow: row nowrap;
  16. }
  17. `
  18. const MapDiv = styled.div`
  19. height: 50%;
  20. width: 100%;
  21. @media only screen and (min-width: 600px) {
  22. width: 50%;
  23. }
  24. `
  25. export default ({ round, onNext }) => {
  26. const gameId = useObservable(gameIdStore);
  27. const playerName = useObservable(playerNameStore);
  28. const {
  29. roundNum,
  30. selectedPoint,
  31. targetPoint,
  32. score,
  33. totalScore,
  34. } = round;
  35. const mapDivRef = useRef(null);
  36. // TODO dynamically determine this zoom level?
  37. const mapRef = useMap(mapDivRef, targetPoint.lat, targetPoint.lng, 4);
  38. useMarkedPoints(mapRef, selectedPoint, targetPoint);
  39. return (
  40. <Container>
  41. <MapDiv ref={mapDivRef} />
  42. <RoundInfoPane {...{ gameId, playerName, selectedPoint, targetPoint, roundNum, score, totalScore, onNext }}/>
  43. </Container>
  44. );
  45. };