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 (
{movieInfo.stillCuts.length > 0 ? movieInfo.stillCuts.map((imageUrl, index) => (
스틸컷
)) :
등록된 스틸컷이 없습니다.
}
영화포스터

{movieInfo.title}

예매율: {Math.round((movieInfo.ticket_sales / (movieInfo.totalReservationRate.totalReservationRate || 1)) * 100)}%

{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}

{movieInfo.overview}
{/*
관람평
*/}
) } export default MoviePage