Add Start cooldown & Patch socket event

This commit is contained in:
Ralex91
2024-02-02 13:55:55 +01:00
parent 6c7f31a6d4
commit cd723f7efd
19 changed files with 298 additions and 151 deletions

View File

@@ -5,15 +5,17 @@ import Prepared from "@/components/game/states/Prepared"
import Question from "@/components/game/states/Question"
import Result from "@/components/game/states/Result"
import Wait from "@/components/game/states/Wait"
import Start from "@/components/game/states/Start"
import { usePlayerContext } from "@/context/player"
import { useSocketContext } from "@/context/socket"
import { useRouter } from "next/router"
import { createElement, useState } from "react"
import { createElement, useMemo, useState } from "react"
const gameStateComponent = {
SELECT_ANSWER: Answers,
SHOW_QUESTION: Question,
WAIT: Wait,
SHOW_START: Start,
SHOW_RESULT: Result,
SHOW_PREPARED: Prepared,
}
@@ -40,16 +42,22 @@ export default function Game() {
},
})
socket.on("game:status", (status) => {
setState({
...state,
status: status,
question: {
...state.question,
current: status.question,
},
useMemo(() => {
socket.on("game:status", (status) => {
setState({
...state,
status: status,
question: {
...state.question,
current: status.question,
},
})
})
})
return () => {
socket.off("game:status")
}
}, [state])
return (
<GameWrapper>