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/onboarding/Checkpoint.tsx | 1 - src/screens/onboarding/Login.tsx | 15 +++++++++++---- src/screens/onboarding/SocialMedia.tsx | 14 ++++++-------- 3 files changed, 17 insertions(+), 13 deletions(-) (limited to 'src/screens/onboarding') diff --git a/src/screens/onboarding/Checkpoint.tsx b/src/screens/onboarding/Checkpoint.tsx index 0be1e831..83a8a2bc 100644 --- a/src/screens/onboarding/Checkpoint.tsx +++ b/src/screens/onboarding/Checkpoint.tsx @@ -11,7 +11,6 @@ import { } from 'react-native'; import {OnboardingStackParams} from '../../routes'; -import {AuthContext} from '../../routes/authentication'; import {RegistrationWizard, Background} from '../../components'; type CheckpointRouteProp = RouteProp; diff --git a/src/screens/onboarding/Login.tsx b/src/screens/onboarding/Login.tsx index 8f19ec3d..2ddae403 100644 --- a/src/screens/onboarding/Login.tsx +++ b/src/screens/onboarding/Login.tsx @@ -14,11 +14,12 @@ import { } from 'react-native'; import {OnboardingStackParams} from '../../routes/onboarding'; -import {AuthContext} from '../../routes/authentication'; import {Background, TaggInput, SubmitButton} from '../../components'; import {usernameRegex, LOGIN_ENDPOINT} from '../../constants'; import AsyncStorage from '@react-native-community/async-storage'; import {UserType} from '../../types'; +import {useDispatch} from 'react-redux'; +import {userLogin} from '../../utils'; type VerificationScreenRouteProp = RouteProp; type VerificationScreenNavigationProp = StackNavigationProp< @@ -51,9 +52,15 @@ const Login: React.FC = ({navigation}: LoginProps) => { attemptedSubmit: false, token: '', }); - // determines if user is logged in - const {login} = React.useContext(AuthContext); const [user, setUser] = useState(NO_USER); + + /** + * Redux Store stuff + * Get the dispatch reference + */ + + const dispatch = useDispatch(); + /** * Updates the state of username. Also verifies the input of the username field by ensuring proper length and appropriate characters. */ @@ -140,7 +147,7 @@ const Login: React.FC = ({navigation}: LoginProps) => { await AsyncStorage.setItem('token', data.token); await AsyncStorage.setItem('userId', data.UserID); await AsyncStorage.setItem('username', username); - login(data.UserID, username); + userLogin(dispatch, {userId: data.UserID, username}); } catch (err) { setUser(NO_USER); console.log(data); diff --git a/src/screens/onboarding/SocialMedia.tsx b/src/screens/onboarding/SocialMedia.tsx index 57270e4e..ee2bed10 100644 --- a/src/screens/onboarding/SocialMedia.tsx +++ b/src/screens/onboarding/SocialMedia.tsx @@ -10,6 +10,7 @@ import { TouchableOpacity, View, } from 'react-native'; +import {useDispatch} from 'react-redux'; import {LinkerType} from 'src/types'; import { Background, @@ -17,7 +18,8 @@ import { RegistrationWizard, } from '../../components'; import {SOCIAL_LIST} from '../../constants/'; -import {AuthContext, OnboardingStackParams} from '../../routes'; +import {OnboardingStackParams} from '../../routes'; +import {userLogin} from '../../utils'; /** * Social Media Screen for displaying social media linkers @@ -33,12 +35,6 @@ const SocialMedia: React.FC = ({route}) => { const {userId, username} = route.params; const linkers: Array = []; - /** - * login: determines if user successully created an account to - * navigate to home and display main tab navigation bar - */ - const {login} = React.useContext(AuthContext); - // let numSocials: Number = state.showMore ? 9 : 3; for (let i = 0; i < SOCIAL_LIST.length; i++) { @@ -48,6 +44,8 @@ const SocialMedia: React.FC = ({route}) => { linkers.push(linker); } + const dispatch = useDispatch(); + /** * Just commenting this out, in case we need it in the future */ @@ -60,7 +58,7 @@ const SocialMedia: React.FC = ({route}) => { const handleLogin = () => { try { - login(userId, username); + userLogin(dispatch, {userId: userId, username: username}); } catch (error) { console.log(error); Alert.alert('There was a problem logging you in'); -- cgit v1.2.3-70-g09d2