diff --git a/functions/handlers/post.js b/functions/handlers/post.js
index 2ccdc8e..8ef48c9 100644
--- a/functions/handlers/post.js
+++ b/functions/handlers/post.js
@@ -160,6 +160,24 @@ exports.quoteWithoutPost = (req, res) => {
}
+exports.checkforLikePost = (req, res) => {
+ const likedPostDoc = admin.firestore().collection('likes').where('userHandle', '==', req.user.handle)
+ .where('postId', '==', req.params.postId).limit(1);
+ let result;
+
+ likedPostDoc.get()
+ .then((data) => {
+ if (data.empty) {
+ result = false;
+ return res.status(200).json(result);
+ }
+ else
+ {
+ result = true;
+ return res.status(200).json(result);
+ }
+ })
+}
exports.likePost = (req, res) => {
let postData;
@@ -201,6 +219,7 @@ exports.likePost = (req, res) => {
}
+
exports.unlikePost = (req, res) => {
let postData;
diff --git a/functions/index.js b/functions/index.js
index f4ab762..ee203eb 100644
--- a/functions/index.js
+++ b/functions/index.js
@@ -70,7 +70,7 @@ app.post("/removeSub", fbAuth, removeSub);
/*------------------------------------------------------------------*
* handlers/post.js *
*------------------------------------------------------------------*/
-const { getallPostsforUser, getallPosts, putPost, likePost, unlikePost, quoteWithPost, quoteWithoutPost} = require("./handlers/post");
+const { getallPostsforUser, getallPosts, putPost, likePost, unlikePost, quoteWithPost, quoteWithoutPost, checkforLikePost} = require("./handlers/post");
app.get("/getallPostsforUser", fbAuth, getallPostsforUser);
@@ -81,6 +81,7 @@ app.post("/putPost", fbAuth, putPost);
app.get("/like/:postId", fbAuth, likePost);
app.get("/unlike/:postId", fbAuth, unlikePost);
+app.get("/checkforLikePost/:postId", fbAuth, checkforLikePost);
app.post("/quoteWithPost/:postId", fbAuth, quoteWithPost);
app.post("/quoteWithoutPost/:postId", fbAuth, quoteWithoutPost);
diff --git a/twistter-frontend/src/pages/Home.js b/twistter-frontend/src/pages/Home.js
index fd288c0..22f6ce2 100644
--- a/twistter-frontend/src/pages/Home.js
+++ b/twistter-frontend/src/pages/Home.js
@@ -32,9 +32,6 @@ class Home extends Component {
this.setState({
posts: res.data
})
- this.setState({posts: (this.state.posts).sort((a,b) =>
- -a.createdAt.localeCompare(b.createdAt))
- })
})
.catch(err => console.log(err));
}
@@ -54,16 +51,15 @@ class Home extends Component {
}
-
-
@@ -234,7 +230,7 @@ class Like extends Component {
constructor(props) {
super(props)
this.state = {
- like: false
+
}
this.handleClick = this.handleClick.bind(this);
@@ -267,17 +263,43 @@ class Like extends Component {
console.log(err);
})
}
-
+
+
}
+
+ componentDidMount() {
+ axios.get(`/checkforLikePost/${this.props.microBlog}`)
+ .then((res) => {
+ this.setState({
+ like: res.data
+ })
+ console.log(res.data);
+ })
+ .catch((err) => {
+ console.log(err)
+ })
+ }
+
render() {
+
const label = this.state.like ? 'Unlike' : 'Like'
return(