mirror of
https://github.com/randyjc/Rahoot.git
synced 2026-03-13 20:15:35 +01:00
First Commit
This commit is contained in:
42
src/components/game/join/Username.jsx
Normal file
42
src/components/game/join/Username.jsx
Normal file
@@ -0,0 +1,42 @@
|
||||
import { usePlayerContext } from "@/context/player"
|
||||
import Form from "@/components/Form"
|
||||
import Button from "@/components/Button"
|
||||
import Input from "@/components/Input"
|
||||
import { useState } from "react"
|
||||
import { useSocketContext } from "@/context/socket"
|
||||
import { useRouter } from "next/router"
|
||||
|
||||
export default function Username() {
|
||||
const { socket } = useSocketContext()
|
||||
const { player, dispatch } = usePlayerContext()
|
||||
const [loading, setLoading] = useState(false)
|
||||
const router = useRouter()
|
||||
const [username, setUsername] = useState("")
|
||||
|
||||
const handleJoin = () => {
|
||||
dispatch({
|
||||
type: "LOGIN",
|
||||
payload: username,
|
||||
})
|
||||
|
||||
router.push("/game")
|
||||
}
|
||||
|
||||
return (
|
||||
<>
|
||||
{loading && (
|
||||
<div className="absolute w-full h-full z-30 bg-black/40 flex justify-center items-center">
|
||||
<Loader />
|
||||
</div>
|
||||
)}
|
||||
|
||||
<Form>
|
||||
<Input
|
||||
onChange={(e) => setUsername(e.target.value)}
|
||||
placeholder="Usernname here"
|
||||
/>
|
||||
<Button onClick={() => handleJoin()}>Submit</Button>
|
||||
</Form>
|
||||
</>
|
||||
)
|
||||
}
|
||||
Reference in New Issue
Block a user