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

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

    async function getMovieList() {
        try {
            const response = await axios.get(`/api/movie/movielist`)
            setMovieList(response.data)
        } catch (error) {

        }
    }

Jiwon Yoon's avatar
Jiwon Yoon committed
20
21
    function handleClick(event) {
        console.log(event.target.name)
Jiwon Yoon's avatar
Jiwon Yoon committed
22
        setTicketInfo({...ticketInfo, movieId: event.target.name })
Jiwon Yoon's avatar
Jiwon Yoon committed
23
    }
Jiwon Yoon's avatar
Jiwon Yoon committed
24

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

export default TicketingMovie