|
|
@ -6,41 +6,51 @@ function Movie(props) { |
|
|
|
const [movie, setMovie] = useState({}); |
|
|
|
const [error, setError] = useState(""); |
|
|
|
|
|
|
|
|
|
|
|
const movieId = props.movieId; |
|
|
|
|
|
|
|
const handleChange = type => async e => { |
|
|
|
e.preventDefault(); |
|
|
|
const Token = window.localStorage.getItem("Token"); |
|
|
|
//if (type==="rating"? setRating(e.target.value):setwatchStatus(e.target.value));
|
|
|
|
const body = type === "rating" ? { |
|
|
|
rating: e.target.value, |
|
|
|
watchStatus: movie.watchStatus |
|
|
|
} : { rating: movie.rating, watchStatus: e.target.value }; |
|
|
|
|
|
|
|
const body = |
|
|
|
type === "rating" |
|
|
|
? { |
|
|
|
rating: e.target.value || null, |
|
|
|
watchStatus: movie.watchStatus, |
|
|
|
} |
|
|
|
: { |
|
|
|
rating: movie.rating, |
|
|
|
watchStatus: e.target.value || null, |
|
|
|
}; |
|
|
|
try { |
|
|
|
const response = await fetch("https://mkr.thefeathers.in/movie/" + movieId, { |
|
|
|
method: "POST", |
|
|
|
headers: new Headers({ "content-type": "application/json", Authentication: Token }), |
|
|
|
body: JSON.stringify |
|
|
|
(body) |
|
|
|
}); |
|
|
|
const response = await fetch( |
|
|
|
"https://mkr.thefeathers.in/movie/" + movieId, |
|
|
|
{ |
|
|
|
method: "POST", |
|
|
|
headers: new Headers({ |
|
|
|
"content-type": "application/json", |
|
|
|
"Authentication": Token, |
|
|
|
}), |
|
|
|
body: JSON.stringify(body), |
|
|
|
}, |
|
|
|
); |
|
|
|
const data = await response.json(); |
|
|
|
console.log(data); |
|
|
|
if (data.success) { |
|
|
|
setMovie({ |
|
|
|
...movie, |
|
|
|
rating: data.data.rating, |
|
|
|
watchStatus: data.data.watchStatus |
|
|
|
|
|
|
|
watchStatus: data.data.watchStatus, |
|
|
|
}); |
|
|
|
setError(""); |
|
|
|
} else { |
|
|
|
setError(data.msg); |
|
|
|
} |
|
|
|
|
|
|
|
} catch (e) { |
|
|
|
setError(e.message); |
|
|
|
} |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
useEffect(() => { |
|
|
|
const main = async () => { |
|
|
|
try { |
|
|
@ -84,23 +94,21 @@ function Movie(props) { |
|
|
|
})} |
|
|
|
<div> |
|
|
|
Rating |
|
|
|
<select value={movie.rating} |
|
|
|
<select |
|
|
|
value={movie.rating || ""} |
|
|
|
onChange={handleChange("rating")}> |
|
|
|
{[1, 2, 3, 4, 5, 6, 7, 8, 9, 10].map(r => ( |
|
|
|
<option value={String(r)}> |
|
|
|
{r} |
|
|
|
</option> |
|
|
|
{["", 1, 2, 3, 4, 5, 6, 7, 8, 9, 10].map(r => ( |
|
|
|
<option value={String(r)}>{r}</option> |
|
|
|
))} |
|
|
|
</select> |
|
|
|
</div> |
|
|
|
<div> |
|
|
|
Watch Status |
|
|
|
<select value={movie.watchStatus} |
|
|
|
<select |
|
|
|
value={movie.watchStatus || ""} |
|
|
|
onChange={handleChange("watchStatus")}> |
|
|
|
{["PLANNED", "IN_PROGRESS", "COMPLETED"].map(r => ( |
|
|
|
<option value={String(r)}> |
|
|
|
{r} |
|
|
|
</option> |
|
|
|
{["", "PLANNED", "IN_PROGRESS", "COMPLETED"].map(r => ( |
|
|
|
<option value={String(r)}>{r}</option> |
|
|
|
))} |
|
|
|
</select> |
|
|
|
</div> |
|
|
|