From 62d6fe2bca4bdd1a48cfe54e4c0c3fe590c3b750 Mon Sep 17 00:00:00 2001 From: Ashm Walia <40498934+ashmgarv@users.noreply.github.com> Date: Tue, 27 Oct 2020 17:36:03 -0700 Subject: [HOT FIX] Refactor to make things clean and make the app work (#82) * Refactored * Final refactor with an issue * It works * Whoops --- src/services/UserFollowServices.ts | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) (limited to 'src/services/UserFollowServices.ts') diff --git a/src/services/UserFollowServices.ts b/src/services/UserFollowServices.ts index 508c1387..105124bc 100644 --- a/src/services/UserFollowServices.ts +++ b/src/services/UserFollowServices.ts @@ -10,7 +10,11 @@ import { import {ProfilePreviewType} from 'src/types'; -export const loadFollowers = async (userId: string, token: string) => { +export const loadFollowers = async ( + userId: string, + token: string, + callback: Function, +) => { try { const response = await fetch(FOLLOWERS_ENDPOINT + `?user_id=${userId}`, { method: 'GET', @@ -20,17 +24,20 @@ export const loadFollowers = async (userId: string, token: string) => { }); if (response.status === 200) { const body = await response.json(); - return body; + callback(body); } else { throw new Error(await response.json()); } } catch (error) { console.log(error); } - return []; }; -export const loadFollowing = async (userId: string, token: string) => { +export const loadFollowing = async ( + userId: string, + token: string, + callback: Function, +) => { try { const response = await fetch(FOLLOWING_ENDPOINT + `?user_id=${userId}`, { method: 'GET', @@ -40,14 +47,13 @@ export const loadFollowing = async (userId: string, token: string) => { }); if (response.status === 200) { const body = await response.json(); - return body; + callback(body); } else { throw new Error(await response.json()); } } catch (error) { console.log(error); } - return []; }; export const followOrUnfollowUser = async ( -- cgit v1.2.3-70-g09d2