Collection.js 1.84 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
import { useEffect, useState } from 'react'
import movieApi from '../apis/movie.api.js'
import catchErrors from '../utils/catchErrors.js'

const Collection = ({ TMDB_TopRated_Data }) => {
    const [videoUrls, setVideoUrls] = useState([])
    const [error, setError] = useState("")

    useEffect(() => {
        if (TMDB_TopRated_Data.length > 0) {
            console.log("야이쒸===", TMDB_TopRated_Data)
            getVideos()
        }
    }, [TMDB_TopRated_Data])

    async function getVideos() {
        try {
            const data = await movieApi.getVideosfromTM(TMDB_TopRated_Data[0].id)
            setVideoUrls(data)
        } catch (error) {
            // catchErrors(error, setError)
            console.log(error)
        }
    }
Kim, Subin's avatar
Kim, Subin committed
25
26
27
    return (
        <>
            <h2 className="fw-bold text-white text-center my-5">Movie Collection</h2>
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
            <div className="row justify-content-sm-center" style={{ marginBottom: "8rem" }}>
                <div className="col-md-8">
                    {videoUrls.length > 0
                        ?
                        <div className="">
                            <div className="ratio ratio-16x9">
                                <iframe src={`https://www.youtube.com/embed/${videoUrls[0].key}`} title="YouTube video" allowfullscreen></iframe>
                            </div>
                        </div>

                        : <div className="text-center">예고편 정보가 존재하지 않습니다.</div>}
                </div>
                {TMDB_TopRated_Data.length > 0
                    ?
                    <img src={`https://image.tmdb.org/t/p/original${TMDB_TopRated_Data[0].poster_path}`} className="col-md-3 bg-black" />
                    :
                    <div className="col-md-3"></div>
                }
Kim, Subin's avatar
Kim, Subin committed
46
47
48
49
50
51
            </div>
        </>
    )
}

export default Collection