<commit_before>'use strict';

const React = require('react');
const _ = require('lodash');
const Headtags = require('vitreum/headtags');

// data
const Store = require('data/store');
const Actions = require('data/actions');

// pages
const NameAgent = require('main/nameAgent/nameAgent.jsx');
const Menu = require('main/menu/menu.jsx');
const Game = require('main/game/game.jsx');


const Main = React.createClass({

	getDefaultProps: function() {
		return {
			pageState: 'NameAgent',
			player: null,
			games: null,
			gameState: null,
		};
	},

	componentDidMount: function() {
		if (!this.props.player) {
			console.log('no player');
			// go to default NameAgent page
			return;
		}
		Actions.getPlayer(this.props.player.id)
			.then((player) => {
				console.log('fetched player');
				if (player.gameId) {
					console.log('player has game ID; connecting');
					Actions.connectAndJoinGame(player.gameId);
					console.log('joined game');
					Actions.setPageState('Game');
				} else {
					console.log('no game; going to menu');
					return Actions.setPageState('Menu');
				}
			})
			.catch((err) => {
				console.error(err);
				return Actions.setPageState('NameAgent');
			});
	},

	renderPage: function() {
		console.log(this.props);
		switch (this.props.pageState) {
			case 'NameAgent':
				return <NameAgent />;
			case 'Menu':
				return <Menu playerName={_.get(this.props.player, 'name')} />;
			case 'Lobby':
				return <Lobby />;
			case 'Game':
				return <Game state={this.props.gameState} />;
			default:
				throw new Error(`Invalid pageState: ${this.props.pageState}`);
		}
	},

	render: function() {
		return (
			<main>
				<Headtags.title>The Ohms</Headtags.title>
				<Headtags.meta name="description" content="Can you resist?" />

				{/*<Headtags.meta name="viewport" content="width=device-width, initial-scale=1" />*/}<commit_msg>Fix game page loading before game state is ready.<commit_after>'use strict';

const React = require('react');
const _ = require('lodash');
const Headtags = require('vitreum/headtags');

// data
const Store = require('data/store');
const Actions = require('data/actions');

// pages
const NameAgent = require('main/nameAgent/nameAgent.jsx');
const Menu = require('main/menu/menu.jsx');
const Game = require('main/game/game.jsx');


const Main = React.createClass({

	getDefaultProps: function() {
		return {
			pageState: 'NameAgent',
			player: null,
			games: null,
			gameState: null,
		};
	},

	componentDidMount: function() {
		if (!this.props.player) {
			console.log('no player');
			// go to default NameAgent page
			return;
		}
		Actions.getPlayer(this.props.player.id)
			.then((player) => {
				console.log('fetched player');
				if (player.gameId) {
					console.log('player has game ID; connecting');
					Actions.connectAndJoinGame(player.gameId);
				} else {
					console.log('no game; going to menu');
					return Actions.setPageState('Menu');
				}
			})
			.catch((err) => {
				console.error(err);
				return Actions.setPageState('NameAgent');
			});
	},

	componentWillReceiveProps: function(nextProps) {
		if (!this.props.gameState && !!nextProps.gameState) {
			Actions.setPageState('Game');
		}
	},

	renderPage: function() {
		console.log(this.props);
		switch (this.props.pageState) {
			case 'NameAgent':
				return <NameAgent />;
			case 'Menu':
				return <Menu playerName={_.get(this.props.player, 'name')} />;
			case 'Game':
				return <Game state={this.props.gameState} />;
			default:
				throw new Error(`Invalid pageState: ${this.props.pageState}`);
		}
	},

	render: function() {
		return (
			<main>
				<Headtags.title>The Ohms</Headtags.title>
				<Headtags.meta name="description" content="Can you resist?" />

				{/*<Headtags.meta name="viewport" content="width=device-width, initial-scale=1" />*/}
{'fraction_non_alphanumeric': 0.16925098554533508, 'fraction_numerical': 0.0005256241787122207, 'mean_word_length': 3.6699386503067486, 'pattern_counts': {'":': 0, '<': 20, '<?xml version=': 0, '>': 24, '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': '7618257', 'n_tokens_mistral': 1465, 'n_tokens_neox': 1230, 'n_words': 257}