aboutsummaryrefslogtreecommitdiff
path: root/src/components/comments/CommentTile.tsx
diff options
context:
space:
mode:
authorIvan Chen <ivan@tagg.id>2021-05-11 18:42:53 -0400
committerIvan Chen <ivan@tagg.id>2021-05-11 18:42:53 -0400
commit51f397132d227edf5e07d48d673ee167d2aa5937 (patch)
treee3813ec91919bc30a551194ab2585ac988b41589 /src/components/comments/CommentTile.tsx
parentfab3b1f7d046895dbaaff1ceddbc75f9ffc7fda0 (diff)
made things faster
Diffstat (limited to 'src/components/comments/CommentTile.tsx')
-rw-r--r--src/components/comments/CommentTile.tsx14
1 files changed, 7 insertions, 7 deletions
diff --git a/src/components/comments/CommentTile.tsx b/src/components/comments/CommentTile.tsx
index 1f1fafda..ee32f889 100644
--- a/src/components/comments/CommentTile.tsx
+++ b/src/components/comments/CommentTile.tsx
@@ -55,6 +55,7 @@ const CommentTile: React.FC<CommentTileProps> = ({
const [showReplies, setShowReplies] = useState<boolean>(false);
const [showKeyboard, setShowKeyboard] = useState<boolean>(false);
const [shouldUpdateChild, setShouldUpdateChild] = useState(true);
+ const [liked, setLiked] = useState(commentObject.user_reaction !== null);
const swipeRef = useRef<Swipeable>(null);
const {replyPosted} = useSelector((state: RootState) => state.user);
const state: RootState = useStore().getState();
@@ -150,12 +151,9 @@ const CommentTile: React.FC<CommentTileProps> = ({
screenType={screenType}
/>
<LikeButton
- initialLikeState={commentObject.user_reaction !== null}
- onPress={() => {
- handleLikeUnlikeComment(commentObject).then(() => {
- setShouldUpdateParent(true);
- });
- }}
+ liked={liked}
+ setLiked={setLiked}
+ onPress={() => handleLikeUnlikeComment(commentObject, liked)}
style={styles.likeButton}
/>
</View>
@@ -183,7 +181,9 @@ const CommentTile: React.FC<CommentTileProps> = ({
});
}}>
<Text style={[styles.date_time, styles.likeCount]}>
- {commentObject.reaction_count}
+ {commentObject.user_reaction !== null
+ ? commentObject.reaction_count + (liked ? 0 : -1)
+ : commentObject.reaction_count + (liked ? 1 : 0)}
</Text>
<Text style={styles.date_time}>Likes</Text>
</TouchableOpacity>