BodyLayout.js
2.2 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
import React, { useState, useEffect } from "react";
import { makeStyles } from "@material-ui/core/styles";
import Container from "@material-ui/core/Container";
import Grid from "@material-ui/core/Grid";
import Typography from "@material-ui/core/Typography";
import Icon from "@material-ui/core/Icon";
// import CircularProgress from "@material-ui/core/CircularProgress";
import TodoCard from "./TodoCard.js";
const useStyles = makeStyles((theme) => ({
root: {
minHeight: "100vh",
backgroundColor: "rgba(0,0,0,0.5)",
},
container: {
flexGrow: 1,
paddingTop: "4rem",
paddingBottom: "1rem",
marginLeft: "auto",
marginRight: "auto",
},
}));
export default function BodyLayout() {
const classes = useStyles();
const [data, setData] = useState([]);
const [isLoading, setIsLoading] = useState(1);
const callApi = async () => {
const response = await fetch("/api/cards");
const body = await response.json();
return body.reverse();
};
useEffect(() => {
callApi()
.then((res) => {
setData(res);
setIsLoading(0);
})
.catch((err) => console.log(err));
}, []);
if (isLoading) {
return <></>;
} else {
return (
<div className={classes.root}>
<Container className={classes.container} maxwidth="md">
<Grid className={classes.item} container>
{data.map((card, idx) => {
if (idx===0 || card.date !== data[idx - 1].date) {
return (
<>
<Typography variant="h4" style={{width:"100%", color:"white"}}>{card.date}</Typography>
<Grid item xs={6} sm={6} md={3}>
<TodoCard key={card.id} data={card} />
</Grid>
</>
);
} else {
return (
<Grid item xs={6} sm={6} md={3}>
<TodoCard key={card.id} data={card} />
</Grid>
);
}
})}
{/* <Grid item xs={6} sm={6} md={3}>
<Icon style={{ fontSize: 60 }}>add_circle</Icon>
</Grid> */}
</Grid>
</Container>
</div>
);
}
}