From 976ed2b105e80b257ebb724b3061400f37460041 Mon Sep 17 00:00:00 2001 From: Mike Vink Date: Thu, 24 Jun 2021 23:11:39 +0200 Subject: mega commit --- client/src/Mancala/StartGame.tsx | 45 ++++++++++++++++++++++++---------------- 1 file changed, 27 insertions(+), 18 deletions(-) (limited to 'client/src/Mancala/StartGame.tsx') diff --git a/client/src/Mancala/StartGame.tsx b/client/src/Mancala/StartGame.tsx index 9d5be2c..4cf8d94 100644 --- a/client/src/Mancala/StartGame.tsx +++ b/client/src/Mancala/StartGame.tsx @@ -1,15 +1,17 @@ import React, { useState } from "react"; import type { GameState } from "../gameState"; import "./StartGame.css"; +import { Play } from "./Play" type StartGameProps = { + gameState: GameState | undefined; setGameState(newGameState: GameState): void; } /** * Allows the players to enter their name. A name is required for both players. They can't have the same names. */ -export function StartGame({ setGameState }: StartGameProps) { +export function StartGame({gameState, setGameState }: StartGameProps) { const [errorMessage, setErrorMessage] = useState(""); const [playerOne, setPlayerOne] = useState(""); @@ -52,23 +54,30 @@ export function StartGame({ setGameState }: StartGameProps) { } } - return ( -
tryStartGame(e)}> - setPlayerOne(e.target.value)} - /> + if (localStorage.getItem("state") !== null) { + var state = localStorage.getItem("state"); + const gameState = JSON.parse(state as string); + setGameState(gameState); + return + } else { + return ( + tryStartGame(e)}> + setPlayerOne(e.target.value)} + /> - setPlayerTwo(e.target.value)} - /> + setPlayerTwo(e.target.value)} + /> -

{errorMessage}

+

{errorMessage}

- - - ) -} \ No newline at end of file + + + ) + } +} -- cgit v1.2.3