<commit_before>// @flow

import { connect } from 'react-redux';
import PlayerBox from './PlayerBox.js';

import type { PlayerBoxProps, PlayerBoxOwnProps } from './PlayerBox.js';
import type { State } from '../../model/State.js';

function mapStateToProps(state:State, ownProps:PlayerBoxOwnProps):PlayerBoxProps {
  if (state.players.length <= ownProps.playerIndex) {
    return { disabled: true };
  } else {
    return {
      disabled: false,
      name: state.players[ownProps.playerIndex].name,
      score: 0
    };
  }
}

const PlayerBoxComponent = connect(mapStateToProps)(PlayerBox);

export default PlayerBoxComponent;
<commit_msg>Displaying proper score in player's box.<commit_after>// @flow

import { connect } from 'react-redux';
import PlayerBox from './PlayerBox.js';

import type { PlayerBoxProps, PlayerBoxOwnProps } from './PlayerBox.js';
import type { State, GameState } from '../../model/State.js';

function mapStateToProps(state:State, ownProps:PlayerBoxOwnProps):PlayerBoxProps {
  if (state.players.length <= ownProps.playerIndex) {
    return { disabled: true };
  } else {
    return {
      disabled: false,
      name: state.players[ownProps.playerIndex].name,
      score: getScore(state.gameState, ownProps.playerIndex),
    };
  }
}

function getScore(gameState:?GameState, playerIndex:number):number {
  if (gameState) {
    let playerHand = gameState.playerState[playerIndex].hand;
    return playerHand.factories.reduce((sum, next) => (sum + next.points), 0);
  } else {
    return 0;
  }
}

const PlayerBoxComponent = connect(mapStateToProps)(PlayerBox);

export default PlayerBoxComponent;

{'fraction_non_alphanumeric': 0.13038130381303814, 'fraction_numerical': 0.0018450184501845018, 'mean_word_length': 4.198083067092652, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 4, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3209865', 'n_tokens_mistral': 495, 'n_tokens_neox': 492, 'n_words': 112}