김대휘

Api test

...@@ -32,5 +32,6 @@ ...@@ -32,5 +32,6 @@
32 "last 1 firefox version", 32 "last 1 firefox version",
33 "last 1 safari version" 33 "last 1 safari version"
34 ] 34 ]
35 - } 35 + },
36 + "proxy": "http://localhost:5000/"
36 } 37 }
......
1 -import React from "react"; 1 +import React, { useState, useEffect } from "react";
2 import NavBar from "./components/NavBar.js"; 2 import NavBar from "./components/NavBar.js";
3 import BodyLayout from "./components/BodyLayout.js"; 3 import BodyLayout from "./components/BodyLayout.js";
4 4
......
1 -import React from "react"; 1 +import React, { useState, useEffect } from "react";
2 +
2 import { makeStyles } from "@material-ui/core/styles"; 3 import { makeStyles } from "@material-ui/core/styles";
3 import Container from "@material-ui/core/Container"; 4 import Container from "@material-ui/core/Container";
4 import Grid from "@material-ui/core/Grid"; 5 import Grid from "@material-ui/core/Grid";
...@@ -6,14 +7,6 @@ import Icon from "@material-ui/core/Icon"; ...@@ -6,14 +7,6 @@ import Icon from "@material-ui/core/Icon";
6 7
7 import TodoCard from "./TodoCard.js"; 8 import TodoCard from "./TodoCard.js";
8 9
9 -const data = {
10 - date: "2020-99-99",
11 - name: "daehwi",
12 - isPublic: true,
13 - title: "열글자까지가능합니다.",
14 - todo: ["응가하기", "똥싸기", "변누기"],
15 -};
16 -
17 const useStyles = makeStyles((theme) => ({ 10 const useStyles = makeStyles((theme) => ({
18 root: { 11 root: {
19 flexGrow: 1, 12 flexGrow: 1,
...@@ -27,19 +20,42 @@ const useStyles = makeStyles((theme) => ({ ...@@ -27,19 +20,42 @@ const useStyles = makeStyles((theme) => ({
27 }, 20 },
28 })); 21 }));
29 22
30 -export default function CenteredGrid() { 23 +const callApi = async () => {
24 + const response = await fetch("/api/cards");
25 + const body = await response.json();
26 + return body;
27 +};
28 +
29 +export default function BodyLayout() {
31 const classes = useStyles(); 30 const classes = useStyles();
31 + const [data, setData] = useState([]);
32 32
33 - return ( 33 + useEffect(() => {
34 - <Container className={classes.root} maxwidth="sm"> 34 + callApi()
35 - <Grid className={classes.item} container spacing={3}> 35 + .then((res) => setData(res))
36 - <Grid item xs="6" sm="6" md="3"> 36 + .catch((err) => console.log(err));
37 - <TodoCard data={data} /> 37 + });
38 - </Grid> 38 +
39 - <Grid item xs="6" sm="6" md="3" alignItems="center"> 39 + if (!data) {
40 - <Icon style={{ fontSize: 60 }}>add_circle</Icon> 40 + return <p>ㄱㄷㄱㄷ</p>;
41 + } else {
42 + console.log(123);
43 + console.log(data);
44 + return (
45 + <Container className={classes.root} maxwidth="sm">
46 + <Grid className={classes.item} container spacing={3}>
47 + {data.map((data) => {
48 + return (
49 + <Grid item xs="6" sm="6" md="3">
50 + <TodoCard data={data} />
51 + </Grid>
52 + );
53 + })}
54 + <Grid item xs="6" sm="6" md="3">
55 + <Icon style={{ fontSize: 60 }}>add_circle</Icon>
56 + </Grid>
41 </Grid> 57 </Grid>
42 - </Grid> 58 + </Container>
43 - </Container> 59 + );
44 - ); 60 + }
45 } 61 }
......
...@@ -37,6 +37,7 @@ const useStyles = makeStyles({ ...@@ -37,6 +37,7 @@ const useStyles = makeStyles({
37 export default function TodoCard(props) { 37 export default function TodoCard(props) {
38 const classes = useStyles(); 38 const classes = useStyles();
39 const data = props.data; 39 const data = props.data;
40 + console.log(data);
40 return ( 41 return (
41 <Card className={classes.root}> 42 <Card className={classes.root}>
42 <CardContent> 43 <CardContent>
......
...@@ -2,9 +2,4 @@ import React from "react"; ...@@ -2,9 +2,4 @@ import React from "react";
2 import ReactDOM from "react-dom"; 2 import ReactDOM from "react-dom";
3 import App from "./App"; 3 import App from "./App";
4 4
5 -ReactDOM.render( 5 +ReactDOM.render(<App />, document.getElementById("root"));
6 - <React.StrictMode>
7 - <App />
8 - </React.StrictMode>,
9 - document.getElementById("root")
10 -);
......
...@@ -12,6 +12,5 @@ ...@@ -12,6 +12,5 @@
12 }, 12 },
13 "devDependencies": { 13 "devDependencies": {
14 "concurrently": "^4.0.1" 14 "concurrently": "^4.0.1"
15 - }, 15 + }
16 - "proxy": "http://localhost:5000/"
17 } 16 }
......
1 -const express = require('express'); 1 +const express = require("express");
2 -const bodyParser = require('body-parser'); 2 +const bodyParser = require("body-parser");
3 const app = express(); 3 const app = express();
4 const port = process.env.PORT || 5000; 4 const port = process.env.PORT || 5000;
5 app.use(bodyParser.json()); 5 app.use(bodyParser.json());
6 app.use(bodyParser.urlencoded({ extended: true })); 6 app.use(bodyParser.urlencoded({ extended: true }));
7 7
8 -app.get('/api/hello', (req, res) => { 8 +app.get("/api/cards", (req, res) => {
9 -res.send({ message: 'Hello Express!' }); 9 + res.send([
10 + {
11 + date: "2020-99-99",
12 + name: "daehwi",
13 + isPublic: true,
14 + title: "열글자까지가능합니다.",
15 + todo: ["응가하기", "똥싸기", "변누기"],
16 + },
17 + {
18 + date: "2020-99-99",
19 + name: "fuck",
20 + isPublic: true,
21 + title: "열글자까지가능합니다.",
22 + todo: ["응가하다말기", "똥싸기", "변누기"],
23 + },
24 + {
25 + date: "2020-99-99",
26 + name: "성훈",
27 + isPublic: true,
28 + title: "열글자까지가능할걸요.",
29 + todo: ["응가하면서폰보기", "똥싸기", "변누기"],
30 + },
31 + ]);
10 }); 32 });
11 33
12 -app.listen(port, () => console.log(`Listening on port ${port}`));
...\ No newline at end of file ...\ No newline at end of file
34 +app.listen(port, () => console.log(`Listening on port ${port}`));
......