TicketingMovie.js 1.2 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
5
import styles from "./ticketingMovie.module.scss"

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

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

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

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

Jiwon Yoon's avatar
Jiwon Yoon committed
27
    return (
Jiwon Yoon's avatar
Jiwon Yoon committed
28
29
30
31
32
33
34
35
        <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
36
37
38
39
40
        </div>
    )
}

export default TicketingMovie