Collection.js 1.75 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" }}>
Kim, Subin's avatar
Kim, Subin committed
27
28
29
30
31
                <div className="col-md-8">
                    {videoUrls.length > 0
                        ?
                        <div className="">
                            <div className="ratio ratio-16x9">
Jiwon Yoon's avatar
Jiwon Yoon committed
32
                                <iframe src={`https://www.youtube.com/embed/${videoUrls[0].key}`} title="YouTube video" allowFullScreen></iframe>
Kim, Subin's avatar
Kim, Subin committed
33
34
35
36
37
38
39
40
41
42
43
                            </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
44
45
46
47
48
49
            </div>
        </>
    )
}

export default Collection