11import React from "react" ;
22import { Arena } from "../Arena" ;
3+ import { FooterPanel } from "../FooterPanel" ;
34import { Hat } from "../Hat" ;
45import { Minesweeper } from "../core" ;
56import { Options } from "../Options" ;
67import "./styles.css" ;
78
9+ function preventZoom ( event ) {
10+ event = event . originalEvent || event ;
11+ if ( event . scale !== undefined && event . scale !== 1 ) event . preventDefault ( ) ;
12+ }
13+
814export default class App extends React . Component {
915 constructor ( props ) {
1016 super ( props ) ;
1117 this . state = {
12- showOptions : false
18+ showOptions : false ,
19+ zoom : 1
1320 } ;
1421
1522 this . game = new Minesweeper ( null , null , this . forceUpdate . bind ( this ) ) ;
1623 }
1724
25+ componentDidMount ( ) {
26+ document . addEventListener ( 'touchmove' , preventZoom , { passive : false } ) ;
27+ document . addEventListener ( 'dblclick' , preventZoom , { passive : false } ) ;
28+ }
29+
30+ componentWillUnmount ( ) {
31+ document . removeEventListener ( 'touchmove' , preventZoom , { passive : false } ) ;
32+ document . removeEventListener ( 'dblclick' , preventZoom , { passive : false } ) ;
33+ }
34+
1835 toggleOptions = ( ) =>
1936 this . setState ( ( { showOptions } ) => ( { showOptions : ! showOptions } ) ) ;
2037
38+ handleZoomChange = zoom => zoom && this . setState ( { zoom } ) ;
39+
2140 newGame = ( arena = [ 10 , 10 ] , mines = 25 ) => this . game . configure ( arena , mines ) ;
2241
2342 render ( ) {
2443 const { flaggingMode, gameState, minesCountTotal, arena, flagged, timerValue } = this . game . getStats ( ) ;
25- const { showOptions } = this . state ;
44+ const { showOptions, zoom } = this . state ;
2645
2746 return (
2847 < div className = "App" >
2948 < Hat
30- flaggingMode = { flaggingMode }
3149 gameState = { gameState }
3250 timerValue = { timerValue }
3351 minesLeftCount = { minesCountTotal - flagged }
3452 onResetClick = { this . game . reset }
3553 onOptionsClick = { this . toggleOptions }
36- onFlaggingSwitch = { this . game . toggleFlaggingMode }
3754 />
3855 < Arena
3956 gameState = { gameState }
@@ -42,6 +59,13 @@ export default class App extends React.Component {
4259 onCellOpen = { this . game . handleCellClick }
4360 onCellFlag = { this . game . flagCell }
4461 onResetClick = { this . game . reset }
62+ zoom = { zoom }
63+ />
64+ < FooterPanel
65+ flaggingMode = { flaggingMode }
66+ zoom = { zoom }
67+ onFlaggingSwitch = { this . game . toggleFlaggingMode }
68+ onZoomChange = { this . handleZoomChange }
4569 />
4670 { showOptions && (
4771 < Options
0 commit comments