diff --git a/leaky-ships/components/Lobby/LobbyFrame.tsx b/leaky-ships/components/Lobby/LobbyFrame.tsx index a763f61..fffb44d 100644 --- a/leaky-ships/components/Lobby/LobbyFrame.tsx +++ b/leaky-ships/components/Lobby/LobbyFrame.tsx @@ -4,23 +4,21 @@ import useGameState from "@lib/hooks/useGameState" import { Fragment, useEffect, useState } from "react" function LobbyFrame({ openSettings }: { openSettings: () => void }) { - const { gameProps } = useGameState() + const { payload } = useGameState().gameProps const [dots, setDots] = useState(1) - const { gamePin, player1, player2 } = gameProps.payload - useEffect(() => { - if (player2) return + if (payload?.player2) return const interval = setInterval(() => setDots((e) => (e % 3) + 1), 1000) return () => clearInterval(interval) - }, [player2]) + }, [payload?.player2]) return (
VS
- {player2 ? ( -
Warte auf Spieler 2 {Array.from(Array(dots), () => ".").join("")}
diff --git a/leaky-ships/lib/hooks/useGameState.tsx b/leaky-ships/lib/hooks/useGameState.tsx
index d2fc2ce..ff549f8 100644
--- a/leaky-ships/lib/hooks/useGameState.tsx
+++ b/leaky-ships/lib/hooks/useGameState.tsx
@@ -1,14 +1,49 @@
import { GamePropsSchema } from "@lib/zodSchemas"
import { useSession } from "next-auth/react"
-import { useEffect, useState } from "react"
+import {
+ Dispatch,
+ ReactNode,
+ SetStateAction,
+ createContext,
+ useContext,
+ useEffect,
+ useState,
+ useMemo,
+} from "react"
import { toast } from "react-toastify"
-function useGameState(initial?: GamePropsSchema) {
- const [gameProps, setGameProps] = useState