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/screens/profile/EditProfile.tsx | 13 ++++++++-----
 1 file changed, 8 insertions(+), 5 deletions(-)

(limited to 'src/screens/profile/EditProfile.tsx')

diff --git a/src/screens/profile/EditProfile.tsx b/src/screens/profile/EditProfile.tsx
index 01b67155..44d99b82 100644
--- a/src/screens/profile/EditProfile.tsx
+++ b/src/screens/profile/EditProfile.tsx
@@ -30,9 +30,11 @@ import {
   genderRegex,
 } from '../../constants';
 import AsyncStorage from '@react-native-community/async-storage';
-import {AuthContext} from '../../routes';
 import Animated from 'react-native-reanimated';
 import {SCREEN_HEIGHT} from '../../utils';
+import {RootState} from '../../store/rootReducer';
+import {useDispatch, useSelector} from 'react-redux';
+import {loadUserData} from '../../store/actions';
 
 type ProfileOnboardingScreenRouteProp = RouteProp<
   OnboardingStackParams,
@@ -62,13 +64,14 @@ const ProfileOnboarding: React.FC<ProfileOnboardingProps> = ({
     profile: {website, biography, birthday, gender},
     avatar,
     cover,
-    updateIsEditedProfile,
-  } = React.useContext(AuthContext);
+  } = useSelector((state: RootState) => state.user);
+
   const [needsUpdate, setNeedsUpdate] = useState(false);
+  const dispatch = useDispatch();
 
   useEffect(() => {
-    updateIsEditedProfile(needsUpdate);
-  }, [needsUpdate, updateIsEditedProfile]);
+    if (needsUpdate) dispatch(loadUserData({userId, username}));
+  }, [loadUserData, needsUpdate]);
 
   const [isCustomGender, setIsCustomGender] = React.useState<boolean>(
     gender !== '' && gender !== 'female' && gender !== 'male',
-- 
cgit v1.2.3-70-g09d2

