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
6
7
8
9
10
11
12
13
14
15
16
17
18
19
const TicketingMovie = (props) => {
    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
        props.setTicketInfo({...props.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
27
28
        <div >
            {console.log(props.ticketInfo.movieId)}
            <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
32
33
                        <button name={movie.id} className={`${props.ticketInfo.movieId == movie.id ? styles.on : styles.btn}`} onClick={handleClick}>
                            {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