MovieComming.js 2.3 KB
Newer Older
Jiwon Yoon's avatar
Jiwon Yoon committed
1
2
import { useState, useEffect } from 'react'
import movieApi from '../../apis/movie.api.js'
Jiwon Yoon's avatar
Jiwon Yoon committed
3
import { Link } from 'react-router-dom';
Jiwon Yoon's avatar
Jiwon Yoon committed
4
import styles from "./movieComming.module.scss"
Jiwon Yoon's avatar
Jiwon Yoon committed
5

Jiwon Yoon's avatar
Jiwon Yoon committed
6
const MovieComming = () => {
Jiwon Yoon's avatar
Jiwon Yoon committed
7
8
    const [TMDB_TopRated_Data, setTMDB_TopRated_Data] = useState()
    const category="upcoming"
Jiwon Yoon's avatar
Jiwon Yoon committed
9
    useEffect(() => {
Jiwon Yoon's avatar
Jiwon Yoon committed
10
        getTMDB_TopRated()
Jiwon Yoon's avatar
Jiwon Yoon committed
11
12
    }, [])

Jiwon Yoon's avatar
Jiwon Yoon committed
13
    async function getTMDB_TopRated() {
Jiwon Yoon's avatar
Jiwon Yoon committed
14
        try {
Jiwon Yoon's avatar
Jiwon Yoon committed
15
16
17
            const data = await movieApi.getfromTM(category)
            console.log(data)
            setTMDB_TopRated_Data(data)
Jiwon Yoon's avatar
Jiwon Yoon committed
18
19
        } catch (error) {

Jiwon Yoon's avatar
Jiwon Yoon committed
20
        }
Jiwon Yoon's avatar
Jiwon Yoon committed
21
    }
Jiwon Yoon's avatar
Jiwon Yoon committed
22
23
    return (
        <div class="row row-cols-1 row-cols-md-4 g-4">
Jiwon Yoon's avatar
Jiwon Yoon committed
24
25
            {console.log(TMDB_TopRated_Data)}
            {TMDB_TopRated_Data
Jiwon Yoon's avatar
Jiwon Yoon committed
26
                ?
Jiwon Yoon's avatar
Jiwon Yoon committed
27
                TMDB_TopRated_Data.map(movie => (
Jiwon Yoon's avatar
Jiwon Yoon committed
28
                    <div className="card h-100" style={{ backgroundColor: "black" }}>
Jiwon Yoon's avatar
Jiwon Yoon committed
29
30
                        <Link to={{
                            pathname: `/movie/${movie.id}`,
Jiwon Yoon's avatar
Jiwon Yoon committed
31
                            state: {...movie}
Jiwon Yoon's avatar
Jiwon Yoon committed
32
33
34
35
                        }} className={`${styles.layer}`} >
                            <img src={`https://image.tmdb.org/t/p/original${movie.poster_path}`} className={`card-img-top rounded ${styles.poster}`} alt="Movie Poster" />
                            <div className={`${styles.description}`}>{movie.overview}</div>
                        </Link>
Jiwon Yoon's avatar
Jiwon Yoon committed
36
                        <div className="card-body text-light">
Jiwon Yoon's avatar
Jiwon Yoon committed
37
                            <marquee onmouseover="this.stop()" className={`h2 card-title text-center ${styles.title}`}>{movie.title}</marquee>
Jiwon Yoon's avatar
Jiwon Yoon committed
38
                            <p className="card-text text-center">예매율: {movie.ticket_sales}0% | {movie.runtime}</p>
Jiwon Yoon's avatar
Jiwon Yoon committed
39
40
                            <p className="card-text text-center"><small className="text-muted">{movie.release_date} 개봉</small></p>
                        </div>
Jiwon Yoon's avatar
Jiwon Yoon committed
41
42
43
44
45
46
                        <Link to={{
                            pathname:`/ticket`,
                            state: {movieId:movie.id}
                        }}>
                            <button className="btn btn-warning">예매하기</button>
                        </Link>
Jiwon Yoon's avatar
Jiwon Yoon committed
47
48
49
50
51
52
53
54
55
                    </div>
                ))
                : <div>영화정보를 로딩할  없습니다.</div>
            }
        </div>
    )
}

export default MovieComming