From 84616a6143fea58899eafa915a73592eaad25361 Mon Sep 17 00:00:00 2001 From: Ivan Chen Date: Mon, 7 Dec 2020 19:19:50 -0500 Subject: [TMA-409] Delete Moments (#124) * edit profile to use HeaderHeight instead of percentage * delete moment done with TODOs for backend * actually hitting the endpoint * ops * moved isProfileView check to drawer component * misunderstood suggestion, now is better * an extra layer of indirection * fixed some bugs and code improvement --- src/services/MomentServices.ts | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) (limited to 'src/services') diff --git a/src/services/MomentServices.ts b/src/services/MomentServices.ts index 46ca1351..ed868582 100644 --- a/src/services/MomentServices.ts +++ b/src/services/MomentServices.ts @@ -1,6 +1,6 @@ -//Common moments api abstracted out here -import {COMMENTS_ENDPOINT, MOMENTS_ENDPOINT} from '../constants'; +import AsyncStorage from '@react-native-community/async-storage'; import {Alert} from 'react-native'; +import {COMMENTS_ENDPOINT, MOMENTS_ENDPOINT} from '../constants'; import {MomentType} from '../types'; //Get all comments for a moment @@ -123,3 +123,21 @@ export const loadMoments: ( } return moments; }; + +export const deleteMoment = async (momentId: string) => { + try { + const token = await AsyncStorage.getItem('token'); + + const response = await fetch(MOMENTS_ENDPOINT + `${momentId}/`, { + method: 'DELETE', + headers: { + Authorization: 'Token ' + token, + }, + }); + return response.status === 200; + } catch (error) { + console.log(error); + console.log('Unable to delete moment', momentId); + return false; + } +}; -- cgit v1.2.3-70-g09d2