Browse Source

changes for setting values

master
rosh 4 years ago
parent
commit
4209ea20aa
  1. 21
      react/src/pages/Movie.js

21
react/src/pages/Movie.js

@ -6,14 +6,13 @@ function Movie(props) {
const [movie, setMovie] = useState({}); const [movie, setMovie] = useState({});
const [error, setError] = useState(""); const [error, setError] = useState("");
const [rating, setRating] = useState(""); const [rating, setRating] = useState("");
const [watchStatus, setWatchStatus] = useState(""); const [watchStatus, setwatchStatus] = useState("");
const movieId = props.movieId; const movieId = props.movieId;
const handleRating = async e => { const handleChange = type => async e => {
e.preventDefault(); e.preventDefault();
setRating(e.target.value);
setWatchStatus(e.target.value);
const Token = window.localStorage.getItem("Token"); const Token = window.localStorage.getItem("Token");
try { try {
@ -26,9 +25,9 @@ function Movie(props) {
}), }),
}); });
const data = await response.json(); const data = await response.json();
if (type==="rating"? setRating(e.target.value):setwatchStatus(e.target.value));
console.log(rating); console.log(data.rating);
console.log(watchStatus); console.log(data.watchStatus);
} catch (e) { } catch (e) {
setError(e.message); setError(e.message);
@ -80,8 +79,8 @@ function Movie(props) {
<div> <div>
Rating Rating
<select defaultValue={rating} <select defaultValue={rating}
onChange={handleRating}> onChange={ () => handleChange("rating")}>
{["Select",1,2,3,4,5,6,7,8,9,10].map(r=> ( {[1,2,3,4,5,6,7,8,9,10].map(r=> (
<option value={String(r)} <option value={String(r)}
selected={ selected={
movie.rating === String(r) ? true : false movie.rating === String(r) ? true : false
@ -94,8 +93,8 @@ function Movie(props) {
<div> <div>
Watch Status Watch Status
<select defaultValue={watchStatus} <select defaultValue={watchStatus}
onChange={handleRating}> onChange={ () => handleChange("watchStatus")}>
{["Select","PLANNED","IN_PROGRESS","COMPLETED"].map(r=> ( {["PLANNED","IN_PROGRESS","COMPLETED"].map(r=> (
<option value={String(r)} <option value={String(r)}
selected={ selected={
movie.watchStatus === String(r) ? true : false movie.watchStatus === String(r) ? true : false

Loading…
Cancel
Save