aboutsummaryrefslogtreecommitdiff
path: root/src/services/UserFollowServices.ts
diff options
context:
space:
mode:
authorAshm Walia <40498934+ashmgarv@users.noreply.github.com>2020-10-27 17:36:03 -0700
committerGitHub <noreply@github.com>2020-10-27 20:36:03 -0400
commit62d6fe2bca4bdd1a48cfe54e4c0c3fe590c3b750 (patch)
tree3afb2c723a10a2649c298e226bc31e10cec92d5a /src/services/UserFollowServices.ts
parent795ba089207571ec13226f2d07c149c8697763ce (diff)
[HOT FIX] Refactor to make things clean and make the app work (#82)
* Refactored * Final refactor with an issue * It works * Whoops
Diffstat (limited to 'src/services/UserFollowServices.ts')
-rw-r--r--src/services/UserFollowServices.ts18
1 files changed, 12 insertions, 6 deletions
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 (