aboutsummaryrefslogtreecommitdiff
path: root/src/screens/onboarding/Login.tsx
diff options
context:
space:
mode:
authorAshm Walia <40498934+ashmgarv@users.noreply.github.com>2020-12-04 08:50:24 -0800
committerGitHub <noreply@github.com>2020-12-04 11:50:24 -0500
commit0fd892ad288f2e1eaaa4fdf5e1fd6f15dbd45860 (patch)
treed7d53d94c6c4026ac9b325508ebce4706d412ac4 /src/screens/onboarding/Login.tsx
parentf620102190629e0b6f180d3ce056d850b1db5aaa (diff)
[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
Diffstat (limited to 'src/screens/onboarding/Login.tsx')
-rw-r--r--src/screens/onboarding/Login.tsx15
1 files changed, 11 insertions, 4 deletions
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<OnboardingStackParams, 'Login'>;
type VerificationScreenNavigationProp = StackNavigationProp<
@@ -51,9 +52,15 @@ const Login: React.FC<LoginProps> = ({navigation}: LoginProps) => {
attemptedSubmit: false,
token: '',
});
- // determines if user is logged in
- const {login} = React.useContext(AuthContext);
const [user, setUser] = useState<UserType>(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<LoginProps> = ({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);