Skip to content

Commit 6ecb57d

Browse files
author
Roman Babaev
committed
Adjust zoom wrap size on arena change
1 parent 32dd6d9 commit 6ecb57d

File tree

3 files changed

+15
-7
lines changed

3 files changed

+15
-7
lines changed

src/App/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ export default class App extends React.Component {
3737

3838
handleZoomChange = zoom => zoom && this.setState({ zoom });
3939

40-
newGame = (arena = [10, 10], mines = 25) => this.game.configure(arena, mines);
40+
newGame = (arena, mines) => this.game.configure(arena, mines);
4141

4242
render() {
4343
const {
@@ -62,7 +62,7 @@ export default class App extends React.Component {
6262
/>
6363
<Arena
6464
gameState={gameState}
65-
size={arena}
65+
arena={arena}
6666
cells={this.game.getCells()}
6767
onCellOpen={this.game.handleCellClick}
6868
onCellFlag={this.game.flagCell}

src/Arena/index.js

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,10 @@ export class Arena extends React.PureComponent {
2626
}
2727

2828
componentDidUpdate(prevProps) {
29-
if (prevProps.zoom !== this.props.zoom) {
29+
if (
30+
prevProps.arena !== this.props.arena
31+
|| prevProps.zoom !== this.props.zoom
32+
) {
3033
const innerElement = this.innerRef && this.innerRef.current;
3134

3235
if (innerElement) {
@@ -39,7 +42,7 @@ export class Arena extends React.PureComponent {
3942
render() {
4043
const {
4144
cells = [],
42-
size,
45+
arena,
4346
onCellFlag,
4447
onCellOpen,
4548
gameState,
@@ -62,8 +65,8 @@ export class Arena extends React.PureComponent {
6265
<div
6366
className={b('inner')}
6467
style={{
65-
width: size[0] * cellSize,
66-
height: size[1] * cellSize,
68+
width: arena[0] * cellSize,
69+
height: arena[1] * cellSize,
6770
transform: `scale(${zoom})`
6871
}}
6972
ref={this.innerRef}

src/ArenaCell/index.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
import React, { memo, useState } from "react";
22
import b_ from "b_";
3-
import { getCellNeighborMines, CELL_FLAGGED, CELL_OPENED, CELL_MINED } from '../core/helpers';
3+
import {
4+
getCellNeighborMines,
5+
CELL_FLAGGED,
6+
CELL_OPENED,
7+
CELL_MINED
8+
} from '../core/helpers';
49
import "./styles.css";
510

611
const b = b_.lock("ArenaCell");

0 commit comments

Comments
 (0)