1
0

Created the Game.jsx page

This commit is contained in:
Mathias Wagner 2023-11-18 23:40:35 +01:00
parent 5a2d375c72
commit 10a789ce4b
Signed by: Mathias
GPG Key ID: B8DC354B0A1F5B44

View File

@ -0,0 +1,33 @@
import {useContext, useEffect, useState} from "react";
import {GroupContext} from "@/common/contexts/GroupContext.jsx";
import {Navigate} from "react-router";
import "./styles.sass";
import Waiting from "@/pages/Game/states/Waiting";
import {socket} from "@/common/utils/socket.js";
import Calculate from "@/pages/Game/states/Calculate/index.js";
export const Game = () => {
const {groups} = useContext(GroupContext);
const [currentState, setCurrentState] = useState("hint");
useEffect(() => {
const timeout = setTimeout(() => {
setCurrentState("waiting");
socket.emit("SUBMISSION_READY");
}, 5000);
return () => clearTimeout(timeout);
}, []);
if (groups.length === 0) return <Navigate to="/"/>;
return (
<div className="game-page">
{currentState === "hint" && <h2 className="hint"><span>Ziel</span>: Erhalte durch den Verkauf von Kuchen
so viel Gewinn wie möglich.</h2>}
{currentState === "waiting" && <Waiting setState={setCurrentState}/>}
{currentState === "calculate" && <Calculate setState={setCurrentState}/>}
</div>
)
}