diff --git a/components/Comment.js b/components/Comment.js
index 1c1e0bc..abbe94e 100644
--- a/components/Comment.js
+++ b/components/Comment.js
@@ -11,10 +11,9 @@ let Comment = ({ comment, postid, viewer }) => {
let [likes, changeLikes] = useState(Object.keys(comment.reactions).length);
const newCommentReaction = () => {
if (!comment.reactions[viewer._id]) {
- API.newCommentReaction(postid, comment.createdAt).then(() => {
- comment.reactions[viewer._id] = { type: "like" };
- changeLikes(likes+1);
- });
+ comment.reactions[viewer._id] = { type: "like" };
+ changeLikes(likes+1);
+ API.newCommentReaction(postid, comment.createdAt);
} else {
//API.removePostReaction(viewer._id).then(() => {
// delete comment.reactions[viewer._id];
diff --git a/components/Post.js b/components/Post.js
index c15e734..6b1d5fc 100644
--- a/components/Post.js
+++ b/components/Post.js
@@ -12,7 +12,8 @@ let Post = (props) => {
const viewer = props.viewer;
let [showCommentsB, changeshowCommentsB] = useState(false);
let [post, changePost] = useState(props.post);
- let [likes, changeLikes] = useState(Object.keys(post.reactions).length)
+ let [likes, changeLikes] = useState(Object.keys(post.reactions).length);
+ let [bookmarked, changeBookmarked] = useState(post.bookmarks && post.bookmarks.includes(viewer._id));
let toProfileText = post.toProfile && post.toProfile !== post.profileid ?
{">"} : undefined;
let cleanContent = post.content.replace(/@[A-z]+:.+\w/g, '');
@@ -24,20 +25,30 @@ let Post = (props) => {
const newPostReaction = () => {
let newPostObj = { ...post };
if (!newPostObj.reactions[viewer._id]) {
- API.newPostReaction(post._id).then(() => {
- newPostObj.reactions[viewer._id] = { type: "like" };
- changeLikes(likes+1);
- });
+ changeLikes(likes + 1);
+ newPostObj.reactions[viewer._id] = { type: "like" };
+ API.newPostReaction(post._id);
} else {
- API.removePostReaction(viewer._id).then(() => {
- delete newPostObj.reactions[viewer._id];
- changeLikes(likes-1);
- });
+ changeLikes(likes - 1);
+ delete newPostObj.reactions[viewer._id];
+ API.removePostReaction(viewer._id);
}
changePost(newPostObj);
}
+ const newPostBookmark = () => {
+ if (!post.bookmarks || !post.bookmarks.includes(viewer._id)) {
+ changeBookmarked(true);
+ if (!post.bookmarks) post.bookmarks = [];
+ post.bookmarks.push(viewer._id);
+ API.newPostBookmark(post._id);
+ } else {
+ changeBookmarked(false);
+ post.bookmarks = post.bookmarks.filter(id => id != viewer._id);
+ API.removePostReaction(post._id)
+ }
+ }
const renderComment = ({ item }) => (
-
+
);
return (
@@ -61,7 +72,13 @@ let Post = (props) => {
-
+
{showCommentsB && }
{