<commit_before>import * as React from 'react';
import {Content, Header, IconButton, Layout, Menu, MenuItem} from 'react-mdl';

import Game from './Game';
import {PlayerInputs} from '../types';
import Setup from './Setup';

export interface AppState {
  readonly players: string[] | null,
  readonly inputs: {bids: PlayerInputs, tricks: PlayerInputs}[]
};

function getInitialState(): AppState {
  const possiblePlayersString = localStorage.getItem('players');
  const possibleInputsString = localStorage.getItem('inputs');
  const players = (possiblePlayersString !== null && JSON.parse(possiblePlayersString)) || null;
  const inputs = (possibleInputsString !== null && JSON.parse(possibleInputsString)) || [{bids: {}, tricks: {}}];
  return {players, inputs: inputs};
}

export default class extends React.Component<{}, AppState> {
  constructor() {
    super();
    this.state = getInitialState();
  }

  onBeginGame(players: string[]) {
    localStorage.setItem('players', JSON.stringify(players));
    this.setState({players} as AppState);
  }

  onBidsSubmitted(round: number, bids: PlayerInputs) {
    this.setState(prevState => {
      prevState.inputs[round] = prevState.inputs[round] || {bids: {}, tricks: {}};
      prevState.inputs[round].bids = bids;
      return {inputs: prevState.inputs} as AppState;
    }, () => {
      localStorage.setItem('inputs', JSON.stringify(this.state.inputs));
    });
  }

  onNewGame() {
    localStorage.clear();
    this.setState(getInitialState());
  }

  onTricksSubmitted(round: number, tricks: PlayerInputs) {
    this.setState(prevState => {
      prevState.inputs[round] = prevState.inputs[round] || {bids: {}, tricks: {}};
      prevState.inputs[round].tricks = tricks;
      return {inputs: prevState.inputs} as AppState;
    }, () => {
      localStorage.setItem('inputs', JSON.stringify(this.state.inputs));
    });
  }

  render() {
    return (
      <Layout fixedHeader={true}>
        <Header title="Wizard Scorekeeper">
          <IconButton id="menu" name="more_vert" />
          <Menu target="menu" align="right">
            <MenuItem disabled={!this.state.players} onClick={() => this.onNewGame()}>New Game</MenuItem>
          </Menu>
        </Header>
        <Content>
          <div style={{paddingBottom: 30, paddingLeft: 30, paddingRight: 30}}>
            {this.state.players ?
              <Game
                players={this.state.players}
                inputs={this.state.inputs}
                onBidsSubmitted={(round, bids) => this.onBidsSubmitted(round, bids)}
                onNewGame={() => this.onNewGame()}
                onTricksSubmitted={(round, tricks) => this.onTricksSubmitted(round, tricks)} /> :
              <Setup onBeginGame={this.onBeginGame.bind(this)} />
            }
          </div>
        </Content>
      </Layout>
    );<commit_msg>Fix not being able to horizontally scroll<commit_after>import * as React from 'react';
import {Content, Header, IconButton, Layout, Menu, MenuItem} from 'react-mdl';

import Game from './Game';
import {PlayerInputs} from '../types';
import Setup from './Setup';

export interface AppState {
  readonly players: string[] | null,
  readonly inputs: {bids: PlayerInputs, tricks: PlayerInputs}[]
};

function getInitialState(): AppState {
  const possiblePlayersString = localStorage.getItem('players');
  const possibleInputsString = localStorage.getItem('inputs');
  const players = (possiblePlayersString !== null && JSON.parse(possiblePlayersString)) || null;
  const inputs = (possibleInputsString !== null && JSON.parse(possibleInputsString)) || [{bids: {}, tricks: {}}];
  return {players, inputs: inputs};
}

export default class extends React.Component<{}, AppState> {
  constructor() {
    super();
    this.state = getInitialState();
  }

  onBeginGame(players: string[]) {
    localStorage.setItem('players', JSON.stringify(players));
    this.setState({players} as AppState);
  }

  onBidsSubmitted(round: number, bids: PlayerInputs) {
    this.setState(prevState => {
      prevState.inputs[round] = prevState.inputs[round] || {bids: {}, tricks: {}};
      prevState.inputs[round].bids = bids;
      return {inputs: prevState.inputs} as AppState;
    }, () => {
      localStorage.setItem('inputs', JSON.stringify(this.state.inputs));
    });
  }

  onNewGame() {
    localStorage.clear();
    this.setState(getInitialState());
  }

  onTricksSubmitted(round: number, tricks: PlayerInputs) {
    this.setState(prevState => {
      prevState.inputs[round] = prevState.inputs[round] || {bids: {}, tricks: {}};
      prevState.inputs[round].tricks = tricks;
      return {inputs: prevState.inputs} as AppState;
    }, () => {
      localStorage.setItem('inputs', JSON.stringify(this.state.inputs));
    });
  }

  render() {
    return (
      <Layout fixedHeader={true}>
        <Header title="Wizard Scorekeeper">
          <IconButton id="menu" name="more_vert" />
          <Menu target="menu" align="right">
            <MenuItem disabled={!this.state.players} onClick={() => this.onNewGame()}>New Game</MenuItem>
          </Menu>
        </Header>
        <Content style={{overflowX: 'scroll'}}>
          <div style={{paddingBottom: 30, paddingLeft: 30, paddingRight: 30}}>
            {this.state.players ?
              <Game
                players={this.state.players}
                inputs={this.state.inputs}
                onBidsSubmitted={(round, bids) => this.onBidsSubmitted(round, bids)}
                onNewGame={() => this.onNewGame()}
                onTricksSubmitted={(round, tricks) => this.onTricksSubmitted(round, tricks)} /> :
              <Setup onBeginGame={this.onBeginGame.bind(this)} />
            }
          </div>
        </Content>
      </Layout>
    );
{'fraction_non_alphanumeric': 0.15622825330549756, 'fraction_numerical': 0.0020876826722338203, 'mean_word_length': 3.181090909090909, 'pattern_counts': {'":': 0, '<': 35, '<?xml version=': 0, '>': 51, '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': '2449661', 'n_tokens_mistral': 1698, 'n_tokens_neox': 1676, 'n_words': 344}