diff --git a/client/src/routes/Home.tsx b/client/src/routes/Home.tsx index 131eb28..54b0507 100644 --- a/client/src/routes/Home.tsx +++ b/client/src/routes/Home.tsx @@ -1,14 +1,20 @@ -import { useState } from "react"; +import { useEffect, useRef, useState } from "react"; import { useLocation, useNavigate } from "react-router-dom"; import { Color, COLOR } from "../../../server/src/engine"; import Show from "../utils/Show"; +import { CircleExclamation } from "../utils/icons"; const Home = () => { const navigate = useNavigate(); + const location = useLocation(); + const [id, setID] = useState(""); const [join, setJoin] = useState(false); const [color, setColor] = useState(COLOR.WHITE); - const [error, setError] = useState(); + + const [err, setErr] = useState(); + const { error } = + location.state != null ? location.state : { error: undefined }; const createGame = () => { fetch("/api/create-game") @@ -21,7 +27,7 @@ const Home = () => { }) .catch((err) => { console.error(err); - setError(error); + setErr(err); }); }; @@ -33,20 +39,23 @@ const Home = () => { }) .then((text) => { if (text == "invalid id") throw new Error("Invalid game ID"); - if (text == "full") throw new Error("Game already had 2 players"); + if (text == "full") throw new Error("Game already has 2 players"); if (text == COLOR.BLACK) navigate("/game", { state: { id, color: text } }); }) .catch((err) => { console.error(err); - setError(error); + setErr(err); + setID(""); + setJoin(false); }); }; return ( <> - + +