MealCard.js
4.01 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
import React, { useState } from 'react';
import { Card, CardBody, CardTitle, CardText, CardImg, CardFooter, Button } from 'reactstrap';
import { Modal, ModalHeader, ModalBody, ModalFooter } from 'reactstrap';
import Map from './Map';
import './MealCard.css';
import { faAngleRight } from "@fortawesome/free-solid-svg-icons"
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome"
const MealCard = (props) => {
const [modal, setModal] = useState(false);
const toggleModal = () => setModal(!modal);
const authApi = () => {
const user = JSON.parse(localStorage.getItem('user'));
if(!user) {
alert('로그인이 필요합니다.');
window.location.href = "/mypick";
return ;
}
return fetch('/api/auth', {
method: 'GET',
headers: {
'Content-Type': 'application/json',
'authorization': user
}
}).then(response => response.json())
.then(result => {
if(result.message === 'valid token') {
return fetch('/api/pick', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'authorization': user
},
body: JSON.stringify({
"cardid":props.id
})
}).then(response => response.json())
.then(result => {
if(result.message === 'insertion success') {
alert('MyPick에 담겼습니다.');
} else if(result.message === 'card exist') {
alert('이미 MyPick에 존재합니다.');
} else {
alert('error');
}
});
} else {
alert('로그인이 필요합니다.');
window.location.href = "/mypick";
}
});
}
const pickHandler = (e) => {
e.preventDefault();
authApi();
}
return (
<>
<Card style={{
'marginTop': '0.6rem',
'marginBottom': '0.6rem',
'boxShadow': '0 4px 8px 0 rgba(0, 0, 0, 0.2), 0 6px 20px 0 rgba(0, 0, 0, 0.19)'
}}>
<CardImg
top width="100%"
src={props.img} alt="Card image cap" />
<CardBody>
<CardTitle><strong>{props.name}</strong></CardTitle>
<CardText>
<small>{props.menu}</small>
</CardText>
</CardBody>
<CardFooter className="wrap" style={{
'padding': '0 0 0 0'
}}>
<Button
onClick={toggleModal}
className="button"
style={{
'width':'100%',
'borderRadius':'0 0 0 0',
'backgroundColor': '#F6F6F6',
'border': '0px',
'color':'black'
}}>
<span style={{
'float':'left',
'fontSize': '14px'
}}>
view more
</span>
<FontAwesomeIcon style={{
'color': 'black',
'float': 'right',
'paddingTop':'0.1rem'
}}
size="lg" icon={faAngleRight} />
</Button>
</CardFooter>
</Card>
<Modal size="lg" className="modalClass" isOpen={modal} toggle={toggleModal}>
<ModalHeader toggle={toggleModal}>{props.name}</ModalHeader>
<ModalBody>
주소
<hr className="my-2"/>
{props.address}
<br/>
<Map
latitude = {props.latitude}
longitude = {props.longitude}
/>
</ModalBody>
<ModalFooter>
<div style={{
width:'100%',
overflow:'hidden',
wordWrap:'break-word'
}}>
<small>
썸네일 출처
<hr className="my-2"/>
{props.img_source} <Button onClick={pickHandler} size="sm" className="float-right" color="warning">Pick!</Button>
</small>
</div>
</ModalFooter>
</Modal>
</>
);
};
export default MealCard;