Collection.js 1.73 KB
Newer Older
Kim, Subin's avatar
Kim, Subin committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
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) {
            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)
        }
    }
Kim, Subin's avatar
Kim, Subin committed
23
24
25
    return (
        <>
            <h2 className="fw-bold text-white text-center my-5">Movie Collection</h2>
Kim, Subin's avatar
Kim, Subin committed
26
            <div className="d-flex justify-content-sm-center" style={{ marginBottom: "8rem" }}>
27
                <div className="col-sm-8">
Kim, Subin's avatar
Kim, Subin committed
28
29
                    {videoUrls.length > 0
                        ?
30
31
                        <div className="ratio ratio-16x9">
                            <iframe src={`https://www.youtube.com/embed/${videoUrls[0].key}`} title="YouTube video" allowFullScreen></iframe>
Kim, Subin's avatar
Kim, Subin committed
32
33
34
                        </div>
                        : <div className="text-center">예고편 정보가 존재하지 않습니다.</div>}
                </div>
35
36
37
38
39
40
41
42
                <div className="col-sm-3">
                    {TMDB_TopRated_Data.length > 0
                        ?
                        <img src={`https://image.tmdb.org/t/p/original${TMDB_TopRated_Data[0].poster_path}`} className="img-fluid bg-black" />
                        :
                        <div></div>
                    }
                </div>
Kim, Subin's avatar
Kim, Subin committed
43
44
45
46
47
48
            </div>
        </>
    )
}

export default Collection