MenuPage.js
7.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
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
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
import React, { useState, useEffect } from 'react';
import NavBar from '../components/NavBar';
import MealCard from '../components/MealCard';
import { CustomInput } from 'reactstrap';
import { Container, Row, Col } from "reactstrap";
import axios from 'axios';
import Loading from '../components/Loading';
import './MenuPage.css';
const MenuPage = (props) => {
const [datas, setDatas] = useState([]);
const [filteredDatas, setFilteredDatas] = useState([]);
const [isLoading, setIsLoading] = useState(false);
const [all, setAll] = useState(false);
const [Kfood, setKfood] = useState(false);
const [Cfood, setCfood] = useState(false);
const [Jfood, setJfood] = useState(false);
const [meat, setMeat] = useState(false);
const [snackfood, setSnackfood] = useState(false);
const [pub, setPub] = useState(false);
const [fastfood, setFastfood] = useState(false);
const [cafe, setCafe] = useState(false);
const [etc, setEtc] = useState(false);
useEffect(() => {
const fetchData = async () => {
const result = await axios(
'http://localhost:5000/api/datas',
// localhost로 바꾸기
);
setDatas(result.data);
setIsLoading(true);
};
fetchData();
}, []);
// filtereddatas 처리 + isloading변경
useEffect(() => {
setIsLoading(false);
let result = [];
const states = [Kfood, Cfood, Jfood, meat, snackfood, pub, fastfood, cafe, etc];
const types = [['한식'], ['중식'], ['일식'], ['고기'], ['분식'], ['호프', '술집'], ['패스트푸드'], ['카페', '디저트'], ['기타']];
for(let i = 0; i < states.length; i++) {
if(states[i] === true) {
const temp = types[i];
for(let j = 0; j < datas.length; j++) {
for(let k = 0; k < temp.length; k++) {
if(datas[j].type === temp[k]) {
result.push(datas[j]);
}
}
}
}
}
setFilteredDatas(result);
setIsLoading(true);
}, [Kfood, Cfood, Jfood, meat, snackfood, pub, fastfood, cafe, etc]);
useEffect(() => {
if(all === true) {
setKfood(true);
setCfood(true);
setJfood(true);
setMeat(true);
setSnackfood(true);
setPub(true);
setFastfood(true);
setCafe(true);
setEtc(true);
}
else {
setKfood(false);
setCfood(false);
setJfood(false);
setMeat(false);
setSnackfood(false);
setPub(false);
setFastfood(false);
setCafe(false);
setEtc(false);
}
}, [all]);
return (
<>
<NavBar/>
<Container style={{
paddingTop : '1.5rem'
}}>
<Row>
<Col>
<CustomInput type="switch" id="all" label="전체"
checked={all}
onChange={()=> setAll(!all)}
/>
</Col>
</Row>
<Row xs="3" sm="3" md="5">
<Col>
<CustomInput type="checkbox" id="Kfood" label="한식"
checked={Kfood}
onChange={()=>setKfood(!Kfood)}
/>
</Col>
<Col>
<CustomInput type="checkbox" id="Cfood" label="중식"
checked={Cfood}
onChange={()=>setCfood(!Cfood)}
/>
</Col>
<Col>
<CustomInput type="checkbox" id="Jfood" label="일식"
checked={Jfood}
onChange={()=>setJfood(!Jfood)}
/>
</Col>
<Col>
<CustomInput type="checkbox" id="meat" label="고기"
checked={meat}
onChange={()=>setMeat(!meat)}
/>
</Col>
<Col>
<CustomInput type="checkbox" id="snackfood" label="분식"
checked={snackfood}
onChange={()=>setSnackfood(!snackfood)}
/>
</Col>
<Col>
<CustomInput type="checkbox" id="pub" label="호프/술집"
checked={pub}
onChange={()=>setPub(!pub)}
/>
</Col>
<Col>
<CustomInput type="checkbox" id="fastfood" label="패스트푸드"
checked={fastfood}
onChange={()=>setFastfood(!fastfood)}
/>
</Col>
<Col>
<CustomInput type="checkbox" id="cafe" label="카페/디저트"
checked={cafe}
onChange={()=>setCafe(!cafe)}
/>
</Col>
<Col>
<CustomInput type="checkbox" id="etc" label="기타"
checked={etc}
onChange={()=>setEtc(!etc)}
/>
</Col>
</Row>
</Container>
<Container>
{/* ???????? ???? */}
{/* <FormGroup>
<Label for="exampleCheckbox">??</Label>
<div>
<CustomInput type="checkbox" id="exampleCustomInline" label="??" inline />
</div>
</FormGroup> */}
</Container>
{isLoading ?
(<Container style={{'paddingTop':'1.2rem'}}>
<Row xs="2" sm="2" md="4">
{filteredDatas.map((data, index) =>
<Col>
<MealCard
key = {index}
id = {data.id}
name = {data.name}
address = {data.address}
latitude = {data.latitude}
longitude = {data.longitude}
type = {data.type}
menu = {data.menu}
img = {data.img}
img_source = {data.img_source}
/>
</Col>
)
}
</Row>
</Container>)
: <Loading/>
}
</>
);
}
export default MenuPage;