diff options
| author | Ashm Walia <40498934+ashmgarv@users.noreply.github.com> | 2020-12-04 08:50:24 -0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-12-04 11:50:24 -0500 |
| commit | 0fd892ad288f2e1eaaa4fdf5e1fd6f15dbd45860 (patch) | |
| tree | d7d53d94c6c4026ac9b325508ebce4706d412ac4 /src/routes/Routes.tsx | |
| parent | f620102190629e0b6f180d3ce056d850b1db5aaa (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/routes/Routes.tsx')
| -rw-r--r-- | src/routes/Routes.tsx | 24 |
1 files changed, 20 insertions, 4 deletions
diff --git a/src/routes/Routes.tsx b/src/routes/Routes.tsx index 92cd3dd2..e54f038d 100644 --- a/src/routes/Routes.tsx +++ b/src/routes/Routes.tsx @@ -1,13 +1,29 @@ -import React from 'react'; - -import {AuthContext} from './authentication'; +import React, {useEffect} from 'react'; import NavigationBar from './tabs'; import Onboarding from './onboarding'; +import {useSelector, useDispatch} from 'react-redux'; +import {RootState} from '../store/rootReducer'; +import {userLogin} from '../utils'; const Routes: React.FC = () => { const { user: {userId}, - } = React.useContext(AuthContext); + } = useSelector((state: RootState) => state.user); + const dispatch = useDispatch(); + + /** + * Load the user from AsyncStorage if any + * Note that this makes logout triggered by invalid Token have no effect. + * We should figure out a way to handle that. + * Suggestions? + * NOTE : Not something introduced by this commit but something we already have. + */ + useEffect(() => { + if (!userId) { + userLogin(dispatch, {userId: '', username: ''}); + } + }, [userId, userLogin]); + return userId ? <NavigationBar /> : <Onboarding />; }; |
