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

Jiwon Yoon's avatar
Jiwon Yoon committed
7
const TicketingMovie = ({ticketInfo, setTicketInfo}) => {
Jiwon Yoon's avatar
Jiwon Yoon committed
8
    const [movieList, setMovieList] = useState([])
9
    const [error, setError] = useState()
Jiwon Yoon's avatar
Jiwon Yoon committed
10
11
12
13
14
15
    useEffect(() => {
        getMovieList()
    }, [])

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

Jiwon Yoon's avatar
Jiwon Yoon committed
24
25
    function handleClick(event) {
        console.log(event.target.name)
Jiwon Yoon's avatar
Jiwon Yoon 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
        <div >
Jiwon Yoon's avatar
Jiwon Yoon committed
31
            {console.log(ticketInfo.movieId)}
Jiwon Yoon's avatar
Jiwon Yoon committed
32
            <div className="d-grid gap-2">
Jiwon Yoon's avatar
Jiwon Yoon committed
33
34
                {movieList.length > 0
                    ? movieList.map(movie => (
Jiwon Yoon's avatar
Jiwon Yoon committed
35
                        <button name={movie.id} className={`${ticketInfo.movieId == movie.id ? styles.on : styles.btn}`} onClick={handleClick}>
Jiwon Yoon's avatar
Jiwon Yoon committed
36
37
                            {movie.title}
                        </button>
Jiwon Yoon's avatar
Jiwon Yoon committed
38
39
                    ))
                    : <div>영화정보를 불러올  없습니다.</div>}
Jiwon Yoon's avatar
Jiwon Yoon committed
40
            </div>
Jiwon Yoon's avatar
Jiwon Yoon committed
41
42
43
44
45
        </div>
    )
}

export default TicketingMovie