Bookmarks and fast reactions
This commit is contained in:
@@ -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 ?
|
||||
<Text> {">"} <UserName profileid={post.toProfile} /></Text> : 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 }) => (
|
||||
<Comment comment={item} viewer={viewer} />
|
||||
<Comment comment={item} viewer={viewer} postid={post._id} />
|
||||
);
|
||||
return (
|
||||
<Card style={styles.card}>
|
||||
@@ -61,7 +72,13 @@ let Post = (props) => {
|
||||
</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={!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>
|
||||
{showCommentsB && <NewComment postid={post._id} newComentAdded={newComentAdded} />}
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user