aboutsummaryrefslogtreecommitdiff
path: root/src/services/MomentService.ts
diff options
context:
space:
mode:
authorIvan Chen <ivan@tagg.id>2021-01-27 17:22:18 -0500
committerIvan Chen <ivan@tagg.id>2021-01-27 17:22:18 -0500
commit821f7b6e5b22405484c3545c6f17600d1f79feaa (patch)
tree346f779dfaa8e4c4378b9d6f2dc1af4ec5aa9a54 /src/services/MomentService.ts
parente897fdbbbe8442f05000645395753ff008a19bf4 (diff)
parent21a3e000443c5c4ab2ae91000108b9d3b0383964 (diff)
Merge branch 'master' into tma577-profile-slowness
# Conflicts: # src/services/index.ts
Diffstat (limited to 'src/services/MomentService.ts')
-rw-r--r--src/services/MomentService.ts93
1 files changed, 1 insertions, 92 deletions
diff --git a/src/services/MomentService.ts b/src/services/MomentService.ts
index 7bad6d4c..0110a0d6 100644
--- a/src/services/MomentService.ts
+++ b/src/services/MomentService.ts
@@ -1,100 +1,9 @@
import AsyncStorage from '@react-native-community/async-storage';
-import {Alert} from 'react-native';
import RNFetchBlob from 'rn-fetch-blob';
-import {
- COMMENTS_ENDPOINT,
- MOMENTS_ENDPOINT,
- MOMENT_THUMBNAIL_ENDPOINT,
-} from '../constants';
-import {ERROR_FAILED_TO_COMMENT} from '../constants/strings';
+import {MOMENTS_ENDPOINT, MOMENT_THUMBNAIL_ENDPOINT} from '../constants';
import {MomentType} from '../types';
import {checkImageUploadStatus} from '../utils';
-//Get all comments for a moment
-export const getMomentComments = async (
- momentId: string,
- callback: Function,
-) => {
- try {
- const token = await AsyncStorage.getItem('token');
- const response = await fetch(COMMENTS_ENDPOINT + '?moment_id=' + momentId, {
- method: 'GET',
- headers: {
- Authorization: 'Token ' + token,
- },
- });
- const status = response.status;
- if (status === 200) {
- const comments = await response.json();
- callback(comments);
- } else {
- console.log('Could not load comments');
- }
- } catch (error) {
- console.log('Could not load comments', error);
- }
-};
-
-export const postMomentComment = async (
- commenter: string,
- comment: string,
- momentId: string,
-) => {
- try {
- const token = await AsyncStorage.getItem('token');
- const request = new FormData();
- request.append('moment_id', momentId);
- request.append('commenter', commenter);
- request.append('comment', comment);
- const response = await fetch(COMMENTS_ENDPOINT, {
- method: 'POST',
- headers: {
- Authorization: 'Token ' + token,
- },
- body: request,
- });
- if (response.status !== 200) {
- throw 'server error';
- }
- return await response.json();
- } catch (error) {
- Alert.alert(ERROR_FAILED_TO_COMMENT);
- return undefined;
- }
-};
-
-//Get count of comments for a moment
-export const getMomentCommentsCount = async (
- momentId: string,
- callback: Function,
-) => {
- try {
- const token = await AsyncStorage.getItem('token');
- const response = await fetch(COMMENTS_ENDPOINT + `${momentId}/`, {
- method: 'GET',
- headers: {
- Authorization: 'Token ' + token,
- },
- });
- const status = response.status;
- if (status === 200) {
- const response_data = await response.json();
- callback(response_data.count);
- } else {
- console.log(
- 'Something went wrong! 😭',
- 'Not able to retrieve comments count',
- );
- }
- } catch (error) {
- console.log(
- 'Something went wrong! 😭',
- 'Not able to retrieve comments count',
- error,
- );
- }
-};
-
export const postMoment: (
fileName: string,
uri: string,