TicketingMovie.js 1.29 KB
Newer Older
Kim, Subin's avatar
Kim, Subin committed
1
2
3
import { useState, useEffect } from 'react'
import movieApi from '../../apis/movie.api'
import catchErrors from '../../utils/catchErrors'
Jiwon Yoon's avatar
Jiwon Yoon committed
4
import styles from "./ticketingMovie.module.scss"
5
6
import movieApi from '../../apis/movie.api'
import catchErrors from '../../utils/catchErrors'
Jiwon Yoon's avatar
Jiwon Yoon committed
7

Kim, Subin's avatar
Kim, Subin committed
8
const TicketingMovie = ({ ticketInfo, setTicketInfo }) => {
Jiwon Yoon's avatar
Jiwon Yoon committed
9
    const [movieList, setMovieList] = useState([])
10
    const [error, setError] = useState()
Kim, Subin's avatar
Kim, Subin committed
11

Jiwon Yoon's avatar
Jiwon Yoon committed
12
13
14
15
16
17
    useEffect(() => {
        getMovieList()
    }, [])

    async function getMovieList() {
        try {
18
19
            const response = await movieApi.getListByCategoryfromDB()
            setMovieList(response)
Jiwon Yoon's avatar
Jiwon Yoon committed
20
        } catch (error) {
21
            catchErrors(error, setError)
Jiwon Yoon's avatar
Jiwon Yoon committed
22
23
24
        }
    }

Jiwon Yoon's avatar
Jiwon Yoon committed
25
    function handleClick(event) {
Kim, Subin's avatar
Kim, Subin committed
26
        setTicketInfo({ ...ticketInfo, movieId: event.target.name })
Jiwon Yoon's avatar
Jiwon Yoon committed
27
    }
Jiwon Yoon's avatar
Jiwon Yoon committed
28

Jiwon Yoon's avatar
Jiwon Yoon committed
29
    return (
Jiwon Yoon's avatar
Jiwon Yoon committed
30
31
32
33
34
35
36
37
        <div className="d-grid gap-2">
            {movieList.length > 0
                ? movieList.map(movie => (
                    <button name={movie.id} className={`${ticketInfo.movieId == movie.id ? styles.on : styles.btn}`} onClick={handleClick}>
                        {movie.title}
                    </button>
                ))
                : <div>영화정보를 불러올  없습니다.</div>}
Jiwon Yoon's avatar
Jiwon Yoon committed
38
39
40
41
42
        </div>
    )
}

export default TicketingMovie