|
@@ -1,25 +1,64 @@
|
|
-import React, { useRef, useEffect } from "react";
|
|
|
|
|
|
+import React, { useRef, useEffect, useState } from "react";
|
|
import styled from "styled-components";
|
|
import styled from "styled-components";
|
|
import useMap from '../../../hooks/useMap';
|
|
import useMap from '../../../hooks/useMap';
|
|
import useMarkersFromGuesses from '../../../hooks/useMarkersFromGuesses';
|
|
import useMarkersFromGuesses from '../../../hooks/useMarkersFromGuesses';
|
|
|
|
|
|
|
|
+const RoundSelectContainer = styled.div`
|
|
|
|
+ /* background-color: #444; */
|
|
|
|
+ height: 100%;
|
|
|
|
+ display: flex;
|
|
|
|
+ flex-flow: column wrap;
|
|
|
|
+ justify-content: flex-start;
|
|
|
|
+ align-items: center;
|
|
|
|
+ align-content: flex-start;
|
|
|
|
+`;
|
|
|
|
+
|
|
|
|
+const RoundSelectButton = styled.div`
|
|
|
|
+ background-color: ${({active}) => active ? "#777" : "#555"};
|
|
|
|
+ height: 2em;
|
|
|
|
+ width: 2em;
|
|
|
|
+ margin-top: 1px;
|
|
|
|
+ margin-bottom: 2px;
|
|
|
|
+ border-radius: 0% 20% 20% 0%;
|
|
|
|
+ cursor: pointer;
|
|
|
|
+ display: flex;
|
|
|
|
+ justify-content: center;
|
|
|
|
+ align-items: center;
|
|
|
|
+`;
|
|
|
|
+
|
|
|
|
+const ResetRoundSelectButton = styled(RoundSelectButton).attrs({
|
|
|
|
+ active: false,
|
|
|
|
+})`
|
|
|
|
+ margin-top: auto;
|
|
|
|
+ margin-bottom: 0px;
|
|
|
|
+`;
|
|
|
|
+
|
|
const MapDiv = styled.div`
|
|
const MapDiv = styled.div`
|
|
- position: absolute;
|
|
|
|
- height: 30%;
|
|
|
|
- width: 90%;
|
|
|
|
|
|
+ height: 100%;
|
|
|
|
+ width: 60vw;
|
|
|
|
+ border: #555 solid 2px;
|
|
`;
|
|
`;
|
|
|
|
|
|
const MapContainer = styled.div`
|
|
const MapContainer = styled.div`
|
|
- height: 100%;
|
|
|
|
|
|
+ height: 350px;
|
|
|
|
+ padding: 2px;
|
|
display: flex;
|
|
display: flex;
|
|
justify-content: center;
|
|
justify-content: center;
|
|
|
|
+ align-items: center;
|
|
`;
|
|
`;
|
|
|
|
|
|
-export default ({ players, coords, roundActive }) => {
|
|
|
|
|
|
+export default ({ players, coords }) => {
|
|
|
|
+ const rounds = Object.keys(coords).length;
|
|
|
|
+ const singleRound = rounds === 1;
|
|
|
|
+
|
|
// create the map
|
|
// create the map
|
|
const mapDivRef = useRef(null);
|
|
const mapDivRef = useRef(null);
|
|
const mapRef = useMap(mapDivRef, 0, 0, 1);
|
|
const mapRef = useMap(mapDivRef, 0, 0, 1);
|
|
|
|
|
|
|
|
+ // set up round number selection
|
|
|
|
+ const [roundNum, setRoundNum] = useState("0");
|
|
|
|
+ const roundActive = singleRound ? "1" : roundNum;
|
|
|
|
+
|
|
// get the target point
|
|
// get the target point
|
|
const targetPoint = coords?.[roundActive] ?? null;
|
|
const targetPoint = coords?.[roundActive] ?? null;
|
|
|
|
|
|
@@ -28,14 +67,27 @@ export default ({ players, coords, roundActive }) => {
|
|
|
|
|
|
// scroll the map to the target point
|
|
// scroll the map to the target point
|
|
useEffect(() => {
|
|
useEffect(() => {
|
|
- if (targetPoint && mapRef.current) {
|
|
|
|
- mapRef.current.panTo(targetPoint);
|
|
|
|
- }
|
|
|
|
|
|
+ mapRef.current && mapRef.current.panTo(targetPoint ?? { lat: 0, lng: 0 });
|
|
}, [mapRef, targetPoint]);
|
|
}, [mapRef, targetPoint]);
|
|
|
|
|
|
|
|
+ const roundSelect = singleRound
|
|
|
|
+ ? null
|
|
|
|
+ : (
|
|
|
|
+ <RoundSelectContainer>
|
|
|
|
+ {
|
|
|
|
+ // fun fact: es6 doesn't have a range(x) function
|
|
|
|
+ Array.from(Array(rounds).keys())
|
|
|
|
+ .map(r => (r + 1).toString())
|
|
|
|
+ .map(r => <RoundSelectButton active={r === roundNum} key={r} onClick={() => setRoundNum(r)}>{r}</RoundSelectButton>)
|
|
|
|
+ }
|
|
|
|
+ <ResetRoundSelectButton onClick={() => setRoundNum("0")}>X</ResetRoundSelectButton>
|
|
|
|
+ </RoundSelectContainer>
|
|
|
|
+ )
|
|
|
|
+
|
|
return (
|
|
return (
|
|
<MapContainer>
|
|
<MapContainer>
|
|
<MapDiv ref={mapDivRef}/>
|
|
<MapDiv ref={mapDivRef}/>
|
|
|
|
+ { roundSelect }
|
|
</MapContainer>
|
|
</MapContainer>
|
|
);
|
|
);
|
|
}
|
|
}
|