aboutsummaryrefslogtreecommitdiff
path: root/src/routes/Routes.tsx
blob: 38a987f762c492fa47a0526f6947d222375eceb0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
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';
import SplashScreen from 'react-native-splash-screen';

const Routes: React.FC = () => {
  const {
    user: {userId},
  } = 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.
   */

  /**
   * SplashScreen is the actual react-native's splash screen.
   * We can hide / show it depending on our application needs.
   */
  useEffect(() => {
    if (!userId) {
      userLogin(dispatch, {userId: '', username: ''});
    } else {
      SplashScreen.hide();
    }
  }, [dispatch, userId]);

  return userId ? <NavigationBar /> : <Onboarding />;
};

export default Routes;