BoxOffice.js 8.53 KB
Newer Older
Jiwon Yoon's avatar
Jiwon Yoon committed
1
2
import axios from "axios"
import baseUrl from '../../utils/baseUrl'
Jiwon Yoon's avatar
Jiwon Yoon committed
3
4
5
6
import React, { useState, useEffect } from "react"
import "./box-office.module.scss"
// import "./mystyle.css"

Kim, Subin's avatar
Kim, Subin committed
7

8
const BoxOffice = () => {
Jiwon Yoon's avatar
Jiwon Yoon committed
9
    const [TMDB_TopRated_Data, setTMDB_TopRated_Data] = useState()
Kim, Subin's avatar
Kim, Subin committed
10
    useEffect(() => {
Jiwon Yoon's avatar
Jiwon Yoon committed
11
        getTMDB_TopRated()
Jiwon Yoon's avatar
Jiwon Yoon committed
12
        let items = document.querySelectorAll('.carousel-item')
Kim, Subin's avatar
Kim, Subin committed
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
        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
28
29
30
31
    async function getTMDB_TopRated() {
        try {
            const response = await axios.get(`${baseUrl}/api/movie`)
            console.log(response.data)
Jiwon Yoon's avatar
Jiwon Yoon committed
32
            setTMDB_TopRated_Data(response.data)
Jiwon Yoon's avatar
Jiwon Yoon committed
33
34
        } catch (error) {

Jiwon Yoon's avatar
Jiwon Yoon committed
35
        }
Jiwon Yoon's avatar
Jiwon Yoon committed
36
37
    }

Kim, Subin's avatar
Kim, Subin committed
38
    return (
Jiwon Yoon's avatar
Jiwon Yoon committed
39
40
41
42
43
44
45
46
47
48
49
50
51
        <div className="container text-center my-3">
            {console.log(TMDB_TopRated_Data)}
            <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">
                        {TMDB_TopRated_Data?
                        TMDB_TopRated_Data.results.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>
Kim, Subin's avatar
Kim, Subin committed
52
53
54
                                </div>
                            </div>
                        </div>
Jiwon Yoon's avatar
Jiwon Yoon committed
55
56
                        ))
                    :(<div>영화를 불러올  없습니다:(</div>)}
Kim, Subin's avatar
Kim, Subin committed
57
                    </div>
Jiwon Yoon's avatar
Jiwon Yoon committed
58
59
60
61
62
63
64
65
                    <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
66
67
                </div>
            </div>
Jiwon Yoon's avatar
Jiwon Yoon committed
68
        </div>
Jiwon Yoon's avatar
Jiwon Yoon committed
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150

        // <div className="container">
        //     <h2 className="fw-bold text-white text-center mt-5">Box Office</h2>
        //     <div id="multi-carousel" className={`d-flex carousel slide align-items-center ${styles.customHeight}`} data-bs-ride="carousel">
        //         <div className="carousel-inner row">
        //             <div className="carousel-item active">
        //                 <div className="col-sm-3">
        //                     <div className="card bg-dark">
        //                         <div className={`card-img ${styles.cursor} ${styles.showplot}`}>
        //                             <img src="//via.placeholder.com/500x400/31f?text=1" className="img-fluid" />
        //                         </div>
        //                         <div className={`card-img-overlay text-white ${styles.dNone}`}>Slide 1</div>
        //                         <button className="btn btn-warning text-white my-1" onClick={(e) => console.log("click", e)}>예매하기</button>
        //                     </div>
        //                 </div>
        //             </div>
        //             <div className="carousel-item">
        //                 <div className="col-sm-3">
        //                     <div className="card bg-dark">
        //                         <div className={`card-img ${styles.cursor} ${styles.showplot}`}>
        //                             <img src="//via.placeholder.com/500x400/e66?text=2" className="img-fluid" />
        //                         </div>
        //                         <div className={`card-img-overlay text-white ${styles.dNone}`}>Slide 2</div>
        //                         <button className="btn btn-warning text-white my-1" onClick={(e) => console.log("click", e)}>예매하기</button>
        //                     </div>
        //                 </div>
        //             </div>
        //             <div className="carousel-item">
        //                 <div className="col-sm-3">
        //                     <div className="card bg-dark">
        //                         <div className={`card-img ${styles.cursor} ${styles.showplot}`}>
        //                             <img src="//via.placeholder.com/500x400/7d2?text=3" className="img-fluid" />
        //                         </div>
        //                         <div className={`card-img-overlay text-white ${styles.dNone}`}>Slide 3</div>
        //                         <button className="btn btn-warning text-white my-1" onClick={(e) => console.log("click", e)}>예매하기</button>
        //                     </div>
        //                 </div>
        //             </div>
        //             <div className="carousel-item">
        //                 <div className="col-sm-3">
        //                     <div className="card bg-dark">
        //                         <div className={`card-img ${styles.cursor} ${styles.showplot}`}>
        //                             <img src="//via.placeholder.com/500x400?text=4" className="img-fluid" />
        //                         </div>
        //                         <div className={`card-img-overlay text-white ${styles.dNone}`}>Slide 4</div>
        //                         <button className="btn btn-warning text-white my-1" onClick={(e) => console.log("click", e)}>예매하기</button>
        //                     </div>
        //                 </div>
        //             </div>
        //             <div className="carousel-item">
        //                 <div className="col-sm-3">
        //                     <div className="card bg-dark">
        //                         <div className={`card-img ${styles.cursor} ${styles.showplot}`}>
        //                             <img src="//via.placeholder.com/500x400/aba?text=5" className="img-fluid" />
        //                         </div>
        //                         <div className={`card-img-overlay text-white ${styles.dNone}`}>Slide 5</div>
        //                         <button className="btn btn-warning text-white my-1" onClick={(e) => console.log("click", e)}>예매하기</button>
        //                     </div>
        //                 </div>
        //             </div>
        //             <div className="carousel-item">
        //                 <div className="col-sm-3">
        //                     <div className="card bg-dark">
        //                         <div className={`card-img ${styles.cursor} ${styles.showplot}`}>
        //                             <img src="//via.placeholder.com/500x400/fc0?text=6" className="img-fluid" />
        //                         </div>
        //                         <div className={`card-img-overlay text-white ${styles.dNone}`}>Slide 6</div>
        //                         <button className="btn btn-warning text-white my-1" onClick={(e) => console.log("click", e)}>예매하기</button>
        //                     </div>
        //                 </div>
        //             </div>
        //         </div>
        //         <button className="carousel-control-prev" type="button" data-bs-target="#multi-carousel" data-bs-slide="prev">
        //             <span className="carousel-control-prev-icon" aria-hidden="true"></span>
        //             <span className="visually-hidden">Previous</span>
        //         </button>
        //         <button className="carousel-control-next" type="button" data-bs-target="#multi-carousel" data-bs-slide="next">
        //             <span className="carousel-control-next-icon" aria-hidden="true"></span>
        //             <span className="visually-hidden">Next</span>
        //         </button>
        //     </div>
        // </div>
Kim, Subin's avatar
Kim, Subin committed
151
152
153
    )
}

154
export default BoxOffice