aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorIvan Chen <ivan@tagg.id>2021-05-10 15:51:34 -0400
committerIvan Chen <ivan@tagg.id>2021-05-10 16:50:42 -0400
commit6674e928c3621c742b56842db9e01d665a244ad3 (patch)
treeefeffe0888e20f16731201b825bd8ba89ce793c0 /src
parentc67025c0137074842b2cfeacefe1ea48d5748630 (diff)
added implementation for handling like or unlike a comment
Diffstat (limited to 'src')
-rw-r--r--src/services/CommentService.ts21
1 files changed, 21 insertions, 0 deletions
diff --git a/src/services/CommentService.ts b/src/services/CommentService.ts
index 69c5f3bc..7ede11cc 100644
--- a/src/services/CommentService.ts
+++ b/src/services/CommentService.ts
@@ -138,8 +138,29 @@ export const handleLikeUnlikeComment = async (comment: CommentBaseType) => {
const token = await AsyncStorage.getItem('token');
if (comment.user_reaction !== undefined) {
// unlike a comment
+ const url = COMMENT_REACTIONS_ENDPOINT + `${comment.user_reaction.id}/`;
+ const response = await fetch(url, {
+ method: 'DELETE',
+ headers: {
+ Authorization: 'Token ' + token,
+ },
+ });
+ return response.status === 200;
} else {
// like a comment
+ const url = COMMENT_REACTIONS_ENDPOINT;
+ const form = new FormData();
+ form.append('comment_id', comment.comment_id);
+ form.append('reaction_type', ReactionOptionsType.Like);
+ const response = await fetch(url, {
+ method: 'POST',
+ headers: {
+ 'Content-Type': 'multipart/form-data',
+ Authorization: 'Token ' + token,
+ },
+ body: form,
+ });
+ return response.status === 200;
}
return undefined;
} catch (error) {