TheaterInfo.js 6.59 KB
Newer Older
Jiwon Yoon's avatar
Jiwon Yoon committed
1
import { useRef, useState, useEffect } from 'react'
Jiwon Yoon's avatar
Jiwon Yoon committed
2
3
import axios from "axios"
import catchErrors from "../utils/catchErrors"
4
// import InfoModal from "./InfoModal"
Jiwon Yoon's avatar
Jiwon Yoon committed
5
6
7
8
9
const { kakao } = window;
const options = {
    center: new kakao.maps.LatLng(37.365264512305174, 127.10676860117488),
    level: 3
};
Jiwon Yoon's avatar
Jiwon Yoon committed
10
const TheaterInfo = () => {
Jiwon Yoon's avatar
Jiwon Yoon committed
11
12
    const container = useRef(null)
    const [cinemaInfo, setCinemaInfo] = useState()
13
14
15
16
17
    const [currentInfo, setCurrentInfo] = useState({
        name: "init",
        title: "init",
        information: "init"
    })
Jiwon Yoon's avatar
Jiwon Yoon committed
18
    const [error, setError] = useState()
19
    const [tabContent, setTabContent] = useState([])
Jiwon Yoon's avatar
Jiwon Yoon committed
20
21
22
23
    useEffect(() => {
        getTheaterInfo()
    }, [])

24
    useEffect(() => {
Jiwon Yoon's avatar
Jiwon Yoon committed
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
        if (currentInfo.title === "address") {
            // 지도를 담을 영역의 DOM 레퍼런스
            const container = document.getElementById("map");
            // center옵션은 지도를 생성하는데 반드시 필요하며 파라미터는 위경도좌표이다. (위도,경도 순서)
            // level옵션은 지도의 확대, 축소 정도이다.
            const options = {
                center: new kakao.maps.LatLng(33.450701, 126.570667),
                level: 3,
            };
            // 지도 생성 및 객체 리턴
            const map = new kakao.maps.Map(container, options);
            const geocoder = new kakao.maps.services.Geocoder();
            // 주소로 좌표를 검색합니다
            geocoder.addressSearch(`${cinemaInfo.address}`, function (result, status) {
                // 정상적으로 검색이 완료됐으면 
                if (status === kakao.maps.services.Status.OK) {
                    const coords = new kakao.maps.LatLng(result[0].y, result[0].x);
                    // 결과값으로 받은 위치를 마커로 표시합니다
                    const marker = new kakao.maps.Marker({
                        map: map,
                        position: coords
                    });
                    // 인포윈도우로 장소에 대한 설명을 표시합니다
                    const infowindow = new kakao.maps.InfoWindow({
                        content: '<div style="color:black; width:150px;text-align:center;padding:6px 0;">Butter Studio</div>'
                    });
                    infowindow.open(map, marker);
                    // 지도의 중심을 결과값으로 받은 위치로 이동시킵니다
                    map.setCenter(coords);
                }
            });
56
        }
Jiwon Yoon's avatar
Jiwon Yoon committed
57
    }, [currentInfo]);
58

Jiwon Yoon's avatar
Jiwon Yoon committed
59
60
61
    async function getTheaterInfo() {
        try {
            const response = await axios.get('/api/info/cinema')
62
            const response2 = await axios.get('/api/theater')
Jiwon Yoon's avatar
Jiwon Yoon committed
63
            setCinemaInfo({ ...response.data, theaterNum: response2.data.length })
64
            setCurrentInfo({
Jiwon Yoon's avatar
Jiwon Yoon committed
65
66
                name: "대중교통 안내",
                title: "transportation",
67
68
                information: response.data.transportation
            })
Jiwon Yoon's avatar
Jiwon Yoon committed
69
        } catch (error) {
70
            catchErrors(error, setError)
Jiwon Yoon's avatar
Jiwon Yoon committed
71
72
73
        }
    }

74
75
76
77
78
79
80
81
82
    function handleClick(e) {
        setCurrentInfo({
            name: e.target.name,
            title: e.target.id,
            information: e.target.value
        })
    }


Jiwon Yoon's avatar
Jiwon Yoon committed
83
84
    return (
        <>
Jiwon Yoon's avatar
Jiwon Yoon committed
85
            {cinemaInfo ?
86
87
                <div>
                    {/* {console.log(currentInfo)} */}
Jiwon Yoon's avatar
Jiwon Yoon committed
88
89
                    {console.log(cinemaInfo)}
                    <h2 className="m-5">{cinemaInfo.cinemaName}</h2>
90
91
92
                    <div className="my-3 text-center">
                        <img src="/images/movieTheater.jpg" style={{ width: "80%" }} />
                    </div>
Jiwon Yoon's avatar
Jiwon Yoon committed
93
94
                    <div className="m-3"> 상영관 : {cinemaInfo.theaterNum}</div>
                    <div className="m-3">{cinemaInfo.address}</div>
95
96
97
98
                    <div className="row justify-content-sm-center py-5">
                        <div className="col-sm-4 text-end">
                            <div className="m-2">
                                <img src="/images/icon-bus.png" style={{ width: "35px" }} />
Jiwon Yoon's avatar
Jiwon Yoon committed
99
                                <button className="px-3" name="대중교통 안내" id="transportation" value={cinemaInfo.transportation} type="button" onClick={handleClick} style={{ background: "black", borderLeftColor: "black", borderTopColor: "black", borderBottomColor: "black", color: "white", borderRightColor: currentInfo.title === "transportation" ? "white" : "black" }}>대중교통 안내
100
101
102
103
                                </button>
                            </div>
                            <div className="m-2">
                                <img src="/images/icon-car.png" style={{ width: "35px" }} />
Jiwon Yoon's avatar
Jiwon Yoon committed
104
                                <button className="px-3" name="자가용/주차 안내" id="parking" value={cinemaInfo.parking} type="button" onClick={handleClick} style={{ background: "black", borderLeftColor: "black", borderTopColor: "black", borderBottomColor: "black", color: "white", borderRightColor: currentInfo.title === "parking" ? "white" : "black" }}>자가용/주차 안내
105
106
107
108
                                </button>
                            </div>
                            <div className="m-2">
                                <img src="/images/icon-map.png" style={{ width: "35px" }} />
Jiwon Yoon's avatar
Jiwon Yoon committed
109
                                <button className="px-3" name="지도보기" id="address" value={cinemaInfo.address} type="button" onClick={handleClick} style={{ background: "black", borderLeftColor: "black", borderTopColor: "black", borderBottomColor: "black", color: "white", borderRightColor: currentInfo.title === "address" ? "white" : "black" }}>지도보기
110
111
112
113
114
                                </button>
                            </div>
                        </div>
                        <div className="col-sm-6">
                            <div className="m-2">
Jiwon Yoon's avatar
Jiwon Yoon committed
115
116
117
                                <div id="parking" style={{ display: currentInfo.title === "parking" ? 'block' : 'none' }}>{currentInfo.information}</div>
                                <div id="map" ref={container} style={{ width: "400px", height: "300px", display: currentInfo.title === "address" ? 'block' : 'none' }}></div>
                                <div id="transportaion" style={{ display: currentInfo.title === "transportation" ? 'block' : 'none' }} >{currentInfo.information}</div>
118
119
120
121
122
123
124
125
126
                            </div>
                        </div>
                    </div>
                    <div id="map"></div>
                </div>
                :
                <div>
                    극장정보를 불러올  없습니다.
                </div>}
Jiwon Yoon's avatar
Jiwon Yoon committed
127
128
129
130
131
        </>
    )
}

export default TheaterInfo