BoxOffice.js 2.95 KB
Newer Older
Jiwon Yoon's avatar
Jiwon Yoon committed
1
import axios from "axios"
한규민's avatar
한규민 committed
2
3
import { baseUrl } from '../../utils/baseUrl.js'
import { useState, useEffect } from "react"
4
import styles from "./box-office.module.scss"
Kim, Subin's avatar
Kim, Subin committed
5

6
const BoxOffice = () => {
Jiwon Yoon's avatar
Jiwon Yoon committed
7
    const [TMDB_TopRated_Data, setTMDB_TopRated_Data] = useState()
Kim, Subin's avatar
Kim, Subin committed
8
    useEffect(() => {
Jiwon Yoon's avatar
Jiwon Yoon committed
9
        getTMDB_TopRated()
Jiwon Yoon's avatar
Jiwon Yoon committed
10
        let items = document.querySelectorAll('.carousel-item')
Kim, Subin's avatar
Kim, Subin committed
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
        console.log("item", items)
        items.forEach((el) => {
            const minPerSlide = 4
            let next = el.nextElementSibling
            for (let i = 1; i < minPerSlide; i++) {
                if (!next) {
                    next = items[0]
                }
                let cloneChild = next.cloneNode(true)
                el.appendChild(cloneChild.children[0])
                next = next.nextElementSibling
            }
        })
    }, [])

Jiwon Yoon's avatar
Jiwon Yoon committed
26
27
28
29
    async function getTMDB_TopRated() {
        try {
            const response = await axios.get(`${baseUrl}/api/movie`)
            console.log(response.data)
Jiwon Yoon's avatar
Jiwon Yoon committed
30
            setTMDB_TopRated_Data(response.data)
Jiwon Yoon's avatar
Jiwon Yoon committed
31
32
        } catch (error) {

Jiwon Yoon's avatar
Jiwon Yoon committed
33
        }
Jiwon Yoon's avatar
Jiwon Yoon committed
34
35
    }

Kim, Subin's avatar
Kim, Subin committed
36
    return (
Jiwon Yoon's avatar
Jiwon Yoon committed
37
        <div className="container text-center my-3">
한규민's avatar
한규민 committed
38
            {console.log(typeof (TMDB_TopRated_Data))}
Jiwon Yoon's avatar
Jiwon Yoon committed
39
40
41
            <div className="row my-auto justify-content-center">
                <div id="recipeCarousel" className="carousel slide" data-bs-ride="carousel" data-bs-interval="999999999">
                    <div className={`carousel-inner`} role="listbox">
한규민's avatar
한규민 committed
42
43
44
45
46
47
48
49
50
                        {TMDB_TopRated_Data ?
                            TMDB_TopRated_Data.map((moviePoster, index) => (
                                <div className={`carousel-item ${index === 0 ? "active" : ""}`}>
                                    <div className="col-sm-3">
                                        <div className="card">
                                            <div className="card-img">
                                                <img src={`https://image.tmdb.org/t/p/original${moviePoster.poster_path}`} className="img-fluid" />
                                            </div>
                                        </div>
Jiwon Yoon's avatar
Jiwon Yoon committed
51
                                    </div>
Kim, Subin's avatar
Kim, Subin committed
52
                                </div>
한규민's avatar
한규민 committed
53
54
                            ))
                            : (<div>영화를 불러올  없습니다:(</div>)}
Kim, Subin's avatar
Kim, Subin committed
55
                    </div>
Jiwon Yoon's avatar
Jiwon Yoon committed
56
57
58
59
60
61
62
63
                    <a className="carousel-control-prev bg-transparent w-aut" href="#recipeCarousel" role="button"
                        data-bs-slide="prev">
                        <span className="carousel-control-prev-icon" aria-hidden="true"></span>
                    </a>
                    <a className="carousel-control-next bg-transparent w-aut" href="#recipeCarousel" role="button"
                        data-bs-slide="next">
                        <span className="carousel-control-next-icon" aria-hidden="true"></span>
                    </a>
Kim, Subin's avatar
Kim, Subin committed
64
65
                </div>
            </div>
Jiwon Yoon's avatar
Jiwon Yoon committed
66
        </div>
Kim, Subin's avatar
Kim, Subin committed
67
68
69
    )
}

70
export default BoxOffice