Working reactions
This commit is contained in:
@@ -7,7 +7,21 @@ import Media from './Media.js';
|
|||||||
import AwesomeIcon from 'react-native-vector-icons/FontAwesome';
|
import AwesomeIcon from 'react-native-vector-icons/FontAwesome';
|
||||||
|
|
||||||
|
|
||||||
let Comment = ({ comment }) => {
|
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);
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
//API.removePostReaction(viewer._id).then(() => {
|
||||||
|
// delete comment.reactions[viewer._id];
|
||||||
|
// changeLikes(likes-1);
|
||||||
|
//});
|
||||||
|
}
|
||||||
|
}
|
||||||
return (
|
return (
|
||||||
<Card style={styles.comment}>
|
<Card style={styles.comment}>
|
||||||
<Card.Content>
|
<Card.Content>
|
||||||
@@ -20,10 +34,10 @@ let Comment = ({ comment }) => {
|
|||||||
</View>
|
</View>
|
||||||
<View style={{flex:2}}>
|
<View style={{flex:2}}>
|
||||||
<Button
|
<Button
|
||||||
icon="favorite-border"
|
icon={comment.reactions[viewer._id] ? "favorite" : "favorite-border"}
|
||||||
dense={true}
|
dense={true}
|
||||||
onPress={() => console.log('Pressed')}
|
onPress={newCommentReaction}
|
||||||
/>
|
>{likes ? likes : ''}</Button>
|
||||||
</View>
|
</View>
|
||||||
</View>
|
</View>
|
||||||
<Text style={{fontSize: 16}}>{comment.content}</Text>
|
<Text style={{fontSize: 16}}>{comment.content}</Text>
|
||||||
|
|||||||
@@ -37,7 +37,7 @@ let Post = (props) => {
|
|||||||
changePost(newPostObj);
|
changePost(newPostObj);
|
||||||
}
|
}
|
||||||
const renderComment = ({ item }) => (
|
const renderComment = ({ item }) => (
|
||||||
<Comment comment={item} />
|
<Comment comment={item} viewer={viewer} />
|
||||||
);
|
);
|
||||||
return (
|
return (
|
||||||
<Card style={styles.card}>
|
<Card style={styles.card}>
|
||||||
|
|||||||
Reference in New Issue
Block a user