Board.js
1.44 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
import React, { useState, useEffect, useContext } from "react";
import { SignApi } from "../utils/api";
import { useHistory } from "react-router-dom";
import Container from "@material-ui/core/Container";
import MediaCard from "../components/board/Card";
import NewCard from "../components/board/NewCard";
import { makeStyles } from "@material-ui/core/styles";
import userContext from "../utils/context";
const useStyles = makeStyles((theme) => ({
container: {
display: "grid",
gridTemplateColumns: "1fr 1fr 1fr 1fr",
background: "white",
marginTop: "40px",
},
}));
const Board = () => {
const classes = useStyles();
const [projects, setProjects] = useState([]);
const { data, setData } = useContext(userContext);
const history = useHistory();
const handleClick = (imageUrl) => {
history.push("editor");
setData({ ...data, editingImageUrl: imageUrl });
};
const getInitialData = async () => {
const { projects } = await SignApi("http://localhost:9000/projects", {
method: "GET",
});
setProjects(projects);
};
useEffect(() => {
getInitialData();
}, []);
return (
<Container maxWidth="lg" className={classes.container}>
<NewCard />
{projects.map(({ id, name, imageUrl }) => (
<MediaCard
key={id}
title={name}
imageUrl={imageUrl}
onClick={() => handleClick(imageUrl)}
/>
))}
</Container>
);
};
export default Board;