Bookmarks and fast reactions
This commit is contained in:
@@ -11,10 +11,9 @@ let Comment = ({ comment, postid, viewer }) => {
|
|||||||
let [likes, changeLikes] = useState(Object.keys(comment.reactions).length);
|
let [likes, changeLikes] = useState(Object.keys(comment.reactions).length);
|
||||||
const newCommentReaction = () => {
|
const newCommentReaction = () => {
|
||||||
if (!comment.reactions[viewer._id]) {
|
if (!comment.reactions[viewer._id]) {
|
||||||
API.newCommentReaction(postid, comment.createdAt).then(() => {
|
|
||||||
comment.reactions[viewer._id] = { type: "like" };
|
comment.reactions[viewer._id] = { type: "like" };
|
||||||
changeLikes(likes+1);
|
changeLikes(likes+1);
|
||||||
});
|
API.newCommentReaction(postid, comment.createdAt);
|
||||||
} else {
|
} else {
|
||||||
//API.removePostReaction(viewer._id).then(() => {
|
//API.removePostReaction(viewer._id).then(() => {
|
||||||
// delete comment.reactions[viewer._id];
|
// delete comment.reactions[viewer._id];
|
||||||
|
|||||||
@@ -12,7 +12,8 @@ let Post = (props) => {
|
|||||||
const viewer = props.viewer;
|
const viewer = props.viewer;
|
||||||
let [showCommentsB, changeshowCommentsB] = useState(false);
|
let [showCommentsB, changeshowCommentsB] = useState(false);
|
||||||
let [post, changePost] = useState(props.post);
|
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 ?
|
let toProfileText = post.toProfile && post.toProfile !== post.profileid ?
|
||||||
<Text> {">"} <UserName profileid={post.toProfile} /></Text> : undefined;
|
<Text> {">"} <UserName profileid={post.toProfile} /></Text> : undefined;
|
||||||
let cleanContent = post.content.replace(/@[A-z]+:.+\w/g, '');
|
let cleanContent = post.content.replace(/@[A-z]+:.+\w/g, '');
|
||||||
@@ -24,20 +25,30 @@ let Post = (props) => {
|
|||||||
const newPostReaction = () => {
|
const newPostReaction = () => {
|
||||||
let newPostObj = { ...post };
|
let newPostObj = { ...post };
|
||||||
if (!newPostObj.reactions[viewer._id]) {
|
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 {
|
} 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);
|
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 }) => (
|
const renderComment = ({ item }) => (
|
||||||
<Comment comment={item} viewer={viewer} />
|
<Comment comment={item} viewer={viewer} postid={post._id} />
|
||||||
);
|
);
|
||||||
return (
|
return (
|
||||||
<Card style={styles.card}>
|
<Card style={styles.card}>
|
||||||
@@ -61,7 +72,13 @@ let Post = (props) => {
|
|||||||
</Button>
|
</Button>
|
||||||
<Button icon="forum" labelStyle={{ fontSize: 18 }} style={{ flow: 1 }} onPress={() => { changeshowCommentsB(!showCommentsB) }} >{post.comments.length}</Button>
|
<Button icon="forum" labelStyle={{ fontSize: 18 }} style={{ flow: 1 }} onPress={() => { changeshowCommentsB(!showCommentsB) }} >{post.comments.length}</Button>
|
||||||
<Button icon="ios-share" style={{ flow: 1 }} labelStyle={{ fontSize: 18 }}></Button>
|
<Button icon="ios-share" style={{ flow: 1 }} labelStyle={{ fontSize: 18 }}></Button>
|
||||||
<Button icon={!post.bookmarks || !post.bookmarks.includes(viewer._id) ? "bookmark-outline" : "bookmark"} style={{ flow: 1 }} labelStyle={{ fontSize: 18 }}></Button>
|
<Button
|
||||||
|
icon={!bookmarked ? "bookmark-outline" : "bookmark"}
|
||||||
|
style={{ flow: 1 }}
|
||||||
|
labelStyle={{ fontSize: 18 }}
|
||||||
|
onPress={newPostBookmark}
|
||||||
|
>
|
||||||
|
</Button>
|
||||||
</Card.Actions>
|
</Card.Actions>
|
||||||
{showCommentsB && <NewComment postid={post._id} newComentAdded={newComentAdded} />}
|
{showCommentsB && <NewComment postid={post._id} newComentAdded={newComentAdded} />}
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user