Search.js 11.6 KB
Newer Older
1
import React, { useState, useEffect } from 'react';
Kim, Chaerin's avatar
Kim, Chaerin committed
2
3
import { Link, Redirect } from 'react-router-dom';
import ohuh from './ohuh-sm.PNG';
Kim, Chaerin's avatar
Kim, Chaerin committed
4
import Place from './Components/Place';
Lee SeoYeon's avatar
.    
Lee SeoYeon committed
5
import { Container, Form, Row, Col, Card, Image, InputGroup, FormControl, Button, Modal } from 'react-bootstrap';
baesangjune's avatar
style    
baesangjune committed
6
import Paginations from './pagination.js';
Lee SeoYeon's avatar
.    
Lee SeoYeon committed
7
8
import * as Icon from 'react-bootstrap-icons';
import axios from "axios";
Lee SeoYeon's avatar
.    
Lee SeoYeon committed
9

Kim, Chaerin's avatar
Kim, Chaerin committed
10
function Search(props) {
baesangjune's avatar
style    
baesangjune committed
11
    const endPage = 10;
Kim, Chaerin's avatar
Kim, Chaerin committed
12
    const [state, setState] = useState(false);
13
    const [index, setIndex] = useState(1);
14
    const [showSet, setShowSet] = useState([false, false, false, false]);
Kim, Chaerin's avatar
Kim, Chaerin committed
15
    const [search, setSearch] = useState(props.location.state.id);
16
    const [mobile, setMobile] = useState();
Lee SeoYeon's avatar
.    
Lee SeoYeon committed
17
18
19
20
    const [show, setShow] = useState(false);

    const handleClose = () => setShow(false);
    const handleShow = () => setShow(true);
21
22
23
24
25
26

    useEffect(() => {
        if (window.innerWidth < 960) {
            setMobile(true)
        } else {
            setMobile(false)
Lee SeoYeon's avatar
.    
Lee SeoYeon committed
27
        }
28
    }, []);
Kim, Chaerin's avatar
Kim, Chaerin committed
29

30
31
32
    const places = [{
        name: "한라산(hallasan)",
        address: "제주 서귀포시 토평동 산15-1",
Kim, Chaerin's avatar
Kim, Chaerin committed
33
34
        img: "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAOUAAADcCAMAAAC4YpZBAAAAkFBMVEX4ugAAAAD8vQD/vwD/wQAAAAP9vQD2uQCwhAO9jgVAMAbmrANTPwYQDAONaQDQmwN2WQG3iwMy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1e2SfpnMusyExiVAZi9RWC/wlYSFwlVPSsZ0FP1y3fcuKMsL48OUqSRZZlj8SxWrck28zllClEiaEufxUnIk6PAh7ZBNb1mLWiKSPgKvstGUm69QhJLVklnXpU6BDRk4ivQp+h5xlX87jlshaqTJKiHeiYlaqpClZiVkK0WEUi52FndjIBP7sQQOyPoZUqctg+ETqRCBVhmLC7cheNRFFzL4csVK0R75k9pb7E4XKmagw4HEKRJElZrBrCp/RtOWgbgBcZa8zFhwzOYu4yoNQY65IpjLl4AgLw1XK61zlXKXtBoVKQwxjdk5CB0Buzg5mkrTHmlDQLVWewziOnRjUFjtXuZMq+Sqj1w6LcYEPVYIzE6sqm/cjEEP6QjMSPyWvQMFVyu0tkxUFAVxl8lgln4ORt+XLLxk51CZkO9NsX186ISjbSwlXKdWZBzLVIzYUM/VxX8oSHzOaMbI0uXMRy3lJG5MxuKuSr5s9telhcouwMB6ptJKtysLzJetsmkzXskM4m0V/rKeeuyohZGQr/s8SvJUoc65Vaeg1NiPZQu4edcmO0j5ZxfJoU/6vv1dyV6Vh9Qn5tEM3WZNRBA/7Uiw4Wy8MvUDuzDsHMpp4obthpN0M50essVWVc60SfG4F2WjFo2uRDaCsULlSKlNRN0E7cvXhVvfj0PnifoXw3V3u3H0dVkX92suxguO2Mqro5zH/RzxqL4+jTjaTmRLYHU/yp3tcqs8SHCf8cHCUxsLOxqPROBtKXwesGT8cL5thLAX0uhKNXsrMwLRCJ7+en4fqCX0aIA7DuIgwKXXCBpXn/xvfqVy7Crh/+U0QBEEQBEEQBEEQBEEQBEEQBEEQBEEQBEEQBEEQBEEQBEEQBEEQBEEQBEEQBEEQBEGQ/yH/ALoViVlZW8doAAAAAElFTkSuQmCC",
        // img: "https://upload.wikimedia.org/wikipedia/commons/thumb/e/eb/KOCIS_Halla_Mountain_in_Jeju-do_%286387785543%29.jpg/269px-KOCIS_Halla_Mountain_in_Jeju-do_%286387785543%29.jpg?size=200x200",
Lee SeoYeon's avatar
.    
Lee SeoYeon committed
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
        // }, {
        //     name: "성산일출봉(sungsan)",
        //     address: "제주 서귀포시 성산읍 성산리 1",
        //     img: "https://www.jeju.go.kr/pub/site/geopark/images/sub/sub03/02%EC%A7%80%EC%A7%88%EB%A7%88%EC%9D%84%EC%9D%B4%EC%95%BC%EA%B8%B0/%EC%A7%80%EC%A7%88%EB%A7%88%EC%9D%84/%EC%A7%80%EC%A7%88%EB%A7%88%EC%9D%84_%EC%84%B1%EC%82%B0%EC%9D%BC%EC%B6%9C%EB%B4%89/1412402261.jpg?400/400",
        // }, {
        //     name: "해녀의 집(haenyeo)",
        //     address: "제주 서귀포시 성산읍 한도로 141-13지번오조리 3 오조해녀의집",
        //     img: "https://mblogthumb-phinf.pstatic.net/MjAxNjExMTdfMTc0/MDAxNDc5MzU3ODU0ODQy.KZYXCjzsXT3rCsE4HXBfxyCg2buvluBvN_7NxVp7BSwg.loJc89d8JjGXdNCn-4yMd7aMWPjfrZn21TI9Hyzemkog.JPEG.icocam11/20161010_100205.jpg?type=w800",
        // }, {
        //     name: "오설록 티 뮤지엄(osulloc)",
        //     address: "제주 서귀포시 안덕면 신화역사로 15 오설록지번서광리 1235-1 오설록",
        //     img: "https://cdnweb01.wikitree.co.kr/webdata/editor/202007/01/img_20200701143323_2ced7627.webp",
        // }, {
        //     name: "오설록 티 뮤지엄(osulloc)",
        //     address: "제주 서귀포시 안덕면 신화역사로 15 오설록지번서광리 1235-1 오설록",
        //     img: "https://upload.wikimedia.org/wikipedia/commons/thumb/e/eb/KOCIS_Halla_Mountain_in_Jeju-do_%286387785543%29.jpg/269px-KOCIS_Halla_Mountain_in_Jeju-do_%286387785543%29.jpg",
51
    }]
Kim, Chaerin's avatar
Kim, Chaerin committed
52
53
54

    if (state !== false) {
        return <Redirect to={{
Lee SeoYeon's avatar
.    
Lee SeoYeon committed
55
56
            pathname: `/search/${search}`,
            state: { id: search },
Kim, Chaerin's avatar
Kim, Chaerin committed
57
        }} />;
Lee SeoYeon's avatar
.    
Lee SeoYeon committed
58
    }
Kim, Chaerin's avatar
Kim, Chaerin committed
59

baesangjune's avatar
style    
baesangjune committed
60
61
62
63
    const handlePage = (num) => {
        setIndex(num);
    }

Lee SeoYeon's avatar
.    
Lee SeoYeon committed
64
65
66
    // async function bookmarkSave() {
    //     await axios.put('/api/users', {userId:userId, bookmarkId:bookmarkId})
    // }
baesangjune's avatar
style    
baesangjune committed
67

Lee SeoYeon's avatar
.    
Lee SeoYeon committed
68
    const handleChange = (e) => {
Kim, Chaerin's avatar
Kim, Chaerin committed
69
70
        setSearch(e.target.value);
    }
Kim, Chaerin's avatar
Kim, Chaerin committed
71

Kim, Chaerin's avatar
Kim, Chaerin committed
72
    const handleSubmit = (e) => {
Kim, Chaerin's avatar
Kim, Chaerin committed
73
        setState(true);
Kim, Chaerin's avatar
Kim, Chaerin committed
74
    }
75

Kim, Chaerin's avatar
Kim, Chaerin committed
76
    function paginate(items, pageNumber, itemNumber) {
77
        const page = [];
Kim, Chaerin's avatar
Kim, Chaerin committed
78
79
        const startIndex = (pageNumber - 1) * itemNumber
        for (var i = 0; i < itemNumber; i++) {
80
81
82
83
84
            page.push(items[(startIndex + i)])
        }
        return page
    }

Kim, Chaerin's avatar
Kim, Chaerin committed
85
    const pagePlace = paginate(places, index, 1)
Lee SeoYeon's avatar
.    
Lee SeoYeon committed
86

Lee SeoYeon's avatar
.    
Lee SeoYeon committed
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
    return (
        <Container >
            <Link to="/" className="d-flex justify-content-center"><Image src={ohuh} /></Link>
            <Row className="mb-2" className="d-flex justify-content-center">
                <Form style={{ width: "90vw" }} onSubmit={handleSubmit}>
                    <InputGroup size="lg">
                        <Link to="/">
                            <Col>
                                {/* <Image src={ohuh} fluid width="130px" /> */}
                            </Col>
                        </Link>
                        <FormControl
                            placeholder="검색어를 입력하세요."
                            value={search}
                            aria-label="Large"
                            aria-describedby="inputGroup-sizing-sm"
                            onChange={handleChange}
                        />
                        <InputGroup.Append>
                            <Button type="submit" variant="outline-secondary" style={{ maxHeight: "8vh", maxWidth: "14vh" }} >검색</Button>
                        </InputGroup.Append>
                    </InputGroup>
                </Form>
            </Row>
            <Row className="d-flex flex-wrap">
                {pagePlace.map((place, index) => {
                    return (
                        <Col key={index} md={6} >
                            <Card align="center" border="info" style={{ margin: "3%" }}>
                                <Button variant="outline-info" style={{ marginLeft: "60vh" }} onClick={handleShow}><Icon.BookmarkStar size={30} />  <Modal
                                    show={show}
                                    onHide={handleClose}
                                    backdrop="static"
                                    keyboard={false}
                                >
                                    <Modal.Header closeButton>
                                        <Modal.Title id="contained-modal-title-vcenter" style={{ fontSize: '30px' }}>북마크 추가됨
                                        </Modal.Title>
                                    </Modal.Header><Form>
                                        <Form.Group controlId="formBasicEmail">
                                            <Form.Label style={{ fontSize: '20px' }}>이름</Form.Label>
                                            <Form.Control type="email" />
                                            <Form.Text className="text-muted">
                                            </Form.Text>
                                        </Form.Group>

                                        {/* <Form.Group controlId="formBasicPassword">
                                            <Form.Label style={{ fontSize: '20px' }}>폴더</Form.Label>
                                            <Form.Control type="password" placeholder="Password" />
                                        </Form.Group> */}
                                        <Modal.Footer>
                                            <Button variant="primary" type="submit">저장</Button>
                                            <Button onClick={props.onHide}>삭제</Button>
                                        </Modal.Footer>
                                    </Form></Modal></Button>
                                <Card.Title style={{ margin: "3%", fontSize: '200%', fontWeight: 'bold' }}>{place.name}
                                </Card.Title>
                                <Card.Img variant="top" style={{ padding: "5%", width: "100%", height: "340px" }} src={place.img} />
                                <Card.Body >
                                    <Card.Text style={{ overflow: 'auto', fontSize: '25px', width: '100%', height: "80px" }} >
                                        {place.address} </Card.Text>
                                    <Button variant="primary" onClick={() => {
                                        const showArr = [false, false, false, false]
                                        showArr[index] = true
                                        setShowSet(showArr)
                                    }}>{place.name} 자세히 살펴보기</Button>
                                    <Place search={place} index={index} show={showSet[index]} onHide={() => setShowSet([false, false, false, false])} />
                                </Card.Body>
155
156
                            </Card>
                        </Col>
157
158
                    )
                })}
Kim, Chaerin's avatar
Kim, Chaerin committed
159
            </Row>
Lee SeoYeon's avatar
.    
Lee SeoYeon committed
160
161
162
163
164
            { console.log(showSet)}
            {/* show가 전부 true로 바뀌어서 전부 다 보이게 되는 것이다. */}
            <Row className="mt-2 d-flex justify-content-center">
                <Paginations index={index} endPage={endPage} handlePage={handlePage}></Paginations>
            </Row>
Kim, Chaerin's avatar
Kim, Chaerin committed
165
        </Container>
166

Kim, Chaerin's avatar
Kim, Chaerin committed
167
168
169
    );
}

Lee SeoYeon's avatar
.    
Lee SeoYeon committed
170
export default Search