-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
82 lines (77 loc) · 1.94 KB
/
Copy pathindex.js
File metadata and controls
82 lines (77 loc) · 1.94 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
/*
This is the page that actually displays the posts
There is a separate file that creates the posts and posts them to the database similar to simplepeida creator
*/
import { useEffect, useState } from "react";
import { useRouter } from "next/router";
import PostsView from "@/components/PostsView";
import {
Box,
Typography,
ListItemButton,
ListItemAvatar,
Avatar,
ListItemText,
Container,
Stack,
} from "@mui/material";
import PostAdd from "@mui/icons-material/PostAdd";
export default function PostPage({}) {
const router = useRouter();
const [posts, setPosts] = useState([]);
function routeCreate() {
router.push(`/posts/new`);
}
useEffect(() => {
// fetch data from api
if (!posts) {
fetch("/api/posts")
.then((response) => response.json())
.then((data) => {
setPosts(data);
});
}
});
return (
<>
<header>
<Box
sx={{
marginTop: 2,
display: "flex",
flexDirection: "column",
alignItems: "center",
marginBottom: 2,
}}
>
<Typography component="h1" variant="h3" align="center">
Posts
</Typography>
<Typography component="p" className="tagline" align="center">
What are MiddKids saying?
</Typography>
</Box>
</header>
<main>
<Container maxWidth="xl">
<Stack
spacing={2}
direction="column"
justifyContent="center"
alignItems="center"
>
<PostsView posts={posts} />
<ListItemButton onClick={() => routeCreate()}>
<ListItemAvatar>
<Avatar>
<PostAdd />
</Avatar>
</ListItemAvatar>
<ListItemText>Add a Post!</ListItemText>
</ListItemButton>
</Stack>
</Container>
</main>
</>
);
}