|
@@ -1,9 +1,9 @@
|
|
|
-import React, { useState, useEffect } from 'react';
|
|
|
+import React, { useEffect } from 'react';
|
|
|
import styled from 'styled-components';
|
|
|
import Loading from '../../util/Loading';
|
|
|
import GuessPane from "./GuessPane";
|
|
|
import PositionedStreetView from "./PositionedStreetView";
|
|
|
-import { dispatch, useCurrentRound, useTargetPoint } from '../../../domain/gameStore';
|
|
|
+import { dispatch, useCurrentRound } from '../../../domain/gameStore';
|
|
|
import usePreventNavigation from '../../../hooks/usePreventNavigation';
|
|
|
|
|
|
const Container = styled.div`
|
|
@@ -32,41 +32,23 @@ const StreetViewWrapper = styled.div`
|
|
|
export default () => {
|
|
|
// warn the user if they navigate away
|
|
|
usePreventNavigation();
|
|
|
-
|
|
|
- const [submitDisabled, setSubmitDisabled] = useState(false);
|
|
|
- const [selectedPoint, setSelectedPoint] = useState(null);
|
|
|
const finished = useCurrentRound() === null;
|
|
|
- const targetPoint = useTargetPoint();
|
|
|
useEffect(() => {
|
|
|
if (finished) {
|
|
|
dispatch.goToSummary();
|
|
|
}
|
|
|
}, [finished]);
|
|
|
|
|
|
- if (finished) {
|
|
|
- return <Loading/>
|
|
|
- }
|
|
|
-
|
|
|
- const handleSubmitGuess = async () => {
|
|
|
- setSubmitDisabled(true);
|
|
|
- await dispatch.submitGuess(selectedPoint);
|
|
|
- }
|
|
|
-
|
|
|
- return (
|
|
|
- <Container>
|
|
|
- <StreetViewWrapper>
|
|
|
- <PositionedStreetView
|
|
|
- startPosition={targetPoint}
|
|
|
- resetPosition={targetPoint}
|
|
|
- onPanoMoved={(lat, lng, head, pitch) => console.log(`${lat}, ${lng}, ${head}, ${pitch}`)}
|
|
|
- />
|
|
|
- </StreetViewWrapper>
|
|
|
- <GuessPane
|
|
|
- onTimeout={handleSubmitGuess}
|
|
|
- onSelectPoint={setSelectedPoint}
|
|
|
- onSubmitGuess={handleSubmitGuess}
|
|
|
- submitDisabled={submitDisabled || selectedPoint === null}
|
|
|
- />
|
|
|
- </Container>
|
|
|
- );
|
|
|
+ return finished
|
|
|
+ ? <Loading />
|
|
|
+ : (
|
|
|
+ <Container>
|
|
|
+ <StreetViewWrapper>
|
|
|
+ <PositionedStreetView
|
|
|
+ onPanoMoved={(lat, lng, head, pitch) => console.log(`${lat}, ${lng}, ${head}, ${pitch}`)}
|
|
|
+ />
|
|
|
+ </StreetViewWrapper>
|
|
|
+ <GuessPane />
|
|
|
+ </Container>
|
|
|
+ );
|
|
|
}
|