Further changes to the ReviewForm to add authentication state

This commit is contained in:
Ray 2023-11-21 10:11:14 +00:00 committed by GitHub
parent ec35fdbdc1
commit 3b7285b1a8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 6 deletions

View File

@ -2,24 +2,31 @@ import Form from "react-bootstrap/Form"
import Button from "react-bootstrap/Button" import Button from "react-bootstrap/Button"
import { AuthContext } from "../contexts/AuthContext" import { AuthContext } from "../contexts/AuthContext"
import { useContext } from "react" import { useContext, useState } from "react"
const submitHandler = (event) => {
event.preventDefault()
}
export function ReviewForm(props) { export function ReviewForm(props) {
const auth = useContext(AuthContext) const auth = useContext(AuthContext)
const[star, setStar ] = useState()
const[title, setTitle ] = useState()
const[review, setReview ] = useState()
if (auth) { if (auth) {
return ( return (
<Form> <Form onSubmit={submitHandler}>
<h3>Review this movie</h3> <h3>Review {props.movietitle}</h3>
<Form.Group> <Form.Group>
<Form.Label>Star</Form.Label> <Form.Label>Star</Form.Label>
<Form.Select> <Form.Select name="star" value={star} onChange={(evt) => setStar(evt.target.value) }>
<option value="1">1</option> <option value="1">1</option>
<option value="2">2</option> <option value="2">2</option>
<option value="3">3</option> <option value="3">3</option>
<option value="4">4</option> <option value="4">4</option>
<option value="5">5</option> <option value="5">5</option>
</Form.Select> </Form.Select>
<Form.Text>You have given {star} star(s)</Form.Text>
</Form.Group> </Form.Group>
<Form.Group> <Form.Group>
<Form.Label>Title</Form.Label> <Form.Label>Title</Form.Label>

View File

@ -24,7 +24,7 @@ export function Detail(props) {
<Container> <Container>
<Row> <Row>
<Col> <Col>
<h1>{movieData.title}</h1> <h1>{movieData.movie_title}</h1>
</Col> </Col>
</Row> </Row>
<Row> <Row>
@ -50,7 +50,7 @@ export function Detail(props) {
</Row> </Row>
<Row> <Row>
<Col> <Col>
<ReviewForm /> <ReviewForm movietitle={movieData.movie_title} />
</Col> </Col>
</Row> </Row>
</Container> </Container>