Fakultas Ilmu Komputer UI

index.tsx 1.64 KB
Newer Older
Wulan Mantiri's avatar
Wulan Mantiri committed
1
import React, { FC, useContext } from 'react';
2
3
import { NavigationContainer } from '@react-navigation/native';
import { createStackNavigator } from '@react-navigation/stack';
4
import { ThemeProvider } from 'react-native-elements';
5
import Toast from 'react-native-toast-message';
6
import dayjs from 'dayjs';
7

8
import { DietelaCoverLoader, LogoutButton } from 'components/core';
Wulan Mantiri's avatar
Wulan Mantiri committed
9
import ContextProvider, { UserContext } from 'provider';
10
import { theme } from 'styles/theme';
11

12
import { screenOptions, toastConfig } from './styles';
Wulan Mantiri's avatar
Wulan Mantiri committed
13
import { getNavigation } from './schema';
14

15
16
dayjs.locale('id');

17
18
const Stack = createStackNavigator();

Wulan Mantiri's avatar
Wulan Mantiri committed
19
const NavigationStack: FC = () => {
20
  const { isAuthenticated, user, isFirstLoading } = useContext(UserContext);
Wulan Mantiri's avatar
Wulan Mantiri committed
21

22
  const { initialRoute, navigation } = getNavigation(isAuthenticated, user);
Wulan Mantiri's avatar
Wulan Mantiri committed
23

Wulan Mantiri's avatar
Wulan Mantiri committed
24
25
26
  if (isFirstLoading) {
    return <DietelaCoverLoader />;
  }
Wulan Mantiri's avatar
Wulan Mantiri committed
27
28
29
30
31
  return (
    <NavigationContainer>
      <Stack.Navigator
        initialRouteName={initialRoute}
        screenOptions={screenOptions}>
32
33
34
35
36
37
38
39
40
41
42
43
        {navigation.map((nav, i) => (
          <Stack.Screen
            key={`nav${i}`}
            name={nav.name}
            component={nav.component}
            options={{
              title: nav.header,
              headerShown: Boolean(nav.header),
              headerRight: LogoutButton,
            }}
          />
        ))}
Wulan Mantiri's avatar
Wulan Mantiri committed
44
45
46
47
48
      </Stack.Navigator>
    </NavigationContainer>
  );
};

49
50
const App: FC = () => {
  return (
Wulan Mantiri's avatar
Wulan Mantiri committed
51
    <ThemeProvider theme={theme}>
52
      <ContextProvider>
Wulan Mantiri's avatar
Wulan Mantiri committed
53
        <NavigationStack />
54
55
        <Toast config={toastConfig} ref={Toast.setRef} />
      </ContextProvider>
Wulan Mantiri's avatar
Wulan Mantiri committed
56
    </ThemeProvider>
57
58
59
60
  );
};

export default App;