leaky-ships/leaky-ships/pages/game.tsx
2023-07-11 19:25:44 +02:00

44 lines
1.2 KiB
TypeScript

import { useGameProps } from "@hooks/useGameProps"
import { useSession } from "next-auth/react"
import { useRouter } from "next/router"
import { useEffect } from "react"
import { toast } from "react-toastify"
export default function Game() {
const { payload } = useGameProps()
const router = useRouter()
const { data: session } = useSession()
useEffect(() => {
const gameId = payload?.game?.id
const path = gameId ? "/game" : "/start"
toast.promise(router.push(path), {
pending: {
render: "Wird weitergeleitet...",
toastId: "pageLoad",
},
success: {
render: gameId
? "Spiel gefunden!"
: session?.user.id
? "Kein laufendes Spiel."
: "Kein laufendes Spiel. Bitte anmelden.",
toastId: "pageLoad",
theme: session?.user.id ? "dark" : undefined,
type: gameId ? "success" : "info",
},
error: {
render: "Es ist ein Fehler aufgetreten 🤯",
type: "error",
toastId: "pageLoad",
theme: "colored",
},
})
})
return (
<div className="h-full bg-theme">
<div className="mx-auto flex h-full max-w-screen-md flex-col items-center justify-evenly"></div>
</div>
)
}