TheaterInfo.js 5.84 KB
Newer Older
Jiwon Yoon's avatar
Jiwon Yoon committed
1
import { useRef, useState, useEffect } from 'react'
Kim, Subin's avatar
Kim, Subin committed
2
3
import cinemaApi from "../apis/cinema.api,js"
import theaterApi from "../apis/theater.api.js"
Jiwon Yoon's avatar
Jiwon Yoon committed
4
import catchErrors from "../utils/catchErrors"
Kim, Subin's avatar
Kim, Subin committed
5

Jiwon Yoon's avatar
Jiwon Yoon committed
6
7
8
9
10
const { kakao } = window;
const options = {
    center: new kakao.maps.LatLng(37.365264512305174, 127.10676860117488),
    level: 3
};
Kim, Subin's avatar
Kim, Subin committed
11

Jiwon Yoon's avatar
Jiwon Yoon committed
12
const TheaterInfo = () => {
Jiwon Yoon's avatar
Jiwon Yoon committed
13
14
    const container = useRef(null)
    const [cinemaInfo, setCinemaInfo] = useState()
15
16
17
18
19
    const [currentInfo, setCurrentInfo] = useState({
        name: "init",
        title: "init",
        information: "init"
    })
Jiwon Yoon's avatar
Jiwon Yoon committed
20
    const [error, setError] = useState()
21
    const [tabContent, setTabContent] = useState([])
Jiwon Yoon's avatar
Jiwon Yoon committed
22
23
24
25
    useEffect(() => {
        getTheaterInfo()
    }, [])

26
    useEffect(() => {
Jiwon Yoon's avatar
Jiwon Yoon committed
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
        if (currentInfo.title === "address") {
            const container = document.getElementById("map");
            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);
                }
            });
49
        }
Jiwon Yoon's avatar
Jiwon Yoon committed
50
    }, [currentInfo]);
51

Jiwon Yoon's avatar
Jiwon Yoon committed
52
53
    async function getTheaterInfo() {
        try {
Kim, Subin's avatar
Kim, Subin committed
54
55
            const response = await cinemaApi.getCinemaInfo()
            const response2 = await theaterApi.getAll()
Jiwon Yoon's avatar
Jiwon Yoon committed
56
            setCinemaInfo({ ...response.data, theaterNum: response2.data.length })
57
            setCurrentInfo({
Jiwon Yoon's avatar
Jiwon Yoon committed
58
59
                name: "대중교통 안내",
                title: "transportation",
60
61
                information: response.data.transportation
            })
Jiwon Yoon's avatar
Jiwon Yoon committed
62
        } catch (error) {
63
            catchErrors(error, setError)
Jiwon Yoon's avatar
Jiwon Yoon committed
64
65
66
        }
    }

67
68
69
70
71
72
73
74
    function handleClick(e) {
        setCurrentInfo({
            name: e.target.name,
            title: e.target.id,
            information: e.target.value
        })
    }

Jiwon Yoon's avatar
Jiwon Yoon committed
75
76
    return (
        <>
Jiwon Yoon's avatar
Jiwon Yoon committed
77
            {cinemaInfo ?
78
                <div>
Jiwon Yoon's avatar
Jiwon Yoon committed
79
                    <h2 className="m-5">{cinemaInfo.cinemaName}</h2>
80
81
82
                    <div className="my-3 text-center">
                        <img src="/images/movieTheater.jpg" style={{ width: "80%" }} />
                    </div>
Jiwon Yoon's avatar
Jiwon Yoon committed
83
84
                    <div className="m-3"> 상영관 : {cinemaInfo.theaterNum}</div>
                    <div className="m-3">{cinemaInfo.address}</div>
85
86
87
88
                    <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
89
                                <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" }}>대중교통 안내
90
91
92
93
                                </button>
                            </div>
                            <div className="m-2">
                                <img src="/images/icon-car.png" style={{ width: "35px" }} />
Jiwon Yoon's avatar
Jiwon Yoon committed
94
                                <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" }}>자가용/주차 안내
95
96
97
98
                                </button>
                            </div>
                            <div className="m-2">
                                <img src="/images/icon-map.png" style={{ width: "35px" }} />
Jiwon Yoon's avatar
Jiwon Yoon committed
99
                                <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" }}>지도보기
100
101
102
103
104
                                </button>
                            </div>
                        </div>
                        <div className="col-sm-6">
                            <div className="m-2">
Jiwon Yoon's avatar
Jiwon Yoon committed
105
106
107
                                <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>
108
109
110
111
112
113
114
115
116
                            </div>
                        </div>
                    </div>
                    <div id="map"></div>
                </div>
                :
                <div>
                    극장정보를 불러올  없습니다.
                </div>}
Jiwon Yoon's avatar
Jiwon Yoon committed
117
118
119
120
121
        </>
    )
}

export default TheaterInfo