From c4a1f9cf3cd589be0262a3a0bea42e8e76a64f0b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=ADctor=20Molero?= Date: Tue, 6 Mar 2018 23:12:28 +0100 Subject: [PATCH 1/6] fix some small bits --- src/components/DealComponent.tsx | 2 -- src/{ => components}/SimpleBlackJack.tsx | 2 +- src/css/enhanced.css | 4 ++-- src/index.tsx | 2 +- src/tests/SimpleBlackJack.test.tsx | 2 +- 5 files changed, 5 insertions(+), 7 deletions(-) rename src/{ => components}/SimpleBlackJack.tsx (90%) diff --git a/src/components/DealComponent.tsx b/src/components/DealComponent.tsx index ffae083..41d4064 100644 --- a/src/components/DealComponent.tsx +++ b/src/components/DealComponent.tsx @@ -14,10 +14,8 @@ interface DealPropsInterface { export default class DealComponent extends React.Component { public render() { let board: Board = this.props.board; - let gameOver: string = board.isGameOver() ? 'Deal Over' : 'Deal On'; return (
-
{gameOver}
{board.getPlayerScore()} { const div = document.createElement('div'); From 182f80f40f43da8728114b20175da4898cd83517 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=ADctor=20Molero?= Date: Wed, 7 Mar 2018 15:59:50 +0100 Subject: [PATCH 2/6] add save button handler --- src/components/BoardComponent.tsx | 31 ++++++++++++++++++++++++++---- src/components/SimpleBlackJack.tsx | 27 ++++++++++++++++++++++++-- 2 files changed, 52 insertions(+), 6 deletions(-) diff --git a/src/components/BoardComponent.tsx b/src/components/BoardComponent.tsx index 9e975e0..992996b 100644 --- a/src/components/BoardComponent.tsx +++ b/src/components/BoardComponent.tsx @@ -11,12 +11,25 @@ interface BoardStateInterface { btnPlayerClass: string; } -export default class BoardComponent extends React.Component<{}, BoardStateInterface> { +interface BoardPropsInterface { + board: string; + onSaveBoardClick: Function; +} + +export default class BoardComponent extends React.Component { - constructor(props: {}) { + constructor(props: BoardPropsInterface) { super(props); + let board: Board = Board.newGame(); + if (this.props.board.length > 0) { + try { + board = JSON.parse(this.props.board); + } catch (invalidJson) { + alert('Cannot parse Board json'); + } + } this.state = { - board: Board.newGame(), + board: board, handNumber: 0, playerScore: 0, houseScore: 0, @@ -52,12 +65,22 @@ export default class BoardComponent extends React.Component<{}, BoardStateInterf this.setNewState(newState); } + public handleSaveBoard() { + let jsonBoard: string = JSON.stringify(this.state.board); + return this.props.onSaveBoardClick(jsonBoard); + } + public render() { return (