Skip to content

Commit 06f5a25

Browse files
committed
Merge branch 'network-page-wireframe' of https://github.com/Ronnie018/Reentry into network-page-wireframe
2 parents 5352166 + ef17291 commit 06f5a25

File tree

8 files changed

+126
-27
lines changed

8 files changed

+126
-27
lines changed

src/components/Leftside.jsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ const Leftside = (props) => {
3737
</a>
3838
</UserInfo>
3939
<Widget>
40-
<a>
40+
<nav>
4141
<div>
4242
<Link to="/notifications">
4343
<span>Notifications</span>
@@ -50,7 +50,7 @@ const Leftside = (props) => {
5050
</Link>
5151
</div>
5252
<AiOutlineUserAdd />
53-
</a>
53+
</nav>
5454
</Widget>
5555
<Item>
5656
<span>

src/components/Posts/ArticleMenuButton.jsx

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ export function ArticleMenuButton({ articleText, articleId, fileType }) {
4040

4141
async function deleteArticle(articleId) {
4242
const articleRef = db.collection("articles").doc(articleId);
43+
const commentsRef = articleRef.collection("comments");
44+
4345
const fileRef = fileType ? storage.refFromURL(fileType) : null;
4446

4547
if (fileRef) {
@@ -50,6 +52,11 @@ export function ArticleMenuButton({ articleText, articleId, fileType }) {
5052
await articleRef.delete().then(() => {
5153
console.log("article deleted");
5254
});
55+
commentsRef.get().then((querySnapshot) => {
56+
querySnapshot.docs.forEach((snapshot) => {
57+
snapshot.ref.delete();
58+
});
59+
});
5360
}
5461

5562
return (

src/components/Posts/SinglePost.jsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,8 +166,9 @@ export function SinglePost({ article, id }) {
166166
<>
167167
<p style={{ textAlign: "left", marginLeft: "15px" }}>Comments:</p>
168168
<div style={{ maxHeight: "300px", overflow: "scroll" }}>
169-
{comments.map((comment) => (
169+
{comments.map((comment, i) => (
170170
<SingleComment
171+
key={i}
171172
comment={comment}
172173
articleAuthor={article.actor.uid}
173174
articleId={id}

src/components/Posts/comments/AddComment/index.jsx

Lines changed: 40 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,24 @@
11
import Container from "./styledComments";
22
import { Button, ButtonGroup } from "@material-ui/core";
3-
import { useState } from "react";
3+
import { useRef, useState } from "react";
44
import db, { auth } from "../../../../firebase";
5+
import { commentValidador } from "../../../../services/validators/commentValidations";
56

67
export function AddComment({ articleId, setshowCommentBox }) {
78
const [commentText, setcommentText] = useState("");
9+
const form = useRef();
810

911
async function addCommentToFireStoreDocument(e, articleId) {
1012
const user = auth.currentUser;
11-
e.preventDefault();
13+
14+
try {
15+
e.preventDefault();
16+
} catch (e) {
17+
console.log(e.message);
18+
}
1219

1320
const timestamp = new Date();
21+
1422
const comment = {
1523
text: commentText,
1624
postedBy: user.displayName,
@@ -19,20 +27,49 @@ export function AddComment({ articleId, setshowCommentBox }) {
1927
commenterProfilePic: user.photoURL,
2028
};
2129

30+
const validator = new commentValidador(comment);
31+
32+
if (!validator.isValid) {
33+
return window.alert(
34+
"validation error during validation of ",
35+
validator.currentField
36+
);
37+
}
38+
2239
const articleRef = db.collection("articles").doc(articleId);
2340
const commentsRef = articleRef.collection("comments");
2441
const response = await commentsRef.add(comment);
2542

2643
setshowCommentBox(false);
2744
}
2845

46+
const keyController = {
47+
ctrl: false,
48+
};
49+
50+
const handleMessageKeyDown = (e) => {
51+
if (e.key === "Control") {
52+
keyController.ctrl = true;
53+
}
54+
if (e.key === "Enter" && keyController.ctrl) {
55+
addCommentToFireStoreDocument(e, articleId);
56+
}
57+
};
58+
59+
const handleMessageKeyUp = (e) => {
60+
if (e.key === "Control") {
61+
keyController.ctrl = false;
62+
}
63+
};
64+
2965
return (
30-
<Container>
66+
<Container onKeyDown={handleMessageKeyDown} onKeyUp={handleMessageKeyUp}>
3167
<div className="picture-wrapper">
3268
<img src={auth.currentUser.photoURL} alt="commenter profile picture" />
3369
</div>
3470
<div className="comment-container">
3571
<form
72+
ref={form}
3673
onSubmit={(e) => addCommentToFireStoreDocument(e, articleId)}
3774
className="comment-form"
3875
>

src/components/Posts/comments/SingleComment/styledSingleComment.jsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ const Container = styled.div`
1313
img {
1414
border-radius: 5px;
1515
width: 100%;
16+
font-size: 0;
1617
}
1718
}
1819
.comment-content-container {

src/components/Welcome.jsx

Lines changed: 27 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import {
1010
Section,
1111
Hero,
1212
} from "../styles/stylesWelcome";
13-
import { Link, Navigate } from "react-router-dom";
13+
import { Link } from "react-router-dom";
1414

1515
const Welcome = (props) => {
1616
useEffect(() => {
@@ -115,31 +115,39 @@ function parallax(e) {
115115
}
116116

117117
function move(elm, event) {
118-
const speed = elm.getAttribute("speed");
119-
const defaultTop = Number(elm.getAttribute("top"));
120-
const defaultLeft = Number(elm.getAttribute("left"));
118+
try {
119+
const speed = elm.getAttribute("speed");
120+
const defaultTop = Number(elm.getAttribute("top"));
121+
const defaultLeft = Number(elm.getAttribute("left"));
121122

122-
const x = (window.innerWidth - event.pageX * speed) / 100;
123-
const y = (window.innerHeight - event.pageY * speed) / 100;
123+
const x = (window.innerWidth - event.pageX * speed) / 100;
124+
const y = (window.innerHeight - event.pageY * speed) / 100;
124125

125-
const yValue = defaultTop + y;
126-
const xValue = defaultLeft + x;
126+
const yValue = defaultTop + y;
127+
const xValue = defaultLeft + x;
127128

128-
elm.style.setProperty("top", `${yValue}px`);
129-
elm.style.setProperty("left", `${xValue}px`);
129+
elm.style.setProperty("top", `${yValue}px`);
130+
elm.style.setProperty("left", `${xValue}px`);
131+
} catch (e) {
132+
console.log(e.message);
133+
}
130134
}
131135

132136
function moveChain(elm, event) {
133-
const speed = elm.getAttribute("speed");
134-
const defaultTop = Number(elm.getAttribute("top"));
135-
const defaultLeft = Number(elm.getAttribute("left"));
137+
try {
138+
const speed = elm.getAttribute("speed");
139+
const defaultTop = Number(elm.getAttribute("top"));
140+
const defaultLeft = Number(elm.getAttribute("left"));
136141

137-
const x = (window.innerWidth - event.pageX * speed) / 100;
138-
const y = (window.innerHeight - event.pageY * speed) / 100;
142+
const x = (window.innerWidth - event.pageX * speed) / 100;
143+
const y = (window.innerHeight - event.pageY * speed) / 100;
139144

140-
const yValue = defaultTop + y;
141-
const xValue = defaultLeft + x;
145+
const yValue = defaultTop + y;
146+
const xValue = defaultLeft + x;
142147

143-
elm.style.setProperty("top", `${yValue}px`);
144-
elm.style.setProperty("left", `${xValue > 0 ? 0 : xValue}px`);
148+
elm.style.setProperty("top", `${yValue}px`);
149+
elm.style.setProperty("left", `${xValue > 0 ? 0 : xValue}px`);
150+
} catch (e) {
151+
console.log(e.message);
152+
}
145153
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
export class commentValidador {
2+
constructor(comment) {
3+
this.currentField = null;
4+
this.isValid = // case one of the validations fail this will be false
5+
this.keyValidation(comment) &&
6+
this.isText(comment.text) &&
7+
this.isText(comment.postedBy) &&
8+
this.isDate(comment.timestamp) &&
9+
this.isText(comment.commenterUid) &&
10+
this.isText(comment.commenterProfilePic, true) &&
11+
true; // returned value case pass all validations
12+
}
13+
14+
keyValidation(data) {
15+
// check if it have all the required fields;
16+
// The fields need to be changed if used in another validation;
17+
18+
this.currentField = data;
19+
// Use this in each validation to keep track where the validation is (in case of validation error you can use this key to print out where it occurred)
20+
return (
21+
"text" in data &&
22+
"postedBy" in data &&
23+
"timestamp" in data &&
24+
"commenterUid" in data &&
25+
"commenterProfilePic" in data &&
26+
true // returned value case pass all validations
27+
);
28+
}
29+
30+
isDate(field) {
31+
this.currentField = field;
32+
return typeof field === "object"; // javascript new Date() type attribute is object
33+
}
34+
35+
isText(field, acceptNull) {
36+
// have an optional second parameter, case the field can be null (in this case the image can be null (check line 10))
37+
this.currentField = field;
38+
if (acceptNull) {
39+
return typeof field === "string" || field === null;
40+
}
41+
return typeof field === "string";
42+
}
43+
}

src/styles/stylesLeftside.jsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,7 @@ const Widget = styled.div`
6161
border-bottom: 1px solid rgba(0, 0, 0, 0.15);
6262
padding-top: 12px;
6363
padding-bottom: 12px;
64-
& > a {
65-
text-decoration: none;
64+
& > nav {
6665
display: flex;
6766
justify-content: space-between;
6867
align-items: center;
@@ -71,6 +70,9 @@ const Widget = styled.div`
7170
background-color: rgba(0, 0, 0, 0.08);
7271
}
7372
div {
73+
a {
74+
text-decoration: none;
75+
}
7476
display: flex;
7577
flex-direction: column;
7678
text-align: left;

0 commit comments

Comments
 (0)