TicketingMovie.js 1.27 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([])
Kim, Subin's avatar
Kim, Subin committed
8
9
    const [error, setError] = useState()

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

    async function getMovieList() {
        try {
Kim, Subin's avatar
Kim, Subin committed
16
17
            const response = await movieApi.getListByCategoryfromDB()
            setMovieList(response)
Jiwon Yoon's avatar
Jiwon Yoon committed
18
        } catch (error) {
Kim, Subin's avatar
Kim, Subin committed
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
        <div >
            <div className="d-grid gap-2">
Jiwon Yoon's avatar
Jiwon Yoon committed
30
31
                {movieList.length > 0
                    ? movieList.map(movie => (
Kim, Subin's avatar
Kim, Subin committed
32
                        <button name={movie.id} className={`${ticketInfo.movieId == movie.id ? styles.on : styles.btn}`} onClick={handleClick}>
Jiwon Yoon's avatar
Jiwon Yoon committed
33
34
                            {movie.title}
                        </button>
Jiwon Yoon's avatar
Jiwon Yoon committed
35
36
                    ))
                    : <div>영화정보를 불러올  없습니다.</div>}
Jiwon Yoon's avatar
Jiwon Yoon committed
37
            </div>
Jiwon Yoon's avatar
Jiwon Yoon committed
38
39
40
41
42
        </div>
    )
}

export default TicketingMovie