import { useState, useEffect } from 'react'; import { Link } from 'react-router-dom'; import movieApi from '../apis/movie.api.js' import Video from '../components/Video.js' const MoviePage = ({ location }) => { const [movieInfo, setMovieInfo] = useState({ ...location.state, stillCuts: [], cast: [], director: [], // attendance: "" }) const [state, setState] = useState(0) 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) console.log(castsInfo) const directorsInfo = await credits.crew.filter(element => element.job === "Director").map(el=>el.name) console.log("directorInfo=", directorsInfo) setMovieInfo({ ...movieInfo, stillCuts: still, cast: castsInfo, director: directorsInfo }) } catch (error) { console.log(error) } } return (
예매율:{Math.round((movieInfo.ticket_sales / movieInfo.totalReservationRate.totalReservationRate) * 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}