|
@@ -1,38 +1,8 @@
|
|
|
-import React, { useRef, useEffect } from "react";
|
|
|
-import styled from "styled-components";
|
|
|
-import usePano from "./usePano";
|
|
|
-import { useTargetPoint, usePanoStartPosition, usePanoStartPov } from "../../../domain/gameStore";
|
|
|
-import { savePanoPositionToLocalStorage, savePanoPovToLocalStorage } from "../../../domain/localStorageMethods";
|
|
|
-
|
|
|
-const Container = styled.div`
|
|
|
- position: relative;
|
|
|
- height: 100%;
|
|
|
- width: 100%;
|
|
|
-`
|
|
|
-
|
|
|
-const Pano = styled.div`
|
|
|
- height: 100%;
|
|
|
- width: 100%;
|
|
|
-`
|
|
|
-
|
|
|
-const ResetButton = styled.div`
|
|
|
- /* TODO improve this to be less brittle */
|
|
|
- display: block;
|
|
|
- position: absolute;
|
|
|
- z-index: 1;
|
|
|
- bottom: 200px;
|
|
|
- right: 9px;
|
|
|
- background-color: #222;
|
|
|
- color: #666;
|
|
|
- padding: 5px;
|
|
|
- border-radius: 2px;
|
|
|
- font-weight: bold;
|
|
|
- cursor: pointer;
|
|
|
-
|
|
|
- &:hover {
|
|
|
- color: #b1b1b1;
|
|
|
- }
|
|
|
-`
|
|
|
+import React, { useEffect, useRef } from 'react';
|
|
|
+import { usePanoStartPosition, usePanoStartPov, useTargetPoint } from '../../../domain/gameStore';
|
|
|
+import { savePanoPositionToLocalStorage, savePanoPovToLocalStorage } from '../../../domain/localStorageMethods';
|
|
|
+import styles from './GamePanel.module.css';
|
|
|
+import usePano from './usePano';
|
|
|
|
|
|
export default () => {
|
|
|
const startPosition = usePanoStartPosition();
|
|
@@ -40,25 +10,28 @@ export default () => {
|
|
|
const resetPosition = useTargetPoint();
|
|
|
const panoDivRef = useRef(null);
|
|
|
const panoRef = usePano(panoDivRef, startPosition, startPov);
|
|
|
- useEffect(() => {
|
|
|
- if (panoRef.current) {
|
|
|
- panoRef.current.addListener("position_changed", () => {
|
|
|
- const { lat, lng } = panoRef.current.getPosition();
|
|
|
- savePanoPositionToLocalStorage(lat(), lng());
|
|
|
- });
|
|
|
- panoRef.current.addListener("pov_changed", () => {
|
|
|
- const { heading, pitch } = panoRef.current.getPov();
|
|
|
- savePanoPovToLocalStorage(heading, pitch);
|
|
|
- });
|
|
|
- }
|
|
|
- }, [panoRef]);
|
|
|
+ useEffect(
|
|
|
+ () => {
|
|
|
+ if (panoRef.current) {
|
|
|
+ panoRef.current.addListener('position_changed', () => {
|
|
|
+ const { lat, lng } = panoRef.current.getPosition();
|
|
|
+ savePanoPositionToLocalStorage(lat(), lng());
|
|
|
+ });
|
|
|
+ panoRef.current.addListener('pov_changed', () => {
|
|
|
+ const { heading, pitch } = panoRef.current.getPov();
|
|
|
+ savePanoPovToLocalStorage(heading, pitch);
|
|
|
+ });
|
|
|
+ }
|
|
|
+ },
|
|
|
+ [ panoRef ]
|
|
|
+ );
|
|
|
|
|
|
return (
|
|
|
- <Container>
|
|
|
- <Pano ref={panoDivRef}/>
|
|
|
- <ResetButton onClick={() => panoRef.current.setPosition(resetPosition)}>
|
|
|
+ <>
|
|
|
+ <div className={styles.fullsize} ref={panoDivRef} />
|
|
|
+ <div className={styles.resetButton} onClick={() => panoRef.current.setPosition(resetPosition)}>
|
|
|
Reset
|
|
|
- </ResetButton>
|
|
|
- </Container>
|
|
|
+ </div>
|
|
|
+ </>
|
|
|
);
|
|
|
};
|