Skip to content

Commit

Permalink
2nd step: Add game history.
Browse files Browse the repository at this point in the history
  • Loading branch information
Mrcel97 committed Aug 22, 2018
1 parent 5755e5e commit 5695711
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,15 @@ class Game extends React.Component {
this.current = this.history[this.history.length-1];
this.winner = calculateWinner(this.current.squares); // Due Game Component now have the squares state this Component will calculateWinner.

const moves = this.history.map((step, move) => {
const desc = move ? 'Go to move #' + move : 'Go to game start';
return (
<li>
<button onClick={() => this.jumpTo(move)}>{desc}</button>
</li>
);
});

let status;
if (this.winner) {
status = 'Winner: ' + this.winner;
Expand All @@ -55,6 +64,7 @@ class Game extends React.Component {
</div>
<div className="game-info">
<div>{status}</div>
<ol>{moves}</ol>
</div>
</div>
);
Expand Down

1 comment on commit 5695711

@Mrcel97
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code at this point generate a dynamic list console error. This will be solved on 4th step.

Please sign in to comment.