diff options
| author | Ashm Walia <40498934+ashmgarv@users.noreply.github.com> | 2020-10-27 17:36:03 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-10-27 20:36:03 -0400 |
| commit | 62d6fe2bca4bdd1a48cfe54e4c0c3fe590c3b750 (patch) | |
| tree | 3afb2c723a10a2649c298e226bc31e10cec92d5a /src/screens/profile | |
| parent | 795ba089207571ec13226f2d07c149c8697763ce (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/screens/profile')
| -rw-r--r-- | src/screens/profile/FollowersListScreen.tsx | 41 |
1 files changed, 9 insertions, 32 deletions
diff --git a/src/screens/profile/FollowersListScreen.tsx b/src/screens/profile/FollowersListScreen.tsx index 21778929..4d14ef67 100644 --- a/src/screens/profile/FollowersListScreen.tsx +++ b/src/screens/profile/FollowersListScreen.tsx @@ -1,16 +1,13 @@ -import React, {useRef, useEffect, useState} from 'react'; +import React, {useEffect, useState} from 'react'; import {RouteProp} from '@react-navigation/native'; import {TabsGradient, Followers, CenteredView} from '../../components'; import Animated from 'react-native-reanimated'; import {AuthContext, ProfileContext} from '../../routes/'; -import {FOLLOWERS_ENDPOINT, FOLLOWING_ENDPOINT} from '../../constants'; -import AsyncStorage from '@react-native-community/async-storage'; import {ProfilePreviewType} from '../../types'; import {ScrollView} from 'react-native-gesture-handler'; -import {StatusBarHeight, SCREEN_HEIGHT} from '../../utils'; +import {SCREEN_HEIGHT} from '../../utils'; import {StyleSheet, View} from 'react-native'; import {ProfileStackParams} from '../../routes'; -import { loadFollowers, loadFollowing } from '../../services/UserFollowServices'; type FollowersListScreenRouteProp = RouteProp< ProfileStackParams, @@ -22,7 +19,7 @@ interface FollowersListScreenProps { const FollowersListScreen: React.FC<FollowersListScreenProps> = ({route}) => { const {isProfileView, isFollowers} = route.params; - const {user} = isProfileView + const {user, followers, following} = isProfileView ? React.useContext(ProfileContext) : React.useContext(AuthContext); const y = Animated.useValue(0); @@ -30,31 +27,8 @@ const FollowersListScreen: React.FC<FollowersListScreenProps> = ({route}) => { const top = Animated.useValue(-SCREEN_HEIGHT); useEffect(() => { - const loadResults = async (q: string) => { - try { - const token = await AsyncStorage.getItem('token'); - - if (!token) { - return; - } - - const result: ProfilePreviewType[] = isFollowers ? await loadFollowers( - user.userId, - token, - ) : await loadFollowing( - user.userId, - token, - ); - setResult(result); - - } catch (error) { - console.log(error); - setResult([]); - } - }; - loadResults(user.userId); - - }, []); + setResult(isFollowers ? followers : following); + }, [followers, following]); return ( <CenteredView> @@ -64,7 +38,10 @@ const FollowersListScreen: React.FC<FollowersListScreenProps> = ({route}) => { stickyHeaderIndices={[4]} contentContainerStyle={styles.contentContainer} showsVerticalScrollIndicator={false}> - <Followers {...{result}} sectionTitle={isFollowers ? "Followers" : "Following"} /> + <Followers + {...{result}} + sectionTitle={isFollowers ? 'Followers' : 'Following'} + /> </ScrollView> <TabsGradient /> </View> |
