From a938c8ab7beea3738ecfe3485f6fbdcb9f53d68a Mon Sep 17 00:00:00 2001 From: Bharat Singh <10626464+Bharat1103@users.noreply.github.com> Date: Tue, 25 Sep 2018 14:52:07 +0530 Subject: [PATCH] #001: Added Scoreboard and Scorer initial implementation. Co-authored-by: Sravya Kanagarla --- src/scorer/Scoreboard.jsx | 88 ++++++++++++++++++++++++++------------- src/scorer/Scorer.jsx | 54 ++++++++++++++++++++---- 2 files changed, 105 insertions(+), 37 deletions(-) diff --git a/src/scorer/Scoreboard.jsx b/src/scorer/Scoreboard.jsx index c40360a..ecd99e9 100644 --- a/src/scorer/Scoreboard.jsx +++ b/src/scorer/Scoreboard.jsx @@ -1,36 +1,64 @@ -import React from 'react'; -import {Container,Row,Col} from 'reactstrap'; +import React, { Component } from 'react'; +import PropTypes from 'prop-types'; +import { Container, Row, Col } from 'reactstrap'; +class ScoreBoard extends Component { + renderPreviousTeamScoreDetails() { + return ( + + + + +

+ {this.props.previousInning.bowlingCard.name} scored + {this.props.previousInning.runsScored}/ + {this.props.previousInning.wicketsFallen} in + {this.props.previousInning.oversBowled} +

+ +
+ +
+ ); + } -const ScoreBoard = () => - -
- - + render() { + return ( + +
- - Team 1 - - - - 120/5 in 12.1/20 - - - -
-
- - - - - Team 2 scored - - - 120/5 in 12.1/20 + + + + {this.props.currentInning.battingCard.name} + + + + + {this.props.currentInning.runsScored}/ + {this.props.currentInning.wicketsFallen} in + {this.props.currentInning.oversBowled}. + {this.props.currentInning.validBallsInCurrentOver}/{this.props.totalOvers} + + + - - -
; +
+ {!(this.props.isFirstInning) ? + this.renderPreviousTeamScoreDetails() : + null + } + + ); + } +} + +ScoreBoard.propTypes = { + isFirstInning: PropTypes.bool.isRequired, + previousInning: PropTypes.instanceOf(Object).isRequired, + currentInning: PropTypes.instanceOf(Object).isRequired, + totalOvers: PropTypes.number.isRequired, +}; -export default ScoreBoard; \ No newline at end of file +export default ScoreBoard; diff --git a/src/scorer/Scorer.jsx b/src/scorer/Scorer.jsx index 30195ff..cdf257e 100644 --- a/src/scorer/Scorer.jsx +++ b/src/scorer/Scorer.jsx @@ -1,11 +1,51 @@ -import React from 'react'; +import React, { Component } from 'react'; +import { connect } from 'react-redux'; +import PropTypes from 'prop-types'; import ScoreBoard from './Scoreboard'; -const Scorer = () => ( -
- +class Scorer extends Component { + renderBasedOnCurrentInning() { + if (this.props.isFirstInning) { + return ( + ); + } + return ( + ); + } -
-); + render() { + return ( +
+ {this.renderBasedOnCurrentInning()} +
); + } +} -export default Scorer; \ No newline at end of file +Scorer.propTypes = { + isFirstInning: PropTypes.bool.isRequired, + firstInning: PropTypes.instanceOf(Object).isRequired, + secondInning: PropTypes.instanceOf(Object).isRequired, + totalOvers: PropTypes.number.isRequired, +}; + +const mapStateToProps = state => ({ + isFirstInning: state.gameInformation.isFirstInning, + firstInning: state.gameInformation.firstInning, + secondInning: state.gameInformation.secondInning, + totalOvers: state.gameInformation.totalOvers, +}); + + +const connectedScorerComponent = connect(mapStateToProps)(Scorer); + +export default connectedScorerComponent;