-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
344 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
221 changes: 216 additions & 5 deletions
221
Week-14-Props_State_Events_and_Lifecycle_Methods/src/App.jsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
60 changes: 60 additions & 0 deletions
60
Week-14-Props_State_Events_and_Lifecycle_Methods/src/Leave Review.jsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
import { useState } from "react" | ||
import StarRating from "./StarRating"; | ||
|
||
export default function LeaveReview({ id, handlePost}){ | ||
//States to pull from form | ||
const [userName, setUserName] = useState(""); | ||
const [review, setReview] = useState(""); | ||
|
||
const postReview = (e) => { | ||
e.preventDefault(); | ||
let index = id; | ||
let newReview = { | ||
author: userName, | ||
stars: selectedRatings[0], | ||
review: review | ||
} | ||
|
||
handlePost(index, newReview); | ||
setUserName(""); | ||
setReview(""); | ||
setSelectedRatings(0); | ||
|
||
}; | ||
|
||
const [selectedRatings, setSelectedRatings] = useState([]); | ||
|
||
const handleRatingChange = (rating) => { | ||
setSelectedRatings((prevRatings) => [...prevRatings, rating]); | ||
}; | ||
//html form | ||
return ( | ||
|
||
<> | ||
|
||
<div id="wrapper"> | ||
<div className="reviewForm"> | ||
<h5>Feel Free to Leave a Review:</h5> | ||
<form onSubmit={postReview}> | ||
<label >Your Name:</label><br/> | ||
<input type="text" id="username" | ||
value={userName} className="form-control" placeholder="Please enter your name:" | ||
onChange={(e) => setUserName(e.target.value)} /> | ||
<br/> | ||
<label >Please Share Your Thoughts:</label><br/> | ||
<input type="text" className="form-control" id="review" | ||
value={review} placeholder="Leave a review here:" | ||
onChange={(e) => setReview(e.target.value)} /> | ||
<br/> | ||
<label>How Many Stars Would You Give?</label> | ||
<StarRating defaultValue={0} onRatingChange={handleRatingChange}/> | ||
<br/> | ||
<button id="post" className="btn btn-secondary" type="submit">Post Review</button> | ||
<br/> | ||
</form> | ||
<br/> | ||
</div> | ||
</div> | ||
</> | ||
) | ||
} |
45 changes: 38 additions & 7 deletions
45
Week-14-Props_State_Events_and_Lifecycle_Methods/src/MovieCard.jsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.