Skip to content

Commit a44128c

Browse files
authored
Merge pull request #37 from csci312a-s23/postViewUI
added styling changes with post view page - updated with main
2 parents 93e78f6 + b45be67 commit a44128c

File tree

10 files changed

+942
-113
lines changed

10 files changed

+942
-113
lines changed

ellen.db

0 Bytes
Binary file not shown.

package-lock.json

+864-91
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+3
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@
2020
"prepare": "husky install"
2121
},
2222
"dependencies": {
23+
"@emotion/react": "^11.10.6",
24+
"@emotion/styled": "^11.10.6",
25+
"@mui/material": "^5.12.1",
2326
"ajv-formats": "^2.1.1",
2427
"db-errors": "^0.2.3",
2528
"knex": "^2.4.2",

public/components/filterBar.js

+9-5
Original file line numberDiff line numberDiff line change
@@ -11,24 +11,28 @@
1111
-setCurrentSortFilter: sets current filter based on button click
1212
*/
1313

14+
import Button from "@mui/material/Button";
1415
import PropTypes from "prop-types";
1516

1617
function filterBar({ currentSortFilter, setCurrentSortFilter }) {
1718
return (
18-
<div>
19+
<div style={{ display: "flex", flexDirection: "row" }}>
1920
{/* Maybe want some sort of sections view / titles view combo? */}
20-
<button
21+
<Button
22+
variant="outlined"
2123
onClick={() => setCurrentSortFilter("new")}
2224
disabled={currentSortFilter === "new"}
2325
>
2426
New
25-
</button>
26-
<button
27+
</Button>
28+
<Button
29+
style={{ marginLeft: "5%" }}
30+
variant="outlined"
2731
onClick={() => setCurrentSortFilter("hot")}
2832
disabled={currentSortFilter === "hot"}
2933
>
3034
Hot
31-
</button>
35+
</Button>
3236
</div>
3337
);
3438
}

public/components/post.js

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import Paper from "@mui/material/Paper";
2+
import PropTypes from "prop-types";
3+
import Link from "next/link";
4+
5+
export default function Post({ postInfo }) {
6+
const postStyle = {
7+
display: "flex",
8+
flexDirection: "column",
9+
};
10+
return (
11+
<div data-testid="post">
12+
<Paper elevation={3} style={postStyle}>
13+
<div style={{ display: "flex", flexDirection: "row", marginTop: "2%" }}>
14+
<Link href={`/posts/${postInfo.id}`} style={{ marginLeft: "5%" }}>
15+
{postInfo.title}
16+
</Link>
17+
<p style={{ alignSelf: "center", marginLeft: "5%" }}>
18+
{" "}
19+
{postInfo.category}{" "}
20+
</p>
21+
<p style={{ marginLeft: "auto", marginRight: "2%" }}>
22+
{" "}
23+
{postInfo.votes}{" "}
24+
</p>
25+
</div>
26+
<p style={{ marginLeft: "10%", marginTop: "3%", marginBottom: "2%" }}>
27+
{postInfo.content}
28+
</p>
29+
<p style={{ marginLeft: "80%", fontSize: "10px" }}>{postInfo.date}</p>
30+
</Paper>
31+
</div>
32+
);
33+
}
34+
Post.propTypes = {
35+
postInfo: PropTypes.object,
36+
};

public/components/postsList.js

+6-5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import PropTypes from "prop-types";
2-
import IndividualPost from "@/components/IndividualPost";
2+
import Post from "./post";
3+
34
function PostList({ posts, sortingFilter }) {
45
let filteredPosts;
56

@@ -21,16 +22,16 @@ function PostList({ posts, sortingFilter }) {
2122
});
2223

2324
return (
24-
<>
25+
<div style={{ width: "100%", margin: "5% 0 5% 0" }}>
2526
{/* WE need a post id */}
2627
{filteredPosts.map((post) => {
2728
return (
28-
<div key={post.id}>
29-
<IndividualPost post={post} />
29+
<div key={post.id} style={{ marginBottom: "2%" }}>
30+
<Post postInfo={post} />
3031
</div>
3132
);
3233
})}
33-
</>
34+
</div>
3435
);
3536
}
3637

public/components/postsList.test.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ describe("postList: postList tests", () => {
5858

5959
const items = await screen.findAllByTestId("post");
6060
const dates = items.map(
61-
(item) => new Date(item.children[3].innerHTML.slice(12))
61+
(item) => new Date(item.children[0].children[2].innerHTML.slice(12))
6262
);
6363
console.log(dates);
6464
let sorted = true;

src/components/newPost/PostCreator.js

+11-7
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import React, { useState } from "react";
22
import Popup from "reactjs-popup";
33
import styles from "./PostCreator.module.css";
44
import ReactSwitch from "react-switch";
5+
import Button from "@mui/material/Button";
56

67
export default function PostCreator({ refresh }) {
78
const [open, setOpen] = useState(false);
@@ -49,13 +50,16 @@ export default function PostCreator({ refresh }) {
4950

5051
return (
5152
<div>
52-
<button
53-
type="button"
54-
className={styles.openCreator}
55-
onClick={() => setOpen((o) => !o)}
56-
>
57-
New Post
58-
</button>
53+
<div style={{ margin: "5%" }}>
54+
<Button
55+
variant="outlined"
56+
type="button"
57+
className={styles.openCreator}
58+
onClick={() => setOpen((o) => !o)}
59+
>
60+
New Post
61+
</Button>
62+
</div>
5963
<Popup open={open} closeOnDocumentClick onClose={closeModal}>
6064
<div className={styles.modal}>
6165
<a className={styles.close} onClick={closeModal}>

src/components/newPost/PostCreator.module.css

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
.openCreator {
2-
width: 100px;
3-
height: 100px;
2+
width: 150px;
3+
height: 50px;
44
}
55

66
.modal {

src/pages/index.js

+10-2
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,22 @@ export default function Home({ posts, refreshPosts }) {
2222
};
2323

2424
return (
25-
<>
25+
<div
26+
style={{
27+
display: "flex",
28+
width: "40%",
29+
flexDirection: "column",
30+
alignItems: "center",
31+
margin: "2%",
32+
}}
33+
>
2634
<FilterBar
2735
currentSortFilter={currentSortFilter}
2836
setCurrentSortFilter={changeSortFilter}
2937
/>
3038
<PostList posts={posts} sortingFilter={currentSortFilter} />
3139
<PostCreator refresh={refreshPosts} />
32-
</>
40+
</div>
3341
);
3442
}
3543

0 commit comments

Comments
 (0)