UserCards.js
2.14 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
import React, { useState, useEffect } from 'react';
import { Container, Row, Col, Button } from 'reactstrap';
import PickedCard from '../components/PickedCard';
const UserCards = (props) => {
const [username, setUsername] = useState('User');
const [picks, setPicks] = useState([]);
const authApi = () => {
const user = JSON.parse(localStorage.getItem('user'));
return fetch('/api/mypicks', {
method: 'GET',
headers: {
'Content-Type': 'application/json',
'authorization': user
}
}).then(response => response.json())
.then( result => {
setPicks(result.datas);
}
);
}
useEffect(() => {
setUsername(props.username);
authApi();
}, [username, props]);
const LogoutHandler = (e) => {
e.preventDefault();
localStorage.removeItem('user');
props.isLogin(false);
return ;
}
return (
<>
<h1 style={{'paddingTop':'3rem'}} className="text-center">
<div className="font-weight-bold">{username}'s Pick</div>
<Button onClick={LogoutHandler} color="link" className="float-right"><h4>Logout</h4></Button>
</h1>
<br/>
<hr className="my-2" />
<br/>
<Container style={{'paddingTop':'1.2rem'}}>
<Row xs="2" sm="2" md="4">
{picks.map((data, index) =>
<Col key = {index}>
<PickedCard
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>
</>
)
}
export default UserCards;