From 976ed2b105e80b257ebb724b3061400f37460041 Mon Sep 17 00:00:00 2001
From: Mike Vink <mike1994vink@gmail.com>
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 (
-        <form onSubmit={(e) => tryStartGame(e)}>
-            <input value={playerOne}
-                placeholder="Player 1 name"
-                onChange={(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 <Play gameState={gameState} setGameState={setGameState} />
+    } else {
+        return (
+            <form onSubmit={(e) => tryStartGame(e)}>
+                <input value={playerOne}
+                    placeholder="Player 1 name"
+                    onChange={(e) => setPlayerOne(e.target.value)}
+                />
 
-            <input value={playerTwo}
-                placeholder="Player 2 name"
-                onChange={(e) => setPlayerTwo(e.target.value)}
-            />
+                <input value={playerTwo}
+                    placeholder="Player 2 name"
+                    onChange={(e) => setPlayerTwo(e.target.value)}
+                />
 
-            <p className="errorMessage">{errorMessage}</p>
+                <p className="errorMessage">{errorMessage}</p>
 
-            <button className="startGameButton" type="submit">
-                Play Mancala!
-            </button>
-        </form>
-    )
-}
\ No newline at end of file
+                <button className="startGameButton" type="submit">
+                    Play Mancala!
+                </button>
+            </form>
+        )
+    }
+}
-- 
cgit v1.2.3

