diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/services/CommentService.ts | 21 |
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) { |