From 0fd892ad288f2e1eaaa4fdf5e1fd6f15dbd45860 Mon Sep 17 00:00:00 2001 From: Ashm Walia <40498934+ashmgarv@users.noreply.github.com> Date: Fri, 4 Dec 2020 08:50:24 -0800 Subject: [TMA - 398 AND TMA-430] Replace Providers with Redux Store (#125) * First * WIP * Thunk * Some more comments * sc * recent searches and follounfollow * Edit profile dummy * Block / unblock and some cleanup * Replace auth provider * Sc * Delete AP after rebase * Discover users * Cleanup * More cleanup * Replace profile provider * Fixed build failure * Fixed a bug reported * Prevent app crash when backend server is down --- src/services/MomentServices.ts | 31 +++++++++++++++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) (limited to 'src/services/MomentServices.ts') diff --git a/src/services/MomentServices.ts b/src/services/MomentServices.ts index bf846b1c..46ca1351 100644 --- a/src/services/MomentServices.ts +++ b/src/services/MomentServices.ts @@ -1,7 +1,7 @@ //Common moments api abstracted out here - -import {COMMENTS_ENDPOINT} from '../constants'; +import {COMMENTS_ENDPOINT, MOMENTS_ENDPOINT} from '../constants'; import {Alert} from 'react-native'; +import {MomentType} from '../types'; //Get all comments for a moment export const getMomentComments = async ( @@ -96,3 +96,30 @@ export const getMomentCommentsCount = async ( ); } }; + +export const loadMoments: ( + userId: string, + token: string, +) => Promise = async (userId, token) => { + let moments: MomentType[] = []; + try { + const response = await fetch(MOMENTS_ENDPOINT + '?user_id=' + userId, { + method: 'GET', + headers: { + Authorization: 'Token ' + token, + }, + }); + const status = response.status; + if (status === 200) { + const data = await response.json(); + moments = data; + } else { + console.log('Could not load moments!'); + return []; + } + } catch (err) { + console.log(err); + return []; + } + return moments; +}; -- cgit v1.2.3-70-g09d2