import { useState, useEffect } from 'react'; import { Link } from 'react-router-dom'; import Video from '../components/Video.js'; import movieApi from '../apis/movie.api.js'; import catchErrors from "../utils/catchErrors.js"; const MoviePage = ({ location }) => { const [movieInfo, setMovieInfo] = useState({ ...location.state, stillCuts: [], cast: [], director: [] }) const [state, setState] = useState(0) const [error, setError] = useState("") useEffect(() => { getImagesAndCredits() }, []) async function getImagesAndCredits() { try { const images = await movieApi.getImagesfromTM(movieInfo.id) const still = images.backdrops.map(el => el.file_path) const credits = await movieApi.getCreditsfromTM(movieInfo.id) const castsInfo = credits.cast.map(el => el.name) const directorsInfo = await credits.crew.filter(element => element.job === "Director").map(el => el.name) setMovieInfo({ ...movieInfo, stillCuts: still, cast: castsInfo, director: directorsInfo }) } catch (error) { catchErrors(error, setError) } } return (
예매율:{Math.round((movieInfo.ticket_sales / (movieInfo.totalReservationRate.totalReservationRate || 1)) * 100)}% 누적관객수: {movieInfo.ticket_sales}명
{movieInfo.director || movieInfo.cast ? <>감독: {movieInfo.director.map(el => el) + ' '}
출연: {movieInfo.cast.slice(0, 5).map(el => el) + ' '}
> : <>> }장르: {movieInfo.genres.reduce((acc, cur, idx) => { if (idx !== 0) return acc + ', ' + cur.name else return acc + cur.name }, "")}
개봉일:{movieInfo.release_date}