feat: implement navigation to public room from home

This commit is contained in:
Jeremy Kahn 2022-08-10 22:15:50 -05:00
parent 36d059329c
commit b24fe12a50

View File

@ -1,16 +1,25 @@
import React, { useState } from 'react' import React, { useState } from 'react'
import { useNavigate } from 'react-router-dom'
import Button from '@mui/material/Button'
import FormControl from '@mui/material/FormControl'
import Typography from '@mui/material/Typography' import Typography from '@mui/material/Typography'
import TextField from '@mui/material/TextField' import TextField from '@mui/material/TextField'
import { v4 as uuid } from 'uuid' import { v4 as uuid } from 'uuid'
export function Home() { export function Home() {
const [roomName, setRoomName] = useState(uuid()) const [roomName, setRoomName] = useState(uuid())
const navigate = useNavigate()
const handleRoomNameChange = (event: React.ChangeEvent<HTMLInputElement>) => { const handleRoomNameChange = (event: React.ChangeEvent<HTMLInputElement>) => {
const { value } = event.target const { value } = event.target
setRoomName(value) setRoomName(value)
} }
const handleFormSubmit = (event: React.SyntheticEvent<HTMLFormElement>) => {
event.preventDefault()
navigate(`/public/${roomName}`)
}
return ( return (
<div className="Home"> <div className="Home">
<header className="max-w-3xl text-center mx-auto"> <header className="max-w-3xl text-center mx-auto">
@ -25,13 +34,22 @@ export function Home() {
</Typography> </Typography>
</header> </header>
<main className="mt-8 max-w-3xl text-center mx-auto"> <main className="mt-8 max-w-3xl text-center mx-auto">
<TextField <form onSubmit={handleFormSubmit} className="max-w-xl mx-auto">
id="outlined-basic" <FormControl fullWidth>
label="Room name" <TextField
variant="outlined" label="Room name"
value={roomName} variant="outlined"
onChange={handleRoomNameChange} value={roomName}
/> onChange={handleRoomNameChange}
size="medium"
/>
</FormControl>
<div className="block pt-4">
<Button variant="contained" type="submit">
Go to public room
</Button>
</div>
</form>
</main> </main>
</div> </div>
) )