Created the Game.jsx page
This commit is contained in:
parent
5a2d375c72
commit
10a789ce4b
33
client/src/pages/Game/Game.jsx
Normal file
33
client/src/pages/Game/Game.jsx
Normal 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>
|
||||||
|
)
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user